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

Comments

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

    ReplyDelete
  2. 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.

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

    ReplyDelete
  4. 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);

    ReplyDelete

Post a Comment

Popular posts from this blog

OpenSCAD linear extrude that interpolates between two shapes

Taking Stuff Apart: Realistic Modulette-8

XCode4: UITabBarController with UINavigationController using Interface Builder