lordankou | Bonjour, je commence juste la programmation openGl pour les besoin d'un projet et j'avoue avoir du mal à comprendre pourquoi ça s'affiche mal (un problème de caméra mais je pense l'avoir pourtant bien régler).
Code :
- #include <GL/glut.h>
- #include <stdlib.h>
- // function to display in OpenGl
- void affichage(void){
- // clear everything
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- gluLookAt(272974.05f, // position oeil X --> + déplace la caméra vers la droite et - déplace la caméra vers la gauche
- 176628.75f, // position oeil Y --> + déplace la caméra vers le haut et - déplace la caméra vers le bas
- -1.0f, // position oeil Z --> +
- 272974.05f, // point regardé X --> + déplace le point cible vers la droite et - déplace le point cible vers la gauche
- 176628.75f, // point regardé Y --> + déplace le point cible vers le haut et - déplace le point cible vers le bas
- 0.0f, // point regardé Z -->
- 0.0f, // vecteur haut X -->
- 1.0f, // vecteur haut Y --> look down
- 0.0f // vecteur haut Z -->
- );
- // define a polygon
- glBegin(GL_POLYGON);
- // define a polygon composed of 4 points with different colors
- glColor3f(1.0,0.0,0.0); glVertex2f(271913.4,177406.4);
- glColor3f(1.0,1.0,0.0); glVertex2f(272010.1,177788.6);
- glColor3f(1.0,0.0,1.0); glVertex2f(272573,177814.3);
- glColor3f(0.0,1.0,0.0); glVertex2f(272652.8,177842.4);
- glColor3f(1.0,0.0,0.0); glVertex2f(272592,178163.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(273653.3,178212.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(273673.5,178006.5);
- glColor3f(1.0,0.0,0.0); glVertex2f(273833.7,177986.5);
- glColor3f(1.0,0.0,0.0); glVertex2f(273793.7, 177801.4);
- glColor3f(1.0,0.0,0.0); glVertex2f(273913.1, 177799);
- glColor3f(1.0,0.0,0.0); glVertex2f(273974.6, 177426.5);
- glColor3f(1.0,0.0,0.0); glVertex2f(274073.7, 177446.4);
- glColor3f(1.0,0.0,0.0); glVertex2f(273933.4, 177125);
- glColor3f(1.0,0.0,0.0); glVertex2f(274253.3, 177044.6);
- glColor3f(1.0,0.0,0.0); glVertex2f(274294.1, 176706.3);
- glColor3f(1.0,0.0,0.0); glVertex2f(274252.2, 176562.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(274513.8, 176466.3);
- glColor3f(1.0,0.0,0.0); glVertex2f(274493.2, 176356.7);
- glColor3f(1.0,0.0,0.0); glVertex2f(273893.5, 176379);
- glColor3f(1.0,0.0,0.0); glVertex2f(273914, 176006.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(273813.7, 175946.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(273853.7, 175786.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(273313.6, 175546.1);
- glColor3f(1.0,0.0,0.0); glVertex2f(273099, 175500.6);
- glColor3f(1.0,0.0,0.0); glVertex2f(272881.2, 175279.1);
- glColor3f(1.0,0.0,0.0); glVertex2f(272713.9, 175349.7);
- glColor3f(1.0,0.0,0.0); glVertex2f(272633.1, 175219.6);
- glColor3f(1.0,0.0,0.0); glVertex2f(272301.3, 175157.7);
- glColor3f(1.0,0.0,0.0); glVertex2f(272285.4, 175045.3);
- glColor3f(1.0,0.0,0.0); glVertex2f(271972.8, 175123.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271873, 175087.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271733.3, 175125.6);
- glColor3f(1.0,0.0,0.0); glVertex2f(271673.3, 175066.1);
- glColor3f(1.0,0.0,0.0); glVertex2f(271533.4, 175146);
- glColor3f(1.0,0.0,0.0); glVertex2f(271593.4, 175286.1);
- glColor3f(1.0,0.0,0.0); glVertex2f(271434.3, 175381);
- glColor3f(1.0,0.0,0.0); glVertex2f(271657.2, 175783.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271613.4, 175966.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271632.2, 176028.1);
- glColor3f(1.0,0.0,0.0); glVertex2f(271673.7, 176718.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271878.2, 176942.2);
- glColor3f(1.0,0.0,0.0); glVertex2f(271853.4, 177186.3);
- glColor3f(1.0,0.0,0.0); glVertex2f(271933.4, 177366.3);
- glEnd();
- // display the result
- glFlush();
- }
- // function to manage the keybord
- void clavier(unsigned char touche,int x,int y){
- switch (touche){
- case 'p': /* affichage du carre plein */
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- break;
- case 'f': /* affichage en mode fil de fer */
- glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- break;
- case 's' : /* Affichage en mode sommets seuls */
- glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
- break;
- case 'q' : /*la touche 'q' pour quitter le programme */
- exit(0);
- }
- // redisplay the object
- glutPostRedisplay();
- }
- // main function
- int main(int argc, char *argv[])
- {
- // --------
- //init GLUT
- // --------
- // take argument
- glutInit(&argc,argv);
- // Mode RGB and one buffer
- glutInitDisplayMode(GLUT_RGB);
- // uper left point of the openGl window
- glutInitWindowPosition(200,200);
- // size of the window (width,Heigh)
- glutInitWindowSize(250,250);
- // name of the windows
- glutCreateWindow("Exemple 1" );
- // define black screen
- glClearColor(0.0,0.0,0.0,0.0);
- // define point size
- glPointSize(2.0);
- // which function is used to display object
- glutDisplayFunc(affichage);
- // which function is used to manage keybord
- glutKeyboardFunc(clavier);
-
- // -------------
- // start of glut
- // -------------
- glutMainLoop();
- }
|
la fonction gluLookAt a comme paramètre le centroide de l'objet que je veux dessiner. et il regarde vers ce même centroide de façon verticale
quand je fais bouger le troisième paramètre (de -1 à 1 je ne vois qu'un gros truc rouge donc il m'affiche bien mon dessin). mais dés que je passe à -1.00000001 ou 1.000000001 il ne m'affiche plus rien. |