Header Files into iPhone and OpenGL

Header Files into iPhone and OpenGL

Trying to learn OpenGL at the same time I'm learning the iPhone SDK

I made a simple cube in Cheetah 3D and was trying to display it on the iPhone using the header file export, what I get is just a unrecognizable blob on the screen. Any suggestions on what I'm doing wrong? thanks.

The Cheetah header file had everything I thought I would need, but it appears the iPhone doesn't support glInterleavedArrays, so I had to try to change the code to work without it.

glTexCoordPointer(2, GL_FLOAT, 8 * sizeof(GL_FLOAT), Box_vertex);
glNormalPointer(GL_FLOAT, 8 * sizeof(GL_FLOAT), Box_vertex + 2);
glVertexPointer(3, GL_FLOAT, 8 * sizeof(GL_FLOAT), Box_vertex + 5);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLES,Box_polygoncount*3,GL_UNSIGNED_SHORT,Box_index);

GLfloat Box_vertexBox_vertexcount[8]={
{0.00000, 1.00000, 0.00000, 0.00000, 1.00000, -0.50000, -0.50000, 0.50000},
{0.00000, 0.00000, 0.00000, 0.00000, 1.00000, -0.50000, 0.50000, 0.50000},
{1.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.50000, 0.50000, 0.50000},
{1.00000, 1.00000, 0.00000, 0.00000, 1.00000, 0.50000, -0.50000, 0.50000},
{0.00000, 1.00000, 0.00000, 0.00000, -1.00000, 0.50000, -0.50000, -0.50000},
{0.00000, 0.00000, 0.00000, 0.00000, -1.00000, 0.50000, 0.50000, -0.50000},
{1.00000, 0.00000, 0.00000, 0.00000, -1.00000, -0.50000, 0.50000, -0.50000},
{1.00000, 1.00000, 0.00000, 0.00000, -1.00000, -0.50000, -0.50000, -0.50000},
{0.00000, 1.00000, -1.00000, 0.00000, 0.00000, -0.50000, -0.50000, -0.50000},
{0.00000, 0.00000, -1.00000, 0.00000, 0.00000, -0.50000, 0.50000, -0.50000},
{1.00000, 0.00000, -1.00000, 0.00000, 0.00000, -0.50000, 0.50000, 0.50000},
{1.00000, 1.00000, -1.00000, 0.00000, 0.00000, -0.50000, -0.50000, 0.50000},
{0.00000, 1.00000, 1.00000, 0.00000, 0.00000, 0.50000, -0.50000, 0.50000},
{0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.50000, 0.50000, 0.50000},
{1.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.50000, 0.50000, -0.50000},
{1.00000, 1.00000, 1.00000, 0.00000, 0.00000, 0.50000, -0.50000, -0.50000},
{0.00000, 1.00000, 0.00000, 1.00000, 0.00000, -0.50000, 0.50000, 0.50000},
{0.00000, 0.00000, 0.00000, 1.00000, 0.00000, -0.50000, 0.50000, -0.50000},
{1.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.50000, 0.50000, -0.50000},
{1.00000, 1.00000, 0.00000, 1.00000, 0.00000, 0.50000, 0.50000, 0.50000},
{0.00000, 1.00000, 0.00000, -1.00000, 0.00000, -0.50000, -0.50000, -0.50000},
{0.00000, 0.00000, 0.00000, -1.00000, 0.00000, -0.50000, -0.50000, 0.50000},
{1.00000, 0.00000, 0.00000, -1.00000, 0.00000, 0.50000, -0.50000, 0.50000},
{1.00000, 1.00000, 0.00000, -1.00000, 0.00000, 0.50000, -0.50000, -0.50000},
};
GLushort Box_indexBox_polygoncount[3]={
{0, 1, 2},
{2, 3, 0},
{4, 5, 6},
{6, 7, 4},
{8, 9, 10},
{10, 11, 8},
{12, 13, 14},
{14, 15, 12},
{16, 17, 18},
{18, 19, 16},
{20, 21, 22},
{22, 23, 20},
};
 
This is probably *not* the best place to get programming advice.

The iPhone doesn't support OpenGL but OpenGL ES, the embedded version. I'd find a reference and work from there.

http://www.khronos.org/opengles/

I was spelunking Apple's examples and there isn't an actual 3d example program -- the Crashlanding game simply uses OpenGL in Ortho mode as a 2d compositing engine, so it doesn't show how to render arbitrary meshes onto the screen.

And, because everyone is still under NDA, third party developers aren't able to publish their own sample code. So... good luck.
 
Hi,
the first thing that makes me worry is that your arrays are way to small.

Your float array has just 8 elements (should be 24*8 ) and the index array has just 3 elements (should be 12*3 ).

I'm surprised that this doesn't cause a crash.:wink:

Bye,
Martin

P.S. Since the memory layout of the float[][] array Cheetah3D exports should be similar to a float[] array using a (flaot*)(float**) cast hould also work.
 
Last edited:
Actually, the code I pasted in somehow lost some brackets, so the arrays really look like
GLfloat Box_vertex[Box_vertexcount][8]
GLushort Box_index[Box_polygoncount][3]
so the number of elements should be correct.

i did try applying lighting, i didn't include that section of the code though.

thanks for your help. I think the end result is I need to learn more about opengl and 3d graphics before tackling this.
 
Trust me, you don't want to use vertex arrays. Use vertex buffer objects instead. I created a little perl script that converts the .h export into a format suitable for OpenGL ES VBOs. Works nicely. This was before I discovered C3D's Javascript functionality... Later I'll make a JS-based exporter for VBOs instead of vertex arrays instead of a perl script.

Vertex arrays -- geometry is sent every frame from client memory (your app) to server memory (the GPU). This is slow, expensive, and for static or mostly static geometry, a waste of time.

Vertex Buffer Objects -- geometry is managed by the "server" (think: GPU).

For the iPhone VBOs make a lot of sense for performance.

If you need to UPDATE the geometry however, you'll want to rearrange the data to not be interleaved. That's what I did in my simple perl script. All vertex position data comes before normals, which come before UVs.

That should give you enough to learn about and play with! Good luck!
 
Do you have your export script posted anywhere? If not, you ought to think about making it available. I know I'd be happy to PayPal you for it. For now, I've purchased and downloaded the Cheetah Video tutorials and am trying to get myself up to speed on 3D in general. Thanks again for your help.
 
Back
Top