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

Texture Coordinates and Indices

Started by cHimura Apr 26, 2011 at 4:45 AM 3 replies 1k views
Original Post
cHimura
cHimura
Hi,

I have 8 vertex and with the indices I create a cube. The cube shows correctly but the texture doesn't show correctly.

This is my code of the vertex with normals and uv texture.



struct CUSTOMVERTEX {
FLOAT x, y, z;
FLOAT nx, ny, nz;
FLOAT tu, tv;
};

CUSTOMVERTEX cube[] = {
{-1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, //v1
{-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f}, //v2
{1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
{1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f},

{-1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
{1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f},
{1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f},
{-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f}
};


How must I place texture coordinates??

Thanks.
TomKQT
TomKQT
It's hard to belive the cube is drawing correctly because all your vertices have the same normal (pointing towards the +y axis). A cube consists of 6 sides and only one of them has this normal => you need 6 different normals (+x, -x, +y, -y, +z, -z), not just 1.
To draw a proper cube with proper lighting and texture coordinates, you cannot go with just 8 vertices. Yes, a cube in theory has just 8 vertices, but each of those 8 vertices is shared by 3 sides of the cube, forcing you to have all the 3 sides share the same parameters in that vertex - this is favourable with position (because position really is shared), but not with normal and texture coordinates.

You'll have to specify 4 vertices per side (6 sides), that means 24 vertices in total.


To understand what was wrong with your texture coordinates, try to draw a cube on a paper (in "3D") and write your coordinates to each vertex. And then verify whether each side has all combinations of coordinates:
0, 0
1, 0
0, 1
1, 1
I bet you'll find out that it's not true in your case.
Mayatrone
Mayatrone
Hi,
First, you'll have to fix your normals and second, you'll need 24 vertices as Tom KQT said. A normal cube does apper to have only 8 vertices. This means that 1 vertex is shared with 3 sides of the cube. But those 3 sides of the cube have different normals/texture coordinates, so you'll have to describe 24 vertices.
Evil Steve
Evil Steve
Another way of saying the same thing as the previous two posters: A vertex is not just a position, it's a position, normal and texture coordinate (in your case). You can only share a vertex if the position, normal and texture coordinates are the same - which they're not for the 8 corners of a cube, only the positions are the same.
cHimura
cHimura
Ok, perfect!!

I fix it and now works fine!

Thanks for your answers.

Topic Locked

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

Sign in to reply to this topic.