encours | bonsoir,
dans mon programme opengl c++, j'ai une voiture qui roule sur une route mais alors je la fais rouler d'un pas de 0.1 et au lieu qu'il roule d'une facon continu elle roule discret comme si elle fait des pas (surement c'est probleme de memoire ) puis elle reste de bouger apres un certain nombre de pas meme si la boucle est pour l'infini
je sais pas pourquoi
voila le code de main (il reste un .h qui contient des fonctions): je souhaite que vous me detectez le probleme :
Code :
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <Windows.h>
- #include <GL/glut.h>
- #include "drawing_functions.h"
- #include "SOIL.h"
- //#include "glm.h"
- //#include "drawmodel.h"
- //#include "glm.c"
- /* l'heure systeme
-
- SYSTEMTIME Time;
-
- GetLocalTime(&Time);
-
- printf("Nous sommes le : %02d/%02d/%04d.\n",
- Time.wDay, Time.wMonth, Time.wYear);
-
- printf("Et il est : %02dh %02dmn %02ds %03dms.\n",
- Time.wHour, Time.wMinute, Time.wSecond, Time.wMilliseconds);
-
- */
- float yy = 1.8;
- GLuint texture[2];
- int LoadGLTextures() // Load Bitmaps And Convert To Textures
- {
- /* load an image file directly as a new OpenGL texture */
- texture[0] = SOIL_load_OGL_texture( "facmodif.bmp",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[1] = SOIL_load_OGL_texture( "vert2.bmp",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[2] = SOIL_load_OGL_texture( "arriere.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[3] = SOIL_load_OGL_texture( "couleur.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[4] = SOIL_load_OGL_texture( "vitre.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[5] = SOIL_load_OGL_texture( "parebrise.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[6] = SOIL_load_OGL_texture( "terrain.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[7] = SOIL_load_OGL_texture( "mur.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[8] = SOIL_load_OGL_texture( "facade.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[9] = SOIL_load_OGL_texture( "facade2.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[10] = SOIL_load_OGL_texture("zlij.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[11] = SOIL_load_OGL_texture("porte.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[12] = SOIL_load_OGL_texture("marbre.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[13] = SOIL_load_OGL_texture("trotoir1.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[14] = SOIL_load_OGL_texture("mur_deniere.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- texture[15] = SOIL_load_OGL_texture("sol.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
- //if(texture[0] == 0)
- //return false;
- //Typical Texture Generation Using Data From The Bitmap
- //glBindTexture(GL_TEXTURE_2D, texture[0]);
- //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- return true; // Return Success
- }
- static void key(unsigned char k, int x, int y)
- {
- switch (k) {
- case 27: //Echaper
- exit(0);
- break;
- default:
- return;
- }
- glutPostRedisplay();
- }
- void Dessiner()
- {
- //for(;;){
- //yy = yy -0.1 ;
- /*
- */
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity( );
- gluLookAt(5.5,6.5,7,0,0,0,0,0,1);
- //drawRectangle3D(1.15,1.15,0.1,1.55,1.15,0.1,1.55,7,0.1,1.15,7,0.1);
- LoadGLTextures();
- //glColor3ub(255,255,255);
- glBindTexture(GL_TEXTURE_2D, texture[6]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- //glScalef(2,2,2);
- glEnable(GL_TEXTURE_2D);
- glColor3ub(0,255,0);
- glBegin(GL_QUADS);
- glTexCoord2i(0,0); glVertex3d(1.55,1.55,0.1);
- glTexCoord2i(20,0); glVertex3d(1.15,6,0);
- glTexCoord2i(20,20); glVertex3d(6,6,0);
- glTexCoord2i(0,20); glVertex3d(6,1.15,0);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glMatrixMode( GL_MODELVIEW );
- //glLoadIdentity( );
- glColor3ub(63,63,63);
- drawRectangle(1,6,-1,6,-1,-19,1,-19,0.01); // route horizontale
- drawRectangle(6,1,6,-1,-12,-1,-12,1,0.011); // route verticale
- glColor3f(1,1,1);
- drawRectangle(0.99,1.1,0.7,1.1,0.7,1.6,0.99,1.6,0.11);//les places des pietons de la route vers la droite
- drawRectangle(0.64,1.1,0.4,1.1,0.4,1.6,0.64,1.6,0.11);
- drawRectangle(0.34,1.1,0.1,1.1,0.1,1.6,0.34,1.6,0.11);
- drawRectangle(0.04,1.1,-0.2,1.1,-0.2,1.6,0.04,1.6,0.11);
- drawRectangle(-0.26,1.1,-0.5,1.1,-0.5,1.6,-0.26,1.6,0.11);
- drawRectangle(-0.56,1.1,-0.84,1.1,-0.84,1.6,-0.56,1.6,0.11);
- drawRectangle(0.99,-1.1,0.7,-1.1,0.7,-1.6,0.99,-1.6,0.11);//les places des pietons de la route vers la gauche
- drawRectangle(0.64,-1.1,0.4,-1.1,0.4,-1.6,0.64,-1.6,0.11);
- drawRectangle(0.34,-1.1,0.1,-1.1,0.1,-1.6,0.34,-1.6,0.11);
- drawRectangle(0.04,-1.1,-0.2,-1.1,-0.2,-1.6,0.04,-1.6,0.11);
- drawRectangle(-0.26,-1.1,-0.5,-1.1,-0.5,-1.6,-0.26,-1.6,0.11);
- drawRectangle(-0.56,-1.1,-0.84,-1.1,-0.84,-1.6,-0.56,-1.6,0.11);
- drawRectangle(-1.1,0.99,-1.1,0.7,-1.6,0.7,-1.6,0.99,0.11);//les places des pietons de la route vers la haut
- drawRectangle(-1.1,0.64,-1.1,0.4,-1.6,0.4,-1.6,0.64,0.11);
- drawRectangle(-1.1,0.34,-1.1,0.1,-1.6,0.1,-1.6,0.34,0.11);
- drawRectangle(-1.1,0.04,-1.1,-0.2,-1.6,-0.2,-1.6,0.04,0.11);
- drawRectangle(-1.1,-0.26,-1.1,-0.5,-1.6,-0.5,-1.6,-0.26,0.11);
- drawRectangle(-1.1,-0.56,-1.1,-0.84,-1.6,-0.84,-1.6,-0.56,0.11);
- drawRectangle(1.1,0.99,1.1,0.7,1.6,0.7,1.6,0.99,0.11);//les places des pietons de la route vers la bas
- drawRectangle(1.1,0.64,1.1,0.4,1.6,0.4,1.6,0.64,0.11);
- drawRectangle(1.1,0.34,1.1,0.1,1.6,0.1,1.6,0.34,0.11);
- drawRectangle(1.1,0.04,1.1,-0.2,1.6,-0.2,1.6,0.04,0.11);
- drawRectangle(1.1,-0.26,1.1,-0.5,1.6,-0.5,1.6,-0.26,0.11);
- drawRectangle(1.1,-0.56,1.1,-0.84,1.6,-0.84,1.6,-0.56,0.11);
- int j ;
- for(j=0;j<15;j++){
- drawRectangle(0.04,1.8+j,-0.04,1.8+j,-0.04,2.4+j,0.04,2.4+j,0.11);//les rectangles au milieu du route droite
- drawRectangle(0.04,-1.8-j,-0.04,-1.8-j,-0.04,-2.4-j,0.04,-2.4-j,0.11);//les rectangles au milieu du route gauche
- drawRectangle(1.8+j,0.04,1.8+j,-0.04,2.4+j,-0.04,2.4+j,0.04,0.11);//les rectangles au milieu du route bas
- drawRectangle(-1.8-j,0.04,-1.8-j,-0.04,-2.4-j,-0.04,-2.4-j,0.04,0.11);//les rectangles au milieu du route haut
- }
- float i,y=1;
- for(i = 1;i<25;i++){
- glColor3ub(255,0,0);
- drawRectangle3D(-1,y,0,-1,y+0.3,0,-1,y+0.3,0.1,-1,y,0.1);// les trotoires du route droite vers (haut) rouge
- drawRectangle3D(-1,y,0.1,-1,y+0.3,0.1,-1.15,y+0.3,0.1,-1.15,y,0.1);
- //if(y>4 || y<2.5){// pour l'entrée du terrain
- drawRectangle3D(1,y,0,1,y+0.3,0,1,y+0.3,0.1,1,y,0.1);// les trotoires du route droite vers (bas) rouge
- drawRectangle3D(1,y,0.1,1,y+0.3,0.1,1.15,y+0.3,0.1,1.15,y,0.1);
- //}
- drawRectangle3D(-y,-1,0,-y-0.3,-1,0,-y-0.3,-1,0.1,-y,-1,0.1);// les trotoires du route haut vers (gauche) rouge
- drawRectangle3D(-y,-1,0.1,-y-0.3,-1,0.1,-y-0.3,-1.15,0.1,-y,-1.15,0.1);
- drawRectangle3D(-y,1,0,-y-0.3,1,0,-y-0.3,1,0.1,-y,1,0.1);// les trotoires du route haut vers (droite) rouge
- drawRectangle3D(-y,1,0.1,-y-0.3,1,0.1,-y-0.3,1.15,0.1,-y,1.15,0.1);
- drawRectangle3D(y,-1,0,y+0.3,-1,0,y+0.3,-1,0.1,y,-1,0.1);// les trotoires du route bas vers (gauche) rouge
- drawRectangle3D(y,-1,0.1,y+0.3,-1,0.1,y+0.3,-1.15,0.1,y,-1.15,0.1);
- drawRectangle3D(y,1,0,y+0.3,1,0,y+0.3,1,0.1,y,1,0.1);// les trotoires du route bas vers (droite) rouge
- drawRectangle3D(y,1,0.1,y+0.3,1,0.1,y+0.3,1.15,0.1,y,1.15,0.1);
- drawRectangle3D(-1,-y,0,-1,-y-0.3,0,-1,-y-0.3,0.1,-1,-y,0.1);// les trotoires du route gauche (vres haut)
- drawRectangle3D(-1,-y,0.1,-1,-y-0.3,0.1,-1.15,-y-0.3,0.1,-1.15,-y,0.1);
- drawRectangle3D(1,-y,0,1,-y-0.3,0,1,-y-0.3,0.1,1,-y,0.1);// les trotoires du route gauche (vres bas)
- drawRectangle3D(1,-y,0.1,1,-y-0.3,0.1,1.15,-y-0.3,0.1,1.15,-y,0.1);
- y= y +0.3;
- glColor3ub(255,255,255);
- drawRectangle3D(-1,y,0,-1,y+0.3,0,-1,y+0.3,0.1,-1,y,0.1);// les trotoires du route droite vers (haut) blanc
- drawRectangle3D(-1,y,0.1,-1,y+0.3,0.1,-1.15,y+0.3,0.1,-1.15,y,0.1);
- //if(y>4 || y<2.5){// pour l'entrée du terrain
- drawRectangle3D(1,y,0,1,y+0.3,0,1,y+0.3,0.1,1,y,0.1);// les trotoires du route droite vers (bas) blanc
- drawRectangle3D(1,y,0.1,1,y+0.3,0.1,1.15,y+0.3,0.1,1.15,y,0.1);
- //}
- drawRectangle3D(-1,-y,0,-1,-y-0.3,0,-1,-y-0.3,0.1,-1,-y,0.1);// les trotoires du route gauche vers (haut) blanc
- drawRectangle3D(-1,-y,0.1,-1,-y-0.3,0.1,-1.15,-y-0.3,0.1,-1.15,-y,0.1);
- drawRectangle3D(1,-y,0,1,-y-0.3,0,1,-y-0.3,0.1,1,-y,0.1);// les trotoires du route gauche vers (bas) blanc
- drawRectangle3D(1,-y,0.1,1,-y-0.3,0.1,1.15,-y-0.3,0.1,1.15,-y,0.1);
- drawRectangle3D(-y,-1,0,-y-0.3,-1,0,-y-0.3,-1,0.1,-y,-1,0.1);// les trotoires du route haut vers (gauche) blanc
- drawRectangle3D(-y,-1,0.1,-y-0.3,-1,0.1,-y-0.3,-1.15,0.1,-y,-1.15,0.1);
- drawRectangle3D(-y,1,0,-y-0.3,1,0,-y-0.3,1,0.1,-y,1,0.1);// les trotoires du route haut vers (droite) blanc
- drawRectangle3D(-y,1,0.1,-y-0.3,1,0.1,-y-0.3,1.15,0.1,-y,1.15,0.1);
- drawRectangle3D(y,-1,0,y+0.3,-1,0,y+0.3,-1,0.1,y,-1,0.1);// les trotoires du route bas vers (gauche) blanc
- drawRectangle3D(y,-1,0.1,y+0.3,-1,0.1,y+0.3,-1.15,0.1,y,-1.15,0.1);
- drawRectangle3D(y,1,0,y+0.3,1,0,y+0.3,1,0.1,y,1,0.1);// les trotoires du route bas vers (droite) blanc
- drawRectangle3D(y,1,0.1,y+0.3,1,0.1,y+0.3,1.15,0.1,y,1.15,0.1);
- y= y +0.3;
- }
- // trotoir droit bas
- glColor3ub(130,130,130);
- drawRectangle3DTexture(texture,1.15,1.15,0.1,1.55,1.15,0.1,1.55,7,0.1,1.15,7,0.1);
- drawRectangle3DTexture(texture,1.55,1.15,0.1,1.55,1.55,0.1,7,1.55,0.1,7,1.15,0.1);
- //trotoir droit haut
- drawRectangle3DTexture(texture,-1.15,1.15,0.1,-1.55,1.15,0.1,-1.55,7,0.1,-1.15,7,0.1);
- drawRectangle3DTexture(texture,-1.55,1.15,0.1,-1.55,1.55,0.1,-7,1.55,0.1,-7,1.15,0.1);
- //trotoir devant usine
- drawRectangle3DTexture(texture,-1.15,-1.15,0.1,-1.55,-1.15,0.1,-1.55,-17,0.1,-1.15,-17,0.1);
- drawRectangle3DTexture(texture,-1.55,-1.15,0.1,-1.55,-1.55,0.1,-17,-1.55,0.1,-17,-1.15,0.1);
- //trotoir devant devant usine
- drawRectangle3DTexture(texture,1.15,-1.15,0.1,1.55,-1.15,0.1,1.55,-7,0.1,1.15,-7,0.1);
- drawRectangle3DTexture(texture,1.55,-1.15,0.1,1.55,-1.55,0.1,7,-1.55,0.1,7,-1.15,0.1);
- //mur droit haut
- /*
- */
- mur_villa(texture);
- dernier_batiment(texture);
- /*
- * le mur de l'immeuble et son image
- */
- glColor3ub(255,255,255);
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- //glScalef(2,2,2);
- glEnable(GL_TEXTURE_2D);
- glBegin (GL_QUADS);
- glTexCoord2i(0,0); glVertex3f (-1.55,1.55,0.1);
- glTexCoord2i(1,0); glVertex3f (-1.55,7,0.1);
- glTexCoord2i(1,1); glVertex3f (-1.55,7,2);
- glTexCoord2i(0,1); glVertex3f (-1.55,1.55,2);
- glEnd ();
- glMatrixMode(GL_MODELVIEW);// les autres murs du meme immeuble
- drawRectangle3D(-1.55,1.55,0.1,-1.55,7,0.1,-1.55,7,2,-1.55,1.55,2);
- drawRectangle3D(-1.55,1.55,0.1,-7,1.55,0.1,-7,1.55,2,-1.55,1.55,2);
- drawRectangle3D(-1.55,1.55,2,-7,1.55,2,-7,7,2,-1.55,7,2);//plafon
- /*-------- le feu rouge a cote du mur
- */
- GLUquadric* params = gluNewQuadric();
- glPushMatrix();
- glTranslated(-1.24,1.52,0); // changement repere
- glColor3ub(155,155,155);
- gluCylinder(params,0.05,0.05,1.1,20,1);
- glTranslated(0,0,0.47); // changement repere
- glColor3ub(255,0,0);
- // la texture et le feu tricolore
- glColor3ub(255,255,255);
- glBindTexture(GL_TEXTURE_2D, texture[1]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glMatrixMode(GL_TEXTURE);
- glEnable(GL_TEXTURE_2D);
- glBegin (GL_QUADS);
- glTexCoord2i(0,0); glVertex3f (0.11,0.11,0);
- glTexCoord2i(1,0); glVertex3f (-0.11,0.11,0);
- glTexCoord2i(1,1); glVertex3f (-0.11,0.11,0.7);
- glTexCoord2i(0,1); glVertex3f (0.11,0.11,0.7);
- glEnd ();
- glDisable(GL_TEXTURE_2D);
- //gluDeleteQuadric(params);
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- /*
- */ //le deuxieme feu tricolore
- glPushMatrix();
- glTranslated(-1.66,-1.27,0); // changement repere
- glColor3ub(42,42,42);
- gluCylinder(params,0.05,0.05,1.1,20,1);
- glTranslated(0,0,0.47); // changement repere
- glBegin (GL_QUADS);
- /* glTexCoord2i(0,1);*/ glVertex3f (-0.11,-0.11,0);
- /*glTexCoord2i(1,1);*/ glVertex3f (-0.11,0.11,0);
- /*glTexCoord2i(1,0);*/ glVertex3f (-0.11,0.11,0.7);
- /*glTexCoord2i(0,0);*/ glVertex3f (-0.11,-0.11,0.7);
- glEnd ();
- glDisable(GL_TEXTURE_2D);
- //gluDeleteQuadric(params);
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- /*
- */ //le troisieme feu tricolore
- glPushMatrix();
- glTranslated(+1.27,-1.53,0); // changement repere
- glColor3ub(42,42,42);
- gluCylinder(params,0.05,0.05,1.1,20,1);
- glTranslated(0,0,0.47); // changement repere
- glBegin (GL_QUADS);
- /* glTexCoord2i(0,1);*/ glVertex3f (0.11,-0.11,0);
- /*glTexCoord2i(1,1);*/ glVertex3f (-0.11,-0.11,0);
- /*glTexCoord2i(1,0);*/ glVertex3f (-0.11,-0.11,0.7);
- /*glTexCoord2i(0,0);*/ glVertex3f (0.11,-0.11,0.7);
- glEnd ();
- glDisable(GL_TEXTURE_2D);
- //gluDeleteQuadric(params);
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- /*
- */ //le quatrieme feu tricolore
- glPushMatrix();
- glTranslated(+1.59,+1.3,0); // changement repere
- glColor3ub(42,42,42);
- gluCylinder(params,0.05,0.05,1.1,20,1);
- glTranslated(0,0,0.47); // changement repere
- glBindTexture(GL_TEXTURE_2D, texture[1]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glMatrixMode(GL_TEXTURE);
- glEnable(GL_TEXTURE_2D);
- glColor3ub(255,255,255);
- glBegin (GL_QUADS);
- glTexCoord2i(0,0); glVertex3f (0.11,-0.11,0);
- glTexCoord2i(1,0); glVertex3f (0.11,0.11,0);
- glTexCoord2i(1,1); glVertex3f (0.11,0.11,0.7);
- glTexCoord2i(0,1); glVertex3f (0.11,-0.11,0.7);
- glEnd ();
- glDisable(GL_TEXTURE_2D);
- gluDeleteQuadric(params);
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- /*
- */
- drawVoiturealler(texture,yy);
- //glFlush();
- glutSwapBuffers();
- /*
- */
- /*GetLocalTime(&Time);
- differ_time = Time.wMilliseconds - current_time;
- if (differ_time < 4 & differ_time > 0)
- {
- Sleep(4 - differ_time);
- }
- // - -- - - - - - - -
- */
- //}
- /*
- */
- //
- }
- void Idle(){
- yy = yy -0.1;
- glutPostRedisplay();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE |GLUT_DEPTH );
- glutInitWindowSize(1000,590);
- glutInitWindowPosition(50,50);
- glutCreateWindow("fenetre OpenGl" );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluPerspective(40,(double)640/480,1,100);
- glEnable(GL_DEPTH_TEST);
- glutDisplayFunc(Dessiner);
- glutIdleFunc(Idle);
- //Dessiner();
- glutKeyboardFunc(key);
- glutMainLoop();
- return 0;
- }
|
merci |