🔒 Locked
Problem with multitexturing and vertex array
Advertisement
Original Post
I render a terrain (heightmap) with a vertex array and i use multitexturing for the terain texture (terrain tex and detail tex).
The terrain look great but the problem i have is that any other texture (not multitexturing) show the terrain texture.
(ex: the skybox show a blending of the skybox texture and the terrain texture)
If i do not render the terrain, the other texture work fine.
here is the code i use to render my terrain:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_TEX].texID);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_DETAIL].texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, nb_vertex);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
to render the other texture (ex: skybox)
glBindTexture(GL_TEXTURE_2D, texture[BACK_ID].texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);
glEnd();
...
(sorry for my english)
i tried and changed my code like this
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_TEX].texID);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_DETAIL].texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, nb_vertex);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
nom, the normale texture are fine but the mukltitexturing don''t work: i see the terrain texture but not the detail texture
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_TEX].texID);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_DETAIL].texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, nb_vertex);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
nom, the normale texture are fine but the mukltitexturing don''t work: i see the terrain texture but not the detail texture
Try changing the glTexEnv code to this:
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
What you''re doing just seems to scale the colours of the detail texture, but not specify what texture combining operation to use.
Hope this helps. . .
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
What you''re doing just seems to scale the colours of the detail texture, but not specify what texture combining operation to use.
Hope this helps. . .
You need to call glEnableClientState(GL_TEXTURE_COORD_ARRAY) and glDisableClientState(GL_TEXTURE_COORD_ARRAY) for each texture unit. What''s happening is that the first time through the code, texture unit 0 is active, so you enable it. By the time you hit disable, texture unit 1 is active, so it''s the one that gets deactivated - texture unit 0 still has tex coord arrays enabled. The second and every other time through the code, texture unit 1 is the one that''s active on entry, so you enable it, and then it gets disabled at the end of the code. I think that''s what causing your problem.
You need to enable/disable the texture coordinate array for each client side texture unit.
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Use glDisable(GL_TEXTURE_2D) once you''ve finnished using multitexturing, to disable the TextureUnits you''re not using. Then set the active texture unit back to TextureUnit0. ie
glActiveTextureARB(GL_TEXTURE2_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
...etc.
glActiveTextureARB(GL_TEXTURE2_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
...etc.
now it works, thank you all for your help
here is my code nom
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_TEX].texID);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_DETAIL].texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, nb_vertex);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
here is my code nom
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_TEX].texID);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, texture_array);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindTexture(GL_TEXTURE_2D, texture[TERRAIN_DETAIL].texID);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, nb_vertex);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
You don''t have to enable/disable the vertex array for each texture unit. Only the texture coordinate array.
the other texture are ok but now i have a little other problem: the other texture are a little darker. If i change "detail" from my code
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
the brithness of all other texture change. detail=16 is the darker.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(detail, detail, 1);
glMatrixMode(GL_MODELVIEW);
the brithness of all other texture change. detail=16 is the darker.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement