OpenGL ES - Procedurally Generated Cylinder

I'm just getting started with OpenGL on the iPhone and the first object I need is a cylinder. I created a small C++ program to generate the structures needed. The resulting cylinder looks like this:
iPhone Cylinder 1

Here is the code:

It ran nicely, here is the result:
iPhone Cylinder 2


Jozef Dobos said...

You might want to correct the faces and normals forloops as they only print and do not assign the arrays.

Will Winder said...

Hi Jozef, Thanks for reading.

In this case I was using the program to print out the generated data and then copying it into my OpenGL program. If this was being generated in the OpenGL program then you're right that the data would need to be cached in a buffer some place.

Anonymous said...

Nice work. Did you use these vertices as GL_POINTS for rendering onto the openGL scene instead of using triangle strips?

Will Winder said...

Hi Anonymous, Since I was using a mobile device for rendering I used batch mode with GL_TRIANGLES. Literally just passing the structs generated above into this:

glVertexPointer(3, GL_FLOAT, 0, verticies);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawElements(GL_TRIANGLES, totalElements, GL_UNSIGNED_BYTE, faces);

Post a Comment