Sign in to follow this  
bencelot

Texture Generation - the boy who couldn't.

Recommended Posts

Hey all, I'm having trouble getting my mind around texture generation. All I'm trying to do (for now) is project a texture onto a single quad, but nothing shows up. Please check to see if I'm doing anything wrong: void DrawImage() { //I know there's nothing wrong with this line glBindTexture(GL_TEXTURE_2D, prettyImage); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); //Setting the planes to generate the texture from GLfloat xPlane[] = {1,0,0,0}; GLfloat yPlane[] = {0,1,0,0}; glTexGenfv(GL_S, GL_OBJECT_PLANE, xPlane); glTexGenfv(GL_T, GL_OBJECT_PLANE, yPlane); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); //Scaling the texture so it perfectly fits the size of the quad glMatrixMode( GL_TEXTURE ); glPushMatrix(); glLoadIdentity(); glScalef(1.0/1280.0, 1.0/1024.0, 1.0 ); glPopMatrix(); glMatrixMode( GL_MODELVIEW ); glEnable(GL_TEXTURE_2D); glColor4f(1,1,1,1); //Rendering the quad glBegin(GL_QUADS); glVertex2f(0,1024); glVertex2f(1280,1024); glVertex2f(1280,0); glVertex2f(0,0); glEnd(); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } What's meant to happen: Every frame this function is called. It binds our pretty image, turns on texture generation, aligns & scales the projected texture so that it will perfectly cover the quad, and then renders. However, all I see is a blank screen. I know I'm binding the texture correctly, and I know that the quad is rendering to the screen because it shows up fine if I don't have any texture generation stuff. Can anyone see what I'm missing? Thanks, Ben.

Share this post


Link to post
Share on other sites
lol, oops.

glMatrixMode( GL_TEXTURE );
glPushMatrix();
glLoadIdentity();
glScalef(1.0/1280.0, 1.0/1024.0, 1.0 );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );

Achieves absolutely nothing. Silly me.


glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glScalef(1.0/1280.0, 1.0/1024.0, 1.0 );
glMatrixMode( GL_MODELVIEW );

Much better.



Share this post


Link to post
Share on other sites
If I may: is the point of this to learn about texture coordinate generation, or to get the texture mapped onto the quad?

If the second is true, it would be considerably more straight-forward to just provide the texture coordinates directly.

Cheers,
--Brian

Share this post


Link to post
Share on other sites
It's just to learn. Now that I've got it scaling correctly, I've applied my 2D shadow map to my 3D map. It looks beautiful.


Now I've got to learn how to multitexture.. so the shadows are cast over the map, along with the grass/road textures that I originally had.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this