Bonjour,
Je suis debutant en OpenGL et j'ai un petit soucis pour mapper une texture sur une surface. Elle refuse tout simplement de s'afficher (la surface s'affiche tout en blanc)... Comme ca fait des heures que je tourne en rond sans trouver la source du probleme.... je m'en remets a vous!j'ai essaye de mettre autant d'information que possible ci-dessous.
Merci d'avance!
Greg
mon code d'initialisation:
initialisation de ma texture:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 void initOpenGL(void) { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow("Close me to terminate"); glClearColor(0.3, 0.3, 0.5, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); }
et, finalement le code d'affichage...
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 int s = 256; // 256*256 texture Vector<Point3D<unsigned char> > tex(s*s, true); // RGB texture Vector<pair<float, float> > texMap(M*N, true); // mapping vertex->texture // fill texture with dummy values int k = 0; for (int i = 0; i < s; ++i){ for (int j = 0; j < s; ++j) { tex[k].x = 255*float(i) / s; tex[k].y = 255*float(i) / s; tex[k].z = 255*float(i) / s; k ++; } } for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { texMap[k].first = float(i) / M; texMap[k].second = float(j) / N; k ++; } } glEnable (GL_TEXTURE_2D); GL_CHECK_ERROR(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); GL_CHECK_ERROR(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); GL_CHECK_ERROR(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL_CHECK_ERROR(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL_CHECK_ERROR(); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); GL_CHECK_ERROR(); // generate one new identifier for the texture glGenTextures(1, &textureHandle); GL_CHECK_ERROR(); // bind it to a 2d texture, therearfter GL_TEXTURE_2D will refer to 'textureHandle' glBindTexture(GL_TEXTURE_2D, textureHandle); GL_CHECK_ERROR(); // specifiy the texture to OpenGL glTexImage2D(GL_TEXTURE_2D, // refers to textureHandle, as it was bound before 0, // level op mipmap (not used for now...) GL_RGB, // texture internal format is RGB (what will be in the GPU) s,s, //Mtex, Ntex, // size of the texture 0, // border size, color can be set with GL_TEXTURE_BORDER_COLOR parameter GL_RGB, // format of the array passed in parameter below is RGB GL_UNSIGNED_BYTE,// texture are passed in 8 bits per channel tex.getInternalData() ); GL_CHECK_ERROR();
Ceci est suivit d'un swapBuffer().
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 virtual void draw(const Camera& cam) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0, // <- Y camera field-of-view, in degrees glutGet(GLUT_WINDOW_WIDTH)/(float)glutGet(GLUT_WINDOW_HEIGHT), // viewport's aspect ratio 0.001, // Near clipping plane depth 200000.0 // Far clipping plane depth ); lookAt(cam_); static bool textureEnabled = true; static bool colorEnabled = false; glEnable (GL_TEXTURE_2D); // we'll draw an array of vertices glEnableClientState(GL_VERTEX_ARRAY); GL_CHECK_ERROR(); // with textures... if (textureEnabled) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); GL_CHECK_ERROR(); } // and colors if (colorEnabled) { glEnableClientState(GL_COLOR_ARRAY); GL_CHECK_ERROR(); } // give OpenGL a pointer to the vertices glVertexPointer(3, GL_FLOAT, 0, vertices.getInternalData()); GL_CHECK_ERROR(); // give OpenGL a pointer to the texture if (textureEnabled) { glTexCoordPointer(2, GL_FLOAT, 0, texMap.getInternalData() ); GL_CHECK_ERROR(); } // give OpenGL a pointer to the colors if (colorEnabled) { glColorPointer( 3, GL_UNSIGNED_BYTE, 0, tex.getInternalData() ); GL_CHECK_ERROR(); } glDrawElements(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, indices.getInternalData() ); GL_CHECK_ERROR(); //glDrawArrays(GL_POINTS, 0, vertices.size()); if (colorEnabled) { glDisableClientState( GL_COLOR_ARRAY ); GL_CHECK_ERROR(); } if (textureEnabled) { glDisableClientState(GL_TEXTURE_COORD_ARRAY); GL_CHECK_ERROR(); } glDisableClientState(GL_VERTEX_ARRAY); GL_CHECK_ERROR(); }
notez que ca fonctionne si j'utilise "glColorPointer". GL_CHECK_ERROR() juste teste glGetError(), dans mon cas glGetError vaut toujours GL_NO_ERROR.
Help![]()
Partager