Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1612 connectés 

  FORUM HardWare.fr
  Programmation
  C

  Problème en C et OpenGL

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème en C et OpenGL

n°1307951
nisalon_ca​je
Posté le 17-02-2006 à 13:38:35  profilanswer
 

Salut, j'ai encore un problème et comme d'habitude je trouve pas la solution : mon problème c'est que j'ai une brique qui clignote anormalement : de temps en temps elle semble s'éteindre !!!
 
Voici la source :

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <GL/glut.h>
  4. #include <math.h>
  5. #define PI 3.14159265
  6. int theta=50;
  7. void changePerspective();
  8. void display();
  9. void brique(void);
  10. void calcTableCosSin();
  11. void rotation();
  12. float ang=0;
  13. float inca=4;
  14. int rotation_act=1;
  15. float Sin[360],Cos[360];
  16. /* Paramètres de lumière */
  17. GLfloat L0pos[]={-4.0,4.0,3.0};
  18. GLfloat L0dif[]={ 1.0,1.0,1.0};
  19. GLfloat L1pos[]={ 1.7,4.5,2.0};
  20. GLfloat L1dif[]={ 1.0,1.0,1.0};
  21. GLfloat Mspec[]={ 0.7,0.7,0.7};
  22. GLfloat Mshiny=5;
  23. /* Fin paramètres de lumière */
  24. int main(int argc,char **argv) {
  25. // Initialisation d'OpenGL
  26. glutInit(&argc,argv);
  27. glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
  28. glutInitWindowPosition(200,200);
  29. glutInitWindowSize(640,480);
  30. glutCreateWindow("essd" );
  31. calcTableCosSin();
  32. glClearColor(0.0,0.0,0.0,0.0);
  33. glPointSize(1.0);
  34. glShadeModel(GL_SMOOTH); 
  35. glEnable(GL_DEPTH_TEST);
  36. /* Paramétrage des lumières */
  37. glShadeModel(GL_SMOOTH);
  38. glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
  39. glEnable(GL_LIGHTING);
  40. glEnable(GL_LIGHT0);
  41. glEnable(GL_LIGHT1);
  42. glLightfv(GL_LIGHT0,GL_DIFFUSE,L0dif);
  43. glLightfv(GL_LIGHT0,GL_SPECULAR,L0dif);
  44. glLightfv(GL_LIGHT1,GL_DIFFUSE,L1dif);
  45. glLightfv(GL_LIGHT1,GL_SPECULAR,L1dif);
  46. /* Paramétrage du matériau */
  47. glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Mspec);
  48. glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,Mshiny);
  49. changePerspective();
  50. glMatrixMode(GL_MODELVIEW);
  51. // Fonctions de rappel
  52. glutDisplayFunc(display);
  53. // Entrée dans la boucle principale
  54. glutMainLoop();
  55. return 0;
  56. }
  57. void changePerspective()
  58. {
  59.   glMatrixMode(GL_PROJECTION);
  60.   glLoadIdentity();
  61.   gluPerspective(theta,1.0,0.1,40.0);
  62.   glMatrixMode(GL_MODELVIEW);
  63. }
  64. void display()
  65. {
  66. /* effacement de l'image avec la couleur de fond */
  67. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  68. glLoadIdentity();
  69. /*Application des transfos de visualisation */
  70. /*CAMERA*/
  71. glTranslatef(-0.5,-0.75,-4.0);
  72. glRotated(20.0,0.60,-1.0,-0.06);
  73. /*CAMERA FIN */
  74. /*LUMIERES*/
  75. glLightfv(GL_LIGHT0,GL_POSITION,L0pos);
  76. glLightfv(GL_LIGHT1,GL_POSITION,L1pos);
  77. /*LUMIERES FIN*/
  78. glPushMatrix();
  79. if(rotation_act==1)
  80. glutTimerFunc(30,rotation,0);
  81. /* Dessin de la brique tournante */
  82. glLoadIdentity();
  83. glPopMatrix();
  84. glPushMatrix();
  85. glRotatef(ang,0.0,1.0,0.0);
  86. brique();
  87. glFlush();
  88. /* On echange les buffers */
  89. glutSwapBuffers();
  90. }
  91. void brique(void) {
  92. // Fonction permettant de dessiner une brique
  93. float tl2=25/100+.2;
  94. glBegin(GL_POLYGON);
  95.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2, 0.2, tl2);
  96.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2, 0.0, tl2);
  97.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2, 0.0, tl2);
  98.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2, 0.2, tl2);
  99.   glEnd();
  100.   glBegin(GL_POLYGON); 
  101.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.2, tl2);
  102.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.0, tl2);
  103.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.0,-tl2);
  104.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.2,-tl2);
  105.   glEnd();
  106.   glBegin(GL_POLYGON);
  107.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.2,-tl2);
  108.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0.0,-tl2);
  109.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.0,-tl2);
  110.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.2 ,-tl2);
  111.   glEnd();
  112.   glBegin(GL_POLYGON);
  113.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.2 ,-tl2);
  114.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.0,-tl2);
  115.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.0, tl2);
  116.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0.2 , tl2);
  117.   glEnd();
  118.   glBegin(GL_POLYGON);
  119.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2, 0.2 ,-tl2);
  120.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2, 0.2 , tl2);
  121.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2, 0.2 , tl2);
  122.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2, 0.2 ,-tl2);
  123.   glEnd();
  124.  
  125.   glBegin(GL_POLYGON);
  126.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0,-tl2);
  127.   glColor3f(1.0,1.0,1.0);   glVertex3f(-tl2,0, tl2);
  128.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0, tl2);
  129.   glColor3f(1.0,1.0,1.0);   glVertex3f( tl2,0,-tl2);
  130.   glEnd();
  131. }
  132. void calcTableCosSin()
  133. {
  134.   /* calcul du tableau des sinus et cosinus */
  135.   int i;
  136.   for (i=0;i<360;i++) {
  137.     Cos[i]=cos(((float)i)/180.0*PI);
  138.     Sin[i]=sin(((float)i)/180.0*PI);
  139.   }
  140. }
  141. void rotation()
  142. {
  143.   ang=ang+inca;
  144.   if (ang>360)
  145.     ang=ang-360;
  146.     glutPostRedisplay();
  147. }


 
Voila, merci de me dire où ca ne va pas et aussi dites moi si mon utilisation de gluttimerfunc est correcte  
 
NC


Message édité par nisalon_caje le 17-02-2006 à 14:45:37
mood
Publicité
Posté le 17-02-2006 à 13:38:35  profilanswer
 

n°1307959
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 17-02-2006 à 13:48:41  profilanswer
 

merci de mettre le code entre les balises adéquates, stp


---------------
J'ai un string dans l'array (Paris Hilton)
n°1308145
nisalon_ca​je
Posté le 17-02-2006 à 15:38:09  profilanswer
 

et voila les balises !

n°1310173
caddie
Posté le 20-02-2006 à 23:59:51  profilanswer
 

Salut,
En fait je viens de lancer ton code, à ta place je spécifierais les normales et je re-regarderais l'utilisation de glPushMatrix et glPopMatrix qui me semble pas très classes là !


Message édité par caddie le 21-02-2006 à 19:16:54
n°1313472
nisalon_ca​je
Posté le 25-02-2006 à 13:40:57  profilanswer
 

ok merci, mais commebnt devrais-je mettre les pop et push matrix ?


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  Problème en C et OpenGL

 

Sujets relatifs
problème d‘authentificationProblème de mise en forme dynamique dans un tableau.
[DEVCPP]v.49810 problème telechargement[RESOLU] problème de condition
[VBnet] Problème avec un compteurProblème avec include
[ANT] Probleme de build.xmlProbléme streams.h
[SQL Server 2005 ] Probleme pour lancer une instanceproblème d'accents
Plus de sujets relatifs à : Problème en C et OpenGL


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR