LWJGL Forum

Programming => OpenGL => Topic started by: g4m0r on May 01, 2012, 07:53:54

Title: JVMcrash with glDrawElements
Post by: g4m0r on May 01, 2012, 07:53:54
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);

      
Title: Re: JVMcrash with glDrawElements
Post by: Fool Running on May 01, 2012, 13:14:56
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.
Title: Re: JVMcrash with glDrawElements
Post by: g4m0r on May 01, 2012, 15:59:01
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?
Title: Re: JVMcrash with glDrawElements
Post by: Fool Running on May 02, 2012, 12:32:33
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.