JVMcrash with glDrawElements

Started by g4m0r, May 01, 2012, 07:53:54

Previous topic - Next topic

g4m0r

Hi,

I have a problem.
I have a VertexArray with glDrawElements.
If I render vertexes only, it works.

But when I also want to render the normals or texture coordinates the JVM crashes.
What's wrong?

here the render():
                 GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
       GL11.glTexCoordPointer(2, 0, tex_cords);
      
       GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
       GL11.glVertexPointer(3, 0, vertex);


                       GL11.glDrawElements(GL11.GL_QUADS, vert_ind);
          
       GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
       GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

      

Fool Running

A couple things I would check:
Make sure you did a flip() on the buffers.
Make sure there are enough bytes in the texture/normal buffers for the number of vertexes you have.
Make sure your vert_ind buffer doesn't attempt to access a vertex index that doesn't exist.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

g4m0r

Hi,

thx.
Is that the problem:
I just increment a integer for every Vector.x, Vector.y, Vector.z on the entire Mesh for INDEX  (vert_ind)

And now for example I have normals with only 1 Vector for a QUAD, but vert_ind have for every quad 12
(4 vertices with 3 floats(=Vector) ) indeces.
Must I do a new indexBuffer for the normals?

Fool Running

When using glDrawElements() with normals and texture coordinates, you must have a normal and a texture coordinate for each vertex. You can't have one normal that is used for 4 vertexes. If you need to have 4 vertexes that all have the same normal, you need to duplicate the normal 4 times in your normal buffer.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D