PDA

View Full Version : OpenGL multiple textures same surface, problem



theguy126
05-27-2011, 06:54 PM
Hello I'm trying to get multiple textures on the same big multi-polygon surface in openGL. to do this I use the glActiveTextureARB and glClientActiveTextureARB to set the texture (just 2 different textures I use, texture and focusedTexture), and set their correct coordinates and enable everything. After I set these up I call a lot of glDrawElements() to draw a surface.

However, the surface only has the LATTER texture that was enabled!

//excerpt of code

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);


glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, focusedTexture);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, focusedTexCoords);

then I call

//excerpt of code
glBindBufferARB(GL_ARRAY_BUFFER_ARB, cVboId);
glColorPointer(3, GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, nVboId);
glNormalPointer(GL_FLOAT, 0, 0);

then I have a for loop that calls a lot of times: glDrawElements(GL_QUAD_STRIP, 2*maxXres, GL_UNSIGNED_INT, quadIndices[i5]);

I even made a hotkey for debugging that switches between three states: case 1 tries to render both, case 2 tries to render texture only, case 3 tries to render focusedTexture only. Cases 2 and 3 both work but Case 1 only does whatever texture is enabled last (in this instance, focusedTexture). Help please.

edit: i also tried changing the modes of the GL_TEXTURE_ENV to GL_INCR or GL_ADD or GL_MODULATE to make sure it's not just hidden behind the other texture, and still it doesn't show up.

V-man
05-28-2011, 12:48 AM
Those function calls are only part of the whole picture.
If you are using glTexEnv, here are examples:
http://www.opengl.org/wiki/Texture_Combiners

If you want a debugger,
http://www.opengl.org/wiki/Debugging_Tools

As for your half VBO and half non-VBO code, I don't know if that works.

Also, I strongly recommend that you download some code. There are a lot of multitexturing examples out there (really old examples):
http://www.lighthouse3d.com/tutorials/glsl-tutorial/multi-texture/

http://www.informit.com/articles/article.aspx?p=770639&seqNum=5

http://nehe.gamedev.net/lesson.asp?index=05
http://www.gamedev.net/topic/55191-gl_arb_multitexture-extension/

theguy126
05-28-2011, 01:17 PM
Those function calls are only part of the whole picture.
If you are using glTexEnv, here are examples:
http://www.opengl.org/wiki/Texture_Combiners


I already tried the default glTexEnv settings recommended by all the tutorials I read including replace and/or modulate etc. I'll try those out when I get back to work but I seriously doubt they will change anything.



If you want a debugger,
http://www.opengl.org/wiki/Debugging_Tools

ok maybe



As for your half VBO and half non-VBO code, I don't know if that works.

It works. Before I started doing multi-texturing I was already doing colors and vertices with VBO and texture non-vbo



Also, I strongly recommend that you download some code. There are a lot of multitexturing examples out there (really old examples):
http://www.lighthouse3d.com/tutorials/glsl-tutorial/multi-texture/

http://www.informit.com/articles/article.aspx?p=770639&seqNum=5

http://nehe.gamedev.net/lesson.asp?index=05
http://www.gamedev.net/topic/55191-gl_arb_multitexture-extension/


I have already looked at half of these but I guess I'll give it a shot, though I think they all contain basically the same tutorial