PDA

View Full Version : Problems passing UV coords.



Baggio
06-02-2005, 06:51 AM
I'm using VBOs and shaders. Now everything works fine with one exception, I can get the lightmap UVs. Here is struct I use to store the info.

struct MeshVert {
vec3 position; /**< Vertex position. */
vec3 normal; /**< Vertex normal. */
vec3 tangent; /**< Tangent of the vertex. */
vec3 biTangent; /**< bitangent of the vertex. */
vec2 UV; /**< UV coordinates. */
vec2 lightmapUV; /**< UV coordinates for the lightmaps. */
};Now everything is in the card already, and this is how I specify which value to use, etc.

glVertexPointer(3, GL_FLOAT, sizeof(MeshVert), 0);
glNormalPointer(GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 1));
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 4));
glClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)((sizeof(vec3) * 4) + sizeof(vec2)));
glClientActiveTextureARB(GL_TEXTURE2);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 2));
glClientActiveTextureARB(GL_TEXTURE3);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 3));The problem is that when I get the UVs in the shaders using gl_MultiTexCoord1.xy it doesn't work unless I comment the code that puts the info for GL_TEXTURE2 and GL_TEXTURE3.

Anybody has any ideas?

PS: I'm on a GeForce 6800 Ultra with drivers version 76.10.

Aeluned
06-02-2005, 07:16 AM
All I can tell you is that the behavior of GLSL almost varies with each driver.

I had all sorts of problems with various drivers,
once loops didn't work, then texture lookups act all weird, etc...it's a headache.

It's still all very buggy, throw in a beta driver like the 76. and all hell breaks loose.

My shaders are ok with the 66.93 driver at the moment.

I know it's not a help, but I just wanted to let you know that <Clinton voice> I feel your pain </Clinton voice>

Baggio
06-02-2005, 09:22 AM
Originally posted by Aeluned:
All I can tell you is that the behavior of GLSL almost varies with each driver.

I had all sorts of problems with various drivers,
once loops didn't work, then texture lookups act all weird, etc...it's a headache.

It's still all very buggy, throw in a beta driver like the 76. and all hell breaks loose.

My shaders are ok with the 66.93 driver at the moment.

I know it's not a help, but I just wanted to let you know that <Clinton voice> I feel your pain </Clinton voice>I changed the drivers to 76.50 and it didn't work, and I also got a chance to run it on a Radeon 9700 and it didn't work either, so I don't think the drivers are the problem. I also know that since I comment some of the lines as I said before and it works, then my data must be right. It must be something to do with how I specify what part of MeshVert specifies the UVs for GL_TEXTURE1, I just don't know what's the problem.

Baggio
06-03-2005, 03:02 AM
Nobody has any idea? I really need some help with this.

Thanks.

T101
06-03-2005, 03:42 AM
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 2)); Notice anything?

Baggio
06-03-2005, 04:46 AM
Originally posted by T101:

glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 2)); Notice anything?Not really. If you look at the MeshVert structure you see that the tangent for the vertex is a vec3 which is equal to three floats, that explains the first parameter. Also, if you see the MeshVert structure you will see that the position of the tangent for the vertex is right after two vec3s which explains why I point to sizeof(vec3) * 2.

Dirk
06-03-2005, 05:05 AM
Originally posted by Baggio:
The problem is that when I get the UVs in the shaders using gl_MultiTexCoord1.xy it doesn't work unless I comment the code that puts the info for GL_TEXTURE2 and GL_TEXTURE3.That smells like you don't call glEnableClientState() for the 3 texcoords individually but just for one (probably the last one, whatever that is).

Hope it helps

Dirk

HellKnight
06-03-2005, 05:21 AM
Try glVertexAttribPointerARB instead of glTexCoordPointer for passing the tex coords. That's the way I'm doing it, and the vertex structure I'm using is very similar to yours. Also dont forget to glEnableVertexAttribARB.

Hope that helps.

Baggio
06-03-2005, 05:45 AM
Originally posted by dirk:

Originally posted by Baggio:
The problem is that when I get the UVs in the shaders using gl_MultiTexCoord1.xy it doesn't work unless I comment the code that puts the info for GL_TEXTURE2 and GL_TEXTURE3.That smells like you don't call glEnableClientState() for the 3 texcoords individually but just for one (probably the last one, whatever that is).

Hope it helps

DirkTHANKS! that was it, I didn't know that I had to call glEnableClientState() for each(the OpenGL redbook seems to state that you only call one per type of array, here is a quote "The first step is to call glEnableClientState() with an enumerated parameter, which activates the chosen array. In theory, you may need to call this up to six times to activate the six available arrays. In practice, you'll probably activate only between one to four arrays."). What about glDisableClientState()? Right now I just call it once for each type of array after calling glDrawElements(), is that right?

Baggio
06-03-2005, 05:48 AM
Originally posted by HellKnight:
Try glVertexAttribPointerARB instead of glTexCoordPointer for passing the tex coords. That's the way I'm doing it, and the vertex structure I'm using is very similar to yours. Also dont forget to glEnableVertexAttribARB.

Hope that helps.Yeah, I have been thinking about that but one plus of the approach I'm using is that I don't actually have to get the location of the attrib, and define it in the shader, instead I just use for example "gl_MultiTexCoord2.xyz" to get the tangent for that vertex. But I will think about it, thanks for the idea.

Chuck0
06-03-2005, 07:00 AM
Originally posted by Baggio:
... What about glDisableClientState()? Right now I just call it once for each type of array after calling glDrawElements(), is that right?no you have to call it for each texture coordinate set (like you have to enable each set separatelly).

thus something like that is necessary:

glClientActiveTextureARB(GL_TEXTURE0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE2);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE3);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);