Sign in to follow this  

Creating a cylinder with texture coordinates

This topic is 4761 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

I've been trying to create a simple cylinder and add a texture on it but couldn't manage to do it. I though I could use D3DXCreateCylinder and that would do it but when I set a texture on it, it just take the first pixel (0,0) of the texture and put his color everywhere on the cylinder. After asking a bit on IRC I've got told you can't specify the texture coordinates for a cylinder created with D3DXCreateCylinder. So now I'm asking for a place where to find a code who create a cylinder specifying every points and texture coordinates using code (loops, sin/cos). I've already stydied something similar for a sphere but it's not exactly the same and it's been a while..

Share this post


Link to post
Share on other sites
Tutorial 5 in the SDK creates a cylinder manually, with texture coordinates. Here is the geometry algorithm they use:


for( DWORD i=0; i<50; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);

pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].color = 0xffffffff;
#ifndef SHOW_HOW_TO_USE_TCI
pVertices[2*i+0].tu = ((FLOAT)i)/(50-1);
pVertices[2*i+0].tv = 1.0f;
#endif

pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].color = 0xff808080;
#ifndef SHOW_HOW_TO_USE_TCI
pVertices[2*i+1].tu = ((FLOAT)i)/(50-1);
pVertices[2*i+1].tv = 0.0f;
#endif
}

Share this post


Link to post
Share on other sites

This topic is 4761 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this