Jump to content
  • Advertisement
Sign in to follow this  
rsjagtia

OpenGL Texture Coordinate Indexes and Vertex Arrays - Help!

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Folks, So i'm a newbie at OpenGL and graphics in general but all i'm trying to do is Render a cube with a texture mapped on to each face (Same texture). My problem is: Front/bakc face: Correct Left/Right Face: Texture is mirrored on the Y axis (i.e..its flipped so its backwards..horizontally) Top/Bottom Face: No Texture appearing Now here is the code i'm using: GLfloat textureCoords[8][2] = {{0.0, 1.0} , {1.0, 1.0}, {1.0, 0.0}, {0, 0.0}, {1.0, 1.0}, {0.0, 1.0}, {0, 0.0}, {1.0, 0.0} }; GLubyte cubeIndex[24]= {0, 1, 2, 3, 0, 4, 5, 1, 0, 4, 7, 3, 1, 5, 6, 2, 4, 5, 6, 7, 7, 6, 2, 3}; Vertex cubeVertex[8] = {Vertex(-1.0, 1.0, 1.0), Vertex(1.0, 1.0, 1.0), Vertex(1.0, -1.0, 1.0), Vertex(-1.0, -1.0, 1.0), Vertex(-1.0, 1.0, -1.0), Vertex(1.0, 1.0, -1.0), Vertex(1.0, -1.0, -1.0), Vertex(-1.0, -1.0, -1.0)}; Vertex is a struct that encapsulates the GLFloat [3] ..x,y,z The cube is rendered with the texture, its just the texture is not oriented right and no matter what indices I use for the left and right face, its always mirrored. Further more the top and bottom face show no texture at all. Now when i move the camera inside the cube, the Texture is FINE on the left and right face. A preview is found here: http://img230.imageshack.us/my.php?image=rendercw2.jpg Any help is appreciated. Thanks guys.

Share this post


Link to post
Share on other sites
Advertisement
Your vertex array contains only 8 vertices, but a cube needs 24. A vertex is not only position, but includes all other associated attributes needed to render it. The cube contains vertices at 8 unique positions, but all 8 of these are used by 3 independent faces, all with different texture coordinates (although some vertices may end up with same texture coordinates also, but that is a coincidence only). For that reason, the cube contains 3*8=24 vertices, not 8.

In other words, a cube doesn't contain any shared vertices, so there are no gain in using indexed arrays. The cube is the worst case for indexed vertex arrays. You must specify all 24 unique vertices of the cube.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!