3

I have a problem with computing texture-space coordinates for a cylinder in raw webgl (no frameworks used). I was able to create the cylinder's polygon list and normal vectors, but somehow I'm struggling with the u,v textures. What I intended to do was:

tex_step_x = 1 / divisions;

for(var u = 0; u < divisions; u++)
{   
    // Top plate
    textureCoordData.push(0.5); textureCoordData.push(0.5);
    textureCoordData.push(1); textureCoordData.push(0.5);
    textureCoordData.push(1); textureCoordData.push(0);

    // The walls
    textureCoordData.push(tex_step_x*u); textureCoordData.push(1);
    textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(1);
    textureCoordData.push(tex_step_x*u); textureCoordData.push(0);

    textureCoordData.push(tex_step_x*u); textureCoordData.push(0);
    textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(0);
    textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(1);

    // Code for the bottom circle
    textureCoordData.push(0); textureCoordData.push(1);
    textureCoordData.push(1); textureCoordData.push(0);
    textureCoordData.push(1); textureCoordData.push(1);
}

The Cylinder is made out of "cake slices" for the bottom and top plate (with different heights) and two triangles for each segment of the wall. Any Ideas on how to calculate the right u,v-coordinates?

gman
  • 100,619
  • 31
  • 269
  • 393
WhiteBr0wnie_24
  • 149
  • 1
  • 1
  • 12
  • Could you show the code you're using to generate the positions and normals of the cylinder? – Peter O. May 08 '15 at 12:34
  • I solved it already but forgot to write an answer. I think it was some kind of cache problem even though I cleared it multiple times. opened it with a different browser (firefox), the texture was shown correctly and afterwards I reopened it with safari and it worked. – WhiteBr0wnie_24 May 08 '15 at 16:27
  • 1
    [you can turn the cache off while in the JavaScript tools in Chrome](https://developer.chrome.com/devtools/docs/settings#disable-cache). I believe similar options exist in other browser. For example [safari](http://imgur.com/OcQCLi3). You need to turn on the develop menu in Safari->Preferences->Advanced – gman Jun 02 '15 at 08:36

0 Answers0