Bonjour,
Pour un projet, j'ai à faire une petite interface graphique en OpenGL et on nous a imposé d'utiliser GLUT.
Aussi mes premiers test fonctionnait pour le mieux sans avoir fait de classe, mais vu que pour le projet faire une classe s'impose, je m'y essai laborieusement depuis hier soir en vain.
J'ai fait des recherche sur Google, et en fait c'est un problème avec les fonctions static.
Berf le code et les messages d'erreur valant mieux qu'un long discours donc je vous envoie le code de ma classe et les erreurs de sorties.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 // LIBRAIRIES et COMMANDE Linux : #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <stdlib.h> #include <cassert> #include <fstream> #include <iostream> #include "Mesh2d.hpp" #include "Visual3d.hpp" class Visual3d{ public: //static Visual3d* pVisual3d; double xold, yold, anglex, angley, presse; Mesh2* pTh; Visual3d(int argc, char** argv){ Mesh2 Th("alexis.msh"); pTh=&Th; anglex=0; angley=0; presse=0; xold=0; yold=0; glutInit(&argc, argv); /* affichage couleur */ glutInitDisplayMode(GLUT_RGB); glutInitWindowSize(400, 400); // Taille ini glutInitWindowPosition(200,200); /* position initiale */ glutCreateWindow(argv[0]); /* creation de la fenetre graphique */ init(); glutDisplayFunc(afficher); /* fonction daffichage */ glutReshapeFunc(refenetrer); // fonction de refenetrage glutKeyboardFunc(clavier); /* gestion du clavier */ glutMouseFunc(mouse); /* fonction souris */ glutMotionFunc(mousemotion); /* deplacement de la souris */ glutMainLoop(); /* lancement de la boucle principale */ } static void init(){ glClearColor(0.3,0.3,0.3,0.3); // Color Used glColor3f(1.0,1.0,1.0); /* couleur courante */ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } static void afficher(void){ glClear(GL_COLOR_BUFFER_BIT); // effacement du tampon // Renommage complet glColor3f(0,0,0); for(int i=0;i<(*pTh).nt;++i){ glBegin(GL_TRIANGLE_STRIP); glVertex3f((*pTh).triangles[i].vertices[0]->x,(*pTh).triangles[i].vertices[0]->y,0.); glVertex3f((*pTh).triangles[i].vertices[1]->x,(*pTh).triangles[i].vertices[1]->y,0.); glVertex3f((*pTh).triangles[i].vertices[2]->x,(*pTh).triangles[i].vertices[2]->y,0.); glEnd(); } glColor3f(0.5,0.5,0.9); for(int i=0;i<(*pTh).nbe;++i){ glBegin(GL_LINES); glVertex3f((*pTh).be(i)[0].x,(*pTh).be(i)[0].y,0.); glVertex3f((*pTh).be(i)[1].x,(*pTh).be(i)[1].y,0.); glEnd(); } /* glColor3f(1.0,1.0,1.0); glLineWidth(1.); glBegin(GL_LINES); glVertex3f(12.0,3.0,5.0); glVertex3f(15.0,1.0,2.0); glEnd(); glBegin(GL_LINES); glVertex3f(15.0,1.0,2.0); glVertex3f(19.0,1.0,2.0); glEnd(); */ glLoadIdentity(); // On initialise la matrice de translation //gluLookAt(-1.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0); glRotatef(-anglex, 0.0, 1.0, 0.0); // pour faire des rotation glRotatef(-angley, 1.0, 0.0, 0.0); glutSwapBuffers(); } static void refenetrer(int w, int h){ glViewport(0, 0, (GLsizei) w, (GLsizei) h); /* modification des tailles */ /* du tampon daffichage */ glMatrixMode(GL_PROJECTION); /* pile courante = projection */ glLoadIdentity(); /* specification de la projection */ glOrtho(-40.0,40.0,-40.0,40.0,-40.0,40.0); glMatrixMode(GL_MODELVIEW); /* pile courante = point de vue */ glLoadIdentity(); } static void clavier(unsigned char touche, int x, int y){ switch(touche){ // en fonction des touches, on affiche : case 'p': glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Texture glutPostRedisplay(); // Raffraichissement break; case 'f': glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Arrête glutPostRedisplay(); break; case 's': glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); // Point glutPostRedisplay(); break; case 'd': glEnable(GL_DEPTH_TEST); // Avec tampon de profondeur glutPostRedisplay(); break; case 'D': glDisable(GL_DEPTH_TEST); // Sans tampon de profondeur glutPostRedisplay(); break; case 27: /* sortie si touche ESC */ exit(0); break; } } static void mouse(int button, int state, int x, int y){ // Si on appuie sur le bouton gauche if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { presse = 1; // Le booléen passe devient vrai xold = x; // On sauvegarde la position yold = y; } // Si on relache le bouton if(button == GLUT_LEFT_BUTTON && state == GLUT_UP) presse = 0; } static void mousemotion(int x, int y) { if(presse == 1) { // Si le bouton est pressé anglex = anglex + (x-xold); // On modifie la position actuelle de la souris angley = angley + (y-yold); // en fonction de la position actuelle de la glutPostRedisplay(); // souris et de la dernière sauvegarde } xold = x; // On sauvegarde la position actuelle de la souris yold = y; } }; int main(int argc, char* argv[]){ Visual3d win(argc,argv); return 0; }Merci à tous
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 [alexis@localhost new]$ make g++ -L/usr/lib/X11R6 -lglut -lGLU -lGL -Wall -O3 -I../RNM-v3 -c Visual3d.cpp Visual3d.cpp: In static member function static void Visual3d::afficher(): Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:63: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:65: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:65: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:66: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:66: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:67: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:67: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:71: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:73: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:73: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:74: error: from this location Visual3d.cpp:26: error: invalid use of member Visual3d::pTh in static member function Visual3d.cpp:74: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::anglex in static member function Visual3d.cpp:93: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::angley in static member function Visual3d.cpp:94: error: from this location Visual3d.cpp: In static member function static void Visual3d::mouse(int, int, int, int): Visual3d.cpp:25: error: invalid use of member Visual3d::presse in static member function Visual3d.cpp:143: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::xold in static member function Visual3d.cpp:144: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::yold in static member function Visual3d.cpp:145: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::presse in static member function Visual3d.cpp:148: error: from this location Visual3d.cpp: In static member function static void Visual3d::mousemotion(int, int): Visual3d.cpp:25: error: invalid use of member Visual3d::presse in static member function Visual3d.cpp:153: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::anglex in static member function Visual3d.cpp:154: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::anglex in static member function Visual3d.cpp:154: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::xold in static member function Visual3d.cpp:154: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::angley in static member function Visual3d.cpp:155: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::angley in static member function Visual3d.cpp:155: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::yold in static member function Visual3d.cpp:155: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::xold in static member function Visual3d.cpp:158: error: from this location Visual3d.cpp:25: error: invalid use of member Visual3d::yold in static member function Visual3d.cpp:159: error: from this location make: *** [Visual3d.o] Error 1
Partager