How to do texture mapping for cylinder created by GL_TRIANGLE_STRIP in OpenGL and how to taper a cylinder

The texture coordinates are 2-dimenional and have to be in range [0.0, 1.0]:

glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i <= 32; i++) {
    double x_next = 1.0 * cos((i + 1) * 2.0 * PI/ (32 - 2.0));
    double y_next = 1.0 * sin((i + 1) * 2.0 * PI / (32 - 2.0));

    if (i % 2 == 0) {
        glTexCoord3f((float)i / 32.0f, 1.0f);
        glVertex3f(x_next, y_next, TABLETOP_Z + cubeLen);

    } else {
        glTexCoord3f((float)i / 32.0f, 0.0f);
        glVertex3f(x_next, y_next, TABLETOP_Z);
    }
}
glEnd();

See How do opengl texture coordinates work?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top