Probleme avec GLUT
Résolu
nyergk
-
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
j ai un listing avec GLUT ou je charge une image avec devil (impeccable) , puis j essaie de faire bouger l image de gauche a droite en test, avec une variable colonne augmenter de 0.1 a chaque tour de glutmainloop(); mais l image bouge un peu, puis se bloque et reste immobile !!! je comprends pas le bugs, la fonction d affichage ne boucle pas !!! je pense que le bug vine de la routine affichage() appeler par glutDisplayFunc() mais je vois pas où ... voici le listing
si quelqu un de doué pouvait me dire ou est l erreur...
merci d avance.
j ai un listing avec GLUT ou je charge une image avec devil (impeccable) , puis j essaie de faire bouger l image de gauche a droite en test, avec une variable colonne augmenter de 0.1 a chaque tour de glutmainloop(); mais l image bouge un peu, puis se bloque et reste immobile !!! je comprends pas le bugs, la fonction d affichage ne boucle pas !!! je pense que le bug vine de la routine affichage() appeler par glutDisplayFunc() mais je vois pas où ... voici le listing
#include<windows.h> #include<GL/gl.h> //OPENGL graphismes #include<GL/glu.h> #include<GL/glut.h> #include<AL/al.h> //OPENAL son #include<AL/alc.h> #include<AL/alut.h> #include<IL/il.h> // chargement des images jpg,bmp,etc... #include<IL/ilu.h> #include<IL/ilut.h> //////////////////////////////////// // STRUCTURE ROUTINES SON //////////////////////////////////// struct SOUND { private: ALuint Buffer; ALuint Source; ALfloat SourcePos[3] ; ALfloat SourceVel[3] ; ALfloat ListenerPos[3]; ALfloat ListenerVel[3] ; ALfloat ListenerOri[6] ; public : void load(char *nomfichier) { ALenum format; ALsizei size; ALvoid* data; ALsizei freq; ALboolean loop; alGenBuffers(1, &Buffer); alutLoadWAVFile(nomfichier, &format, &data, &size, &freq, &loop); alBufferData(Buffer, format, data, size, freq); alutUnloadWAV(format, data, size, freq); alGenSources(1, &Source); alSourcei (Source, AL_BUFFER, Buffer ); alSourcef (Source, AL_PITCH, 1.0 ); alSourcef (Source, AL_GAIN, 1.0 ); alSourcefv(Source, AL_POSITION, SourcePos); alSourcefv(Source, AL_VELOCITY, SourceVel); alSourcei (Source, AL_LOOPING, loop ); alListenerfv(AL_POSITION, ListenerPos); alListenerfv(AL_VELOCITY, ListenerVel); alListenerfv(AL_ORIENTATION, ListenerOri); } void erase() { alDeleteBuffers(1, &Buffer); alDeleteSources(1, &Source); } void on(){alSourcePlay(Source); } void off(){alSourceStop(Source); } void wait(){alSourcePause(Source); } }; ///////////////////////////////////////////// // STRUCTURE CHARGEMENT IMAGES JPG, BMP,...// ///////////////////////////////////////////// struct IMAGE { unsigned char *adress; int w,h,format,bpp ; float x,y ; ILuint n; //chagrment d une image, adresse *image void load(char *nom) { ilGenImages(1,&n); ilBindImage(n); ilLoadImage(nom); ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE); iluFlipImage(); w=ilGetInteger(IL_IMAGE_WIDTH); //largeur h=ilGetInteger(IL_IMAGE_HEIGHT);//hauteur format=ilGetInteger(IL_IMAGE_FORMAT);//RGB ... bpp=ilGetInteger(IL_IMAGE_BPP); //24 bits adress=ilGetData(); //adresse de l image } void on(float xx, float yy) { glRasterPos2f(xx,yy); glDrawPixels(w,h,format,GL_UNSIGNED_BYTE,adress); x=xx;y=yy; } void on() { glRasterPos2f(x,y); glDrawPixels(w,h,format,GL_UNSIGNED_BYTE,adress); } void flip() {ilBindImage(n);iluFlipImage();} // image a l envers void destroy() {ilDeleteImages(1,&n);} }; ///////////////////////////////////////////// // DECLARATIONS VARIABLES ///////////////////////////////////////////// struct IMAGE montagne; struct SOUND essai_son; unsigned char tch1 ; int tch2; //clavier int mouse_button,mouse_x,mouse_y; //souris float colonne; ////////////////////////////////////////// // DECLARATIONS ROUTINES ////////////////////////////////////////// void ini_simple(int argvc, char *argv[], char *envp[]); void affichage(); void mouse(int boutton,int etat,int x, int y); void keyboard(unsigned char key,int x, int y); void keyboard(int key,int x,int y); //////////////////////////////////////////////// // ROUTINES /////////////////////////////////////////////// void mouse(int button,int etat,int x, int y) { //if(button==GLUT_LEFT_BUTTON) ; //if(button==GLUT_RIGHT_BUTTON) exit(0) ; //if(button==GLUT_MIDDLE_BUTTON) ; mouse_button=button; mouse_x=x; mouse_y=y; } void keyboard(unsigned char key,int x, int y) { if(key==27) exit(0); // code ascii ESC tch1=key ; } void keyboard(int key,int x,int y) { if(key==GLUT_KEY_RIGHT); if(key==GLUT_KEY_LEFT); if(key==GLUT_KEY_DOWN); if(key==GLUT_KEY_UP); tch2=key; } void changesize(int w, int h){} //////////////////////////////////////////////// ////// MAIN() ////////////////////////////////// //////////////////////////////////////////////// int main(int argvc, char *argv[], char *envp[]) {// initialisation systeme alutInit(NULL, 0); // son ilInit();// chargement images glutInit(&argvc, argv); //GLUT glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);/* affichage couleur */ glutInitWindowSize(1200, 800); /* taille initiale fenetre graphique */ glutInitWindowPosition(200,200); /* position initiale */ glutCreateWindow("window"); /* creation de la fenetre graphique */ montagne.load("image.jpg"); glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF); glutKeyboardFunc(keyboard); /* gestion du clavier */ glutSpecialFunc(keyboard); glutMouseFunc(mouse); /* fonction souris */ glutDisplayFunc(affichage); /* fonction d'affichage */ //glutReshapeFunc(changesize); /* fonction de refenetrage */ //glutIdleFunc(program); glutMainLoop(); } void affichage() { glClear(GL_COLOR_BUFFER_BIT); montagne.on(colonne,-1); glutSwapBuffers(); colonne=colonne+0.1; if (colonne>1) colonne=-1; }
si quelqu un de doué pouvait me dire ou est l erreur...
merci d avance.