# Creating a cylinder with texture coordinates

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

## 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 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 on other sites
Thx a lot, I'll try this :)

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633731
• Total Posts
3013582
×