I have basic texture mapping working. I have a targa mapped onto a quad. However, if I try to enable depth testing or backface culling, the quad disappears. Does texture mapping not work with depth testing/backface culling?

Thanks,
Greg

Dixie Dude

05-30-2001, 12:25 PM

well, try to "flip" your quad. Perhaps you drawn it backwards so when you enable backface culling you disable your quad.

gtada

05-30-2001, 12:53 PM

Thanks Dixie Dude, it was there. I'm a moron. http://www.opengl.org/discussion_boards/ubb/wink.gif

Now I have a different problem. When I rotate the quad along the X or Y axis, the texture "stays in place." It looks like it's just projected through the quad, and not ON the quad. However, if I rotate along the Z axis, the texture rotates with the quad. What did I do?!!

Deiussum

05-31-2001, 05:40 AM

Are you giving specific texture coordinates or using glTexGen to generate texcoords for you?

I haven't had any troubles learning OpenGL up to this point. Is texturemapping that hard?

Deiussum

05-31-2001, 10:03 AM

You've got things backwards there. You need to put the glTexCoord calls first. Think of it as a state machine... when you call glVertex it will use whatever the current texcoord/color/etc is. Since you don't set the texcoords until AFTER the vertex, that texcoord won't be used until the NEXT vertex call. So... on the next drawn frame your first vertex is going to have the texcoord that you used on your last line there.

gtada

05-31-2001, 11:20 AM

Ah. Now the bitmap is rightside-up, but the other problem still exists. It still looks like the texture is just projected on to the quad, so when I rotate the quad around the Y or X axis, the texture doesn't foreshorten. Any ideas?

Korval

05-31-2001, 12:53 PM

There are three possibilities.

1) You aren't setting anything in the texture matrix, right?

2) You may want to try glHint(GL_PERSPECTIVE_CORRECT) (I think that's the right syntax for it).

3) Also, though I doubt this is the cause, make sure you aren't putting your camera matrix in your GL_PROJECTION matrix. It could call perspective correction problems.

gtada

06-01-2001, 09:09 AM

Deiussum and Korval,
I have no idea what I've done. From what I can see (which ain't much, I'm relatively new to this), I don't see what I'm doing wrong. So, here's the code that I do have:

Your primary problem is that you are using an orthographic projection matrix, which does not do any perspective correction for you. What that means is, that your quad will look the same no matter how far away it. Try using gluPerspective instead.

Secondly, you have your far plane set to a lower value than your near plane. While that isn't what was causing your issue in this case, it would probably be wise not to do that. Note that when you use gluPerspective both the near and far planes MUST > 0.0. (Note: NOT >= 0.0 but > 0.0) Using 0 for the near clip plane will cause problems, just as using a far clip plane < the near plane will cause problems. http://www.opengl.org/discussion_boards/ubb/smile.gif