Posté(e) le 22 octobre 200618 a Bonjour, mon programme ne m'affiche pas de jarre à l'écran. J'ai cherché pour savoir ce qui clochait mais je ne trouve rien. Voici le code : #include <GL/glut.h> #include <stdlib.h> #include <math.h> #define PI 3.14159263 GLfloat jarre_2d[]={0,0, 3,0, 4,2, 4,5, 3,7, 1,9, 1,11, 3,13}; void lathe(int nbr_vertices, GLfloat profile[], float angle, int nbr_sections) { int s, v; float theta1, theta2, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; for(s=0; s<nbr_sections; s++) { theta1 = (s*1.0)*angle/nbr_sections*PI/180; theta2 = (s+1.0)*angle/nbr_sections*PI/180; for(v=0; v<nbr_vertices-1; v++) { x1 = profile[v*2]*cos(theta1); y1 = profile[v*2+1]; z1 = profile[v*2]*sin(theta1); x2 = profile[v*2+2]*cos(theta1); y2 = profile[v*2+3]; z2 = profile[v*2+2]*sin(theta1); x3 = profile[v*2+2]*cos(theta2); y3 = profile[v*2+3]; z3 = profile[v*2+2]*sin(theta2); x4 = profile[v*2]*cos(theta2); y4 = profile[v*2+1]; z4 = profile[v*2]*sin(theta2); glBegin(GL_POLYGON); glVertex3f(x1,y1,z1); glVertex3f(x2,y2,z2); glVertex3f(x3,y3,z3); glVertex3f(x4,y4,z4); glEnd(); } } } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_DOUBLE); // Clear the colour and depth buffer glLoadIdentity(); // Clear matrix stack // We set the camera in position 50,50,100 and we look at origo gluLookAt(50,50,100,0,0,0,0,1,0); glColor3f(0.6,0.2,1.0); // jarre glTranslatef(-8,2,20); glScalef(10,10,10); lathe(8, jarre_2d, 360.0, 16); glFlush(); // Makes sure that we output the model to the graphics card glutSwapBuffers(); } // Called when a key is pressed void key(unsigned char k, int x, int y) { if( k == 'q' ) exit(0); } void reshape(int width,int height) { glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(float)640/(float)480,0.1f,1000.0f); // Always keeps the same aspect as a 640 wide and 480 high window glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix } void init() { glClearColor(0,0,0,0); glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); // We want rgb display functionality glutInitWindowSize(640,480); // Set the window dimensions glutInitWindowPosition(0,0); // Set the window starting point glutCreateWindow("Exercise 1"); // Set the caption and launch the window init(); // Last things before rendering starts glutDisplayFunc(display); // This will be called every frame glutReshapeFunc(reshape); // Reshape the window when something changes glutKeyboardFunc(key); // Callback for input glutMainLoop(); // Starts the main program // We will not reach this point unless exit(0) is called (see function keyCB) return 0; } Merci Modifié le 23 octobre 200618 a par Premium
Posté(e) le 23 octobre 200618 a Auteur Des erreurs à la compilation ? Le problème est résolu. Je m'étais trompé dans l'écriture de certains paramètres
Posté(e) le 23 octobre 200618 a Au fait, c'est quoi une jarre exactement ? C'est un récipient ressemblant à une amphore
Archivé
Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.