Creating a wheel in OpenGL


I need to create a model of a car and I am having trouble creating the wheels for it. The wheel has to be formed from 8 triangles rotated in a circle about a point. However, I am having difficulty with that.

Here’s what I have so far:

void draw_triangle ()
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f( 0.0,  0.0, 10);
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 0, -10);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f( 0.0, -10, 0);


void draw_wheel ()
	glTranslatef(0.0, 10.0, 0.0);
	glRotatef(45, 1.0, 0.0, 0.0);

However, it is not giving me the desired result. If I can draw just one wheel correctly, I think I can manage drawing four wheels and placing them in the right locations but I just cannot seem to get it.

Any help is appreciated. Thank you!

However, it is not giving me the desired result

For one, you only drew two triangles. You’ll need a loop to make this work the way you want.

For another, you really, really don’t have to do it this way. Making an octagon is very simple; you can just make a “draw_octogon” function that draws 8 triangles. No need for matrix transformations. Just precompute what the vertices are.

It didn’t work right with 2 triangles so I figured it would fail even more with all 8. Could you give me an example of “draw_octagon” please?

Thank you!

You could try a GL_TRIANGLE_FAN:

Thanks for the suggestion! This page helped me a lot: