gl_quad_strip

I’m having trouble with my gl_quad_strip loop which draws a cylinder, It draws the cylinder just fine, with the right height and radius.

The problem I am having is that it the angle of it is completely wrong, its rotated around and I’m struggling to fix it.



		glBegin(GL_QUAD_STRIP);
		for (int i = 0; i <= number_of_sides; i++) {

			float angle = i*((1.0/number_of_sides) * (2*PI));

			glNormal3d(cos(angle),sin(angle),0);
			glVertex3d( radius*cos(angle), radius*sin(angle), height);
			glVertex3d( radius*cos(angle), radius*sin(angle), 0);  
		}
		glEnd();


An easy fix would be to put a glRotate command before the glBegin.

You could also try switching the X and Y coordinates in the glNormal and glVertex commands.

So forth and so on …

I tried a glRotatef and it didn’t make a difference.

And I’m not sure what you mean by switching the X and Y coordinates, switch them to what?

If you want the cylinder to be vertical, you need to switch the Y and Z values. OpenGL is Y-up with Z coming out of the screen. So height-related values go on the Y.


glBegin(GL_QUAD_STRIP); for (int i = 0; i <= number_of_sides; i++) {     
    float angle = i*((1.0/number_of_sides) * (2*PI));
    glNormal3d( cos(angle),0,sin(angle) );
    glVertex3d( radius*cos(angle), height, radius*sin(angle) );
    glVertex3d( radius*cos(angle), 0, radius*sin(angle) );   }
glEnd();