UV problems moving from fixed func to shaders

Hello all,

I’m very new to GLSL, so apologies in advance if any of the stuff below is very elementary :wink:
Here are a couple of questions to kick things off (I’m sure there’ll be more ;-))

  1. When using shaders, do I still need to call glEnable(GL_TEXTURE_2D); ?
    Trial and error showed that as long as I glBindTexture, then I can do something like
    gl_TexCoord[0] = gl_MultiTexCoord0;
    and everything seemed to work fine. Is a glEnable(GL_TEXTURE_2D) necessary?

And now to the more important point!
2) In my fixed func stuff, I used to pass a pointer to my tex coords before calling glDrawElements and then the following code would make sure my texture generation was all good.

const GLfloat sPlane[] = { 1.0f/someVal, 0.0f, 0.0f, 0.0f } ;
const GLfloat tPlane[] = { 0.0f, 0.0f, 1.0f/someVal, 0.0f } ;

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

Having moved to shaders, passing the same UVs and doing this on the vert shader:
gl_TexCoord[0] = gl_MultiTexCoord0;
doesn’t have the same effect…
This makes sense, I just have no idea how to make my shader work the same way the fixed func stuff used to.

Any help much appreciated.

cheers,
g.

  1. You do not have to call glEnable(texture target) when using shaders, only when using the fixed function pipeline.

  2. Your vertex shader would need to compute your texture coordinate like so:

gl_TexCoord[0].s = dot(gl_Vertex, gl_ObjectPlaneS[0]);
gl_TexCoord[0].t = dot(gl_Vertex, gl_ObjectPlaneT[0]);
gl_TexCoord[0].p = dot(gl_Vertex, gl_ObjectPlaneR[0]);
gl_TexCoord[0].q = dot(gl_Vertex, gl_ObjectPlaneQ[0]);

Super!
Thx for the help!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.