Obj Loader and OpenGL

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Obj Loader and OpenGL

Postby Hachaso » Wed May 20, 2009 3:16 pm

Hi!

I wondering if you need to do something special with the vertex data and index data loaded from the OBJ file, to make it appear on screen?

I have done a test in the code to specify the data directly in the code instead of loading it from an OBJ file. This to see if it looks ok.

for instance: This is just an example so you get the idea of my problem

float vertices2[] = {0.004520f, 0.000000f, -0.363459f,
0.179520f, 0.000000f, -0.315091f,
0.004520f, 0.000000f, -0.002436f,
0.004520f, 1.390251f, -0.363459f,
0.003921f, 1.528259f, 0.001508f,
0.179520f, 1.390251f, -0.315091f
};


short indices[] = {1, 2, 3,
4, 5, 6};



ByteBuffer vbb = ByteBuffer.allocateDirect(vertices2.length * 4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer2 = vbb.asFloatBuffer();
mVertexBuffer2.put(vertices2);

vbb = ByteBuffer.allocateDirect(indices.length * 4);
vbb.order(ByteOrder.nativeOrder());
mIndexBuffer2 = vbb.asShortBuffer();
mIndexBuffer2.put(indices);


Later in the "Draw" method I try to draw the object on the screen. Using glVertexPointer and glDrawElements.

gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer2);
gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer2);


The problem is that I can see something on the screen but it is absolutely not what should be there.
If I hard code the data of a Penguin, it's not a penguin I see on the screen.
What am I doing wrong here?

Thanks
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Top

Postby fusion » Sun May 24, 2009 9:48 am

I had the same problem and solved it by not using the indexcount in gl.glDrawElements but mIndexCount * 3.
Opengl expects the number of vertices it has to render.

gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount * 3, GL10.GL_UNSIGNED_SHORT, mIndexBuffer2);
fusion
Freshman
Freshman
 
Posts: 3
Joined: Sun May 24, 2009 9:42 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests