Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture coordinate generation + multitexturing

Started by methe Sep 20, 2006 at 6:06 AM 4 replies 900+ views
Original Post
methe
methe
Hi there, I've followed a tutorial (http://cityintherain.com/howtotex.html) on how to enable automatic texture coordinate with multitexturing on. Here is the set up of the stuff:

           // Parameter used by the automatic texture coordinate generation
           // Define how the S parameter depends on x, y, z, w
          GLfloat paramS[ ] = {1.0, 0.0, 0.0, 0.0};

          // Define how the T parameter depends on x, y, z, w
          GLfloat paramT[ ] = {0.0, 1.0, 0.0, 0.0};

           //We give the elevation as texture 0
          glActiveTexture(GL_TEXTURE0);
          glEnable(GL_TEXTURE_2D);
          glBindTexture(GL_TEXTURE_2D, gl_altitude_id);
          glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

           //Set automatic coord generation for texture 1
          //Set automatic texture coord generation for S axis
          glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
          glTexGenfv(GL_S, GL_OBJECT_PLANE, paramS);

          //Set automatic texture coord generation for T axis
          glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
          glTexGenfv(GL_T, GL_OBJECT_PLANE, paramT);

          //Enable automatic texture coordinate generation for S and T axis
          glEnable(GL_TEXTURE_GEN_S);
          glEnable(GL_TEXTURE_GEN_T);

          //We give the normal as texture 1
          glActiveTexture(GL_TEXTURE1);
          glEnable(GL_TEXTURE_2D);
          glBindTexture(GL_TEXTURE_2D, gl_normal_id);
          glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

          //Set automatic coord generation for texture 2
          //Set automatic texture coord generation for S axis
          glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
          glTexGenfv(GL_S, GL_OBJECT_PLANE, paramS);

          //Set automatic texture coord generation for T axis
          glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
          glTexGenfv(GL_T, GL_OBJECT_PLANE, paramT);

          //Enable automatic texture coordinate generation for S and T axis
          glEnable(GL_TEXTURE_GEN_S);
          glEnable(GL_TEXTURE_GEN_T);

          glActiveTexture(GL_TEXTURE2);
          glDisable(GL_TEXTURE_2D);

          glBegin(GL_POLYGON);
//             glMultiTexCoord2f(GL_TEXTURE0, 0.0, 0.0);
//             glMultiTexCoord2f(GL_TEXTURE1, 0.0, 0.0);
            glVertex2f(0.0, 0.0);
//             glMultiTexCoord2f(GL_TEXTURE0, 1.0, 1.0);
//             glMultiTexCoord2f(GL_TEXTURE1, 1.0, 1.0);
            glVertex2f(1.0, 1.0);
//             glMultiTexCoord2f(GL_TEXTURE0, 0.0, 1.0);
//             glMultiTexCoord2f(GL_TEXTURE1, 0.0, 1.0);
            glVertex2f(0.0, 1.0);
          glEnd();

Note that if I comment all code for automatic texture coord generation and uncomment the manual glMultiTexCoord2f() calls, everything works fine, proving the mistake is not in other part of the setup but simply the texture coord generation. Your eyes and wisdom are appreciated. :) [Edited by - methe on September 20, 2006 7:25:48 AM]
"A man does what he does because he sees the world as he sees it." A.K
e-u-l-o-g-y
e-u-l-o-g-y
I can't see that you told us what the problem is ;)
By the way - please use source tags when posting code (read the FAQ for more information :)
my-eulogy - A blog about coding and gfxsdgi - Semi-Daily Game IdeaChunkyHacker - Viewer for Relic chunky formats (used in DOW)
methe
methe
Well the problem is simply that the textures don't show up. Both the automatic texture generation and the by-hand (commented glMultiTexCoord2f()) should produce the same result and they obviously don't. I can't find what's wrong with the coordinate generation.
Now, to get the full story, theses textures are used in a shader turned on just before the pasted code. These shaders work perfectly in the case of by-hand texture coordinate and not in the automatic way. If there is nothing special to do in shaders when using multitexturing then I suppose the texture generation initialization is wrong which I have no clue where and how, leading to my request. :)
"A man does what he does because he sees the world as he sees it." A.K
Lord_Evil
Lord_Evil
Afaik shaders don't work with glTexGen, so you would have to build the texture coordinates in your shader on your own.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
methe
methe
This explains it all...
And now I'm gonna slap the guy next door for having stolen my Orange Book.

thanks for the answer anyway!
"A man does what he does because he sees the world as he sees it." A.K
methe
methe
Added coord generation in my shader and everything works great! Thanks guys. Only detail: The shader works great on my computer but I have a shader compile error on another one! 0_o gonna inquiry that.
log:
Internal error: assembly compile error for vertex shader at offset 9388:
-- error message --
line 137, column 11: error: invalid operand variable
line 141, column 11: error: invalid operand variable
line 143, column 27: error: invalid operand variable

with about 200 lines below of stuffs. Ö_°


"A man does what he does because he sees the world as he sees it." A.K

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.