Texture Generation - the boy who couldn't.

Started by
2 comments, last by bencelot 15 years, 9 months ago
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.
--------------------------Check out my free, top-down multiplayer shooter: Subvein
Advertisement
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.



--------------------------Check out my free, top-down multiplayer shooter: Subvein
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
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.
--------------------------Check out my free, top-down multiplayer shooter: Subvein

This topic is closed to new replies.

Advertisement