Jump to content
  • Advertisement
Sign in to follow this  
tenpoundbear

Texture Cube with Index Buffer

This topic is 2710 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 Guys,

I am drwing a cube with a texture on it using index buffer. Unfortunately, the last side of the cude isn't showing the texture correctly... the 5 other sides are showing it fine.

I've checked the texture cordinates for the last 2 hours... don't know what the problem is sadly.

texturecubeindex.jpg

This is the bulk of the code for the cube.
[source]
//back
planet[ 0 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 30.0f ); planet[ 0 ].normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
planet[ 1 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 30.0f ); planet[ 1 ].normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
planet[ 2 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 30.0f ); planet[ 2 ].normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
planet[ 3 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 30.0f ); planet[ 3 ].normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );

//front
planet[ 4 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 20.0f ); planet[ 4 ].normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
planet[ 5 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 20.0f ); planet[ 5 ].normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
planet[ 6 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 20.0f ); planet[ 6 ].normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
planet[ 7 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 20.0f ); planet[ 7 ].normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );

//bottom
planet[ 8 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 20.0f ); planet[ 8 ].normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
planet[ 9 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 30.0f ); planet[ 9 ].normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
planet[ 10 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 30.0f ); planet[ 10 ].normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
planet[ 11 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 20.0f ); planet[ 11 ].normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );

//top
planet[ 12 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 20.0f ); planet[ 12 ].normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
planet[ 13 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 30.0f ); planet[ 13 ].normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
planet[ 14 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 30.0f ); planet[ 14 ].normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
planet[ 15 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 20.0f ); planet[ 15 ].normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );

//right side
planet[ 16 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 20.0f ); planet[ 16 ].normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
planet[ 17 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 20.0f ); planet[ 17 ].normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
planet[ 18 ].vertex = D3DXVECTOR3( 5.0f, 5.0f, 30.0f ); planet[ 18 ].normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
planet[ 19 ].vertex = D3DXVECTOR3( 5.0f, -5.0f, 30.0f ); planet[ 19 ].normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );

//left side
planet[ 20 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 20.0f ); planet[ 20 ].normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f );
planet[ 21 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 20.0f ); planet[ 21 ].normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f );
planet[ 22 ].vertex = D3DXVECTOR3( -5.0f, 5.0f, 30.0f ); planet[ 22 ].normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f );
planet[ 23 ].vertex = D3DXVECTOR3( -5.0f, -5.0f, 30.0f ); planet[ 23 ].normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f );

//back
planet[ 0 ].tu = 0.0f; planet[ 0 ].tv = 1.0f;
planet[ 1 ].tu = 0.0f; planet[ 1 ].tv = 0.0f;
planet[ 2 ].tu = 1.0f; planet[ 2 ].tv = 0.0f;
planet[ 3 ].tu = 1.0f; planet[ 3 ].tv = 1.0f;

//front
planet[ 4 ].tu = 0.0f; planet[ 4 ].tv = 1.0f;
planet[ 5 ].tu = 0.0f; planet[ 5 ].tv = 0.0f;
planet[ 6 ].tu = 1.0f; planet[ 6 ].tv = 0.0f;
planet[ 7 ].tu = 1.0f; planet[ 7 ].tv = 1.0f;

//bottom
planet[ 8 ].tu = 0.0f; planet[ 8 ].tv = 1.0f;
planet[ 9 ].tu = 0.0f; planet[ 9 ].tv = 0.0f;
planet[ 10 ].tu = 1.0f; planet[ 10 ].tv = 0.0f;
planet[ 11 ].tu = 1.0f; planet[ 11 ].tv = 1.0f;

//top
planet[ 12 ].tu = 0.0f; planet[ 12 ].tv = 1.0f;
planet[ 13 ].tu = 0.0f; planet[ 13 ].tv = 0.0f;
planet[ 14 ].tu = 1.0f; planet[ 14 ].tv = 0.0f;
planet[ 15 ].tu = 1.0f; planet[ 15 ].tv = 1.0f;

//r side
planet[ 16 ].tu = 0.0f; planet[ 16 ].tv = 1.0f;
planet[ 17 ].tu = 0.0f; planet[ 17 ].tv = 0.0f;
planet[ 18 ].tu = 1.0f; planet[ 18 ].tv = 0.0f;
planet[ 19 ].tu = 1.0f; planet[ 19 ].tv = 1.0f;

//l side
planet[ 20 ].tu = 1.0f; planet[ 20 ].tv = 1.0f;
planet[ 21 ].tu = 1.0f; planet[ 21 ].tv = 0.0f;
planet[ 22 ].tu = 0.0f; planet[ 22 ].tv = 0.0f;
planet[ 23 ].tu = 0.0f; planet[ 23 ].tv = 1.0f;

//INDEX
//back
indices[ 0 ] = 0;
indices[ 1 ] = 1;
indices[ 2 ] = 2;
indices[ 3 ] = 0;
indices[ 4 ] = 2;
indices[ 5 ] = 3;

//front
indices[ 6 ] = 4;
indices[ 7 ] = 5;
indices[ 8 ] = 6;
indices[ 9 ] = 4;
indices[ 10 ] = 6;
indices[ 11 ] = 7;

//bottom
indices[ 12 ] = 8;
indices[ 13 ] = 9;
indices[ 14 ] = 10;
indices[ 15 ] = 8;
indices[ 16 ] = 10;
indices[ 17 ] = 11;

//top
indices[ 18 ] = 12;
indices[ 19 ] = 13;
indices[ 20 ] = 14;
indices[ 21 ] = 12;
indices[ 22 ] = 14;
indices[ 23 ] = 15;

//right
indices[ 24 ] = 16;
indices[ 25 ] = 17;
indices[ 26 ] = 18;
indices[ 27 ] = 16;
indices[ 28 ] = 18;
indices[ 29 ] = 19;

//left
indices[ 30 ] = 0;
indices[ 31 ] = 1;
indices[ 32 ] = 5;
indices[ 33 ] = 0;
indices[ 34 ] = 5;
indices[ 35 ] = 4;


It has to be a texture cordinate problem?

Share this post


Link to post
Share on other sites
Advertisement
Why are you reusing vertices for the last face (the last index buffer block)? I coldn't be bother to look through all the Tex coordinatess but I guess the problem lies there.

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!