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:
Here is the code:
It ran nicely, here is the result:
Here is the code:
It ran nicely, here is the result:
You might want to correct the faces and normals forloops as they only print and do not assign the arrays.
ReplyDeleteHi Jozef, Thanks for reading.
ReplyDeleteIn 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.
Nice work. Did you use these vertices as GL_POINTS for rendering onto the openGL scene instead of using triangle strips?
ReplyDeleteHi 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:
ReplyDeleteglVertexPointer(3, GL_FLOAT, 0, verticies);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawElements(GL_TRIANGLES, totalElements, GL_UNSIGNED_BYTE, faces);