PDA

View Full Version : glDrawElements() doesn't work with loaded vals



Nakoustix
04-15-2012, 04:48 AM
Hi
I'am relatively new to OpenGL programming and I have a strange problem I couldn't solve yet.
I wrote a C++ converter-tool which parses an .obj file and generates an OpenGL friendly binary. It writes meshpoints, normals, texcoords and indices with a specific structure into a file to load and draw it with glDrawElements() on an Android device.
My problem:
If I load this values (and they're loaded right), my model class doesn't draw anything!
It's strange because i'm sure the converter works as arranged!
If I debug the values from the converter and write it directly into the javacode, the model draws perfectly. But if I load my binary and put the values at creation time into the buffers, nothing will be drawn... ???
The loader first gets information about the number of vertices and indices from the file, allocate the buffers and then puts value by value into this buffers (FloatBuffer and ShortBuffer from java.nio.*) by calling vBuffer.put(val). Then it sets the bufferpositions to 0.
My drawing method looks like this (without textures at the moment):

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

gl.glVertexPointer(3, GL10.GL_FLOAT,0,vBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0,nBuffer);

gl.glDrawElements(GL10.GL_TRIANGLES, indexcount, GL10.GL_SHORT, iBuffer);

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);

Do you have any idea why this happens?
There are the same values (debugged already) and the same drawing method but the runtime-loaded model doesn't draw anything!!!
Why???

I hope you have some suggestions because I'm really confused about!

Thanks n peace

Nakoustix
04-16-2012, 02:00 AM
Ok i know it smells like corrupt buffers, but I'M SURE THEY'RE RIGHT!
If I print out the values IN THE DRAWING METHOD I can see that they're right!
Does anybody have an idea what's missing in my code?
Thanks