PDA

View Full Version : Using multitexture with vertex arrays



Macinkross
06-25-2003, 04:07 PM
I'm setting up two texture coord arrays in opengl for texture units one and two. I do this with glClientActiveTextureARB.

With one unit everything works fine. My initial texture displays with the proper texture coords. However, when I enable unit two rather than displaying the new texture with the first, the first is displayed again with the coords in the second texture coordinate array. I can't seem to get the second texture to display at all.

I'm sure my units are set up right because the texturing works fine in immediate mode. Below is the code I use to set up the texture arrays :




glActiveTextureARB(GL_TEXTURE1_ARB);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(terrainVertex), &vertexList[0].s1);


glActiveTextureARB(GL_TEXTURE0_ARB);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(terrainVertex), &vertexList[0].s);


Any suggestions are greatly appreciated.


[This message has been edited by Macinkross (edited 06-25-2003).]

SirKnight
06-25-2003, 06:04 PM
The third parameter in glTexCoordPointer is the stride. That is, the byte offset between consecutive array elements. You probably should pass 0 as the stride. That means the array is tightly packed.

-SirKnight

[This message has been edited by SirKnight (edited 06-25-2003).]

Macinkross
06-25-2003, 06:20 PM
No, the stride is right, SirKnight.

The array is called vertexList which is an array of a struct I have called terrainVertex. In terrainVertex I store a vertex position (three floats) and two texture coords (two floats each).

Out of desperation, I tried 0 and (as I expected) it yielded completely bogus results.

That said, thanks for the suggestion. This glitch is halting development on my project and I have a deadline coming up. I really need to figure out whats wrong. If anyone can help please feel free to suggest something.

JotDot
06-25-2003, 07:13 PM
Since you only pasted a code snippet, I figured I'd ask just in case:

Did you remember to
1) glEnable(GL_TEXTURE_2D); on each texture unit?
2) Bind the textures for each texture unit?

Tom Nuydens
06-26-2003, 06:33 AM
Did you try glGetError()?

-- Tom

Macinkross
06-26-2003, 10:06 AM
Tom: No errors are thrown. Good idea though.

JotDot: As far as I know I set everything up right. I'm going to post the rest of my code in case someone can spot something.

This is called every time the render loop runs.



/* Texture Unit 0
__________________________________________________ ____*/

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
finalTex.bindTexture();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


/*Texture Unit 1
__________________________________________________ ______*/
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
detailMap.bindTexture();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);



The only thing I really added from immediate mode are the two lines below where I set up each unit ( I enable texture arrays for each client state).

I think there must be something little I'm doing wrong but I can't seem to find it.

JotDot
06-26-2003, 07:46 PM
I'm not really an expert in all this so I made a simple test app using your code that you posted. I loaded up two textures, set up the client vertex array, used your code shown, and then used glDrawElements() to display my image.

It works fine.

Without knowing more, I am assuming the problem lays somewhere else. ie: Currently the only way I could get this particular code to have the "first" texture to appear using the second set of texture coordinates - was to use a texture id of zero for the first unit, then the "first" texture number for the 2nd stage. Not saying that this is your problem though.

Macinkross
06-28-2003, 07:43 PM
Thanks JotDot.

The more I work with this, the more I'm starting to think its a driver problem. --Of course I've blamed things on the driver or compiler in the past and ALWAYS find that it is infact my fault. So, I dunno.

I'm going to keep working though. Thanks for the help.