RM50Man
Messages postés314Date d'inscriptionmercredi 1 novembre 2000StatutMembreDernière intervention20 août 2006
-
26 oct. 2005 à 00:08
vladisback
Messages postés61Date d'inscriptiondimanche 19 novembre 2000StatutMembreDernière intervention 5 août 2008
-
28 oct. 2005 à 12:34
Mon code ne marche pas:
Le compilateur devcpp me met build error 1
#include <gl/glut.h> /* contient déjà <GL/gl.h> et <GL/glu.h> */
#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
void resetgraph(), initgraph();
int SIZEX,SIZEY; /* taille de la fenêtre */
GLfloat light_pos[4] = { 0., 0., 1., 0.}; /* lum à l'infini */
float Cphi=0, Otheta=0, scale=3; /*orientations */
/* description géométrique de l'objet 2 (pyramide). */
#define SQRT2 1.4142138 /* sqrt(2) */
#define SQRT3S2 .8660254 /* sqrt(3)/2 */
#define HH .4714045 /* sqrt(2)/3 */
#define nb_faces 4
#define M_PI 3.1416
float coords[nb_faces][3] =
{ {0,SQRT2,0}, {-SQRT3S2,0,-.5}, {SQRT3S2,0,-.5}, {0,0,1.} };
/* couleurs aux sommets et non pas aux faces (i.e. interpolées) */
float colors[nb_faces][3] = { {.4,.4,.4},{1,0,0},{0,1,0},{0,0,1} };
int faces[nb_faces][3] = { {0,1,2}, {0,2,3}, {0,3,1}, {3,2,1} };
/* normales aux faces et non aux sommets (i.e. objet pas lisse) */
float normals[nb_faces][3] =
{ {0,1/3.,-2*HH},{HH,1/3.,SQRT3S2*HH},{-HH,1/3.,SQRT3S2*HH},{0,-1,0} };
void draw_scene() { /* tracé de la scène */
int i;
glPushMatrix();
glTranslatef(-4.,0.,0.);
glRotatef(Otheta*180/M_PI, 1,0,0); /* on oriente l'objet 1 */
glColor3f(1.,.5,.5);
glutSolidTorus(1.,2.,20,30);
glPopMatrix();
glPushMatrix();
glTranslatef(4.,0.,0.);
glRotatef(20, 1,0,0); /* on oriente l'objet 2 */
glScalef(scale,scale,scale);
glBegin(GL_TRIANGLES);
for(i=0; i<nb_faces; i++) {
glNormal3fv(normals[i]); /* normale commune à la face */
glColor3fv (colors[faces[i][0]]);
glVertex3fv(coords[faces[i][0]]);
glColor3fv (colors[faces[i][1]]); /* couleurs aux sommets */
glVertex3fv(coords[faces[i][1]]);
glColor3fv (colors[faces[i][2]]);
glVertex3fv(coords[faces[i][2]]);
}
glEnd();
glPopMatrix();
}
void redisplay() { /* routine générale d'affichage */
resetgraph(); /* on réinitialise l'affichage */
draw_scene(); /* on trace */
glutSwapBuffers(); /* on rend le tracé visible */
glFlush();
}
void reshape(int x,int y) { glViewport(0,0,SIZEX=x,SIZEY=y); } /* resize */
void idle() { /* animation */
static float temps = 0;
temps += 0.05; Cphi -= .003; Otheta += .01; scale = 3+.3*sin(temps);
glutPostRedisplay();
}
void main(int argc, char **argv) {
glutInit(&argc,argv); /* initialisation de GLUT */
initgraph(); /* initialisations graphiques */
glutMainLoop(); /* boucle des evenements */
}
void initgraph() { /* initialisations graphiques */
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize(256,256);
glutCreateWindow("Essai !");
glutDisplayFunc(redisplay);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
}
void resetgraph() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* on efface */
glMatrixMode(GL_PROJECTION); /* on oriente la caméra */
glLoadIdentity();
gluPerspective(80., SIZEX/(float)SIZEY, .1, 100.);
glTranslatef(0,0,-10);
glRotatef(Cphi*180/M_PI, 0,1,0);
glMatrixMode(GL_MODELVIEW); /* on oriente la lumière */
glLoadIdentity();
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
}
vladisback
Messages postés61Date d'inscriptiondimanche 19 novembre 2000StatutMembreDernière intervention 5 août 2008 27 oct. 2005 à 21:44
je suis étonné que tu ne trouve pas le problemes. tu ne regarde pas les erreurs que devcpp te donnent
chez moi ça fonctionne trés bien, mes modifications:
j'ai enlever ta definition de M_PI parce qu'il est deja defini dans math.h
et pui j'ai changé ton main en
int main(int argc, char **argv) {
glutInit(&argc,argv); /* initialisation de GLUT */
initgraph(); /* initialisations graphiques */
glutMainLoop(); /* boucle des evenements */
return 0;
}
et tout fonctionne parfaitement donc je ne sais pas si c'était vraiment ça le probléme...
++
ensuite j'ai installer les librairies de glut en passant par le devpak manager de devcpp,
j'ai ensuite créé un nouveau projet glut puis j'ai remplacer le main.cpp par ton code et comme ça tout marche impecc
donc le probleme ne vient pas du code mais de ton install je pense...