Monday, 15 April 2013

opengl - glDrawArrays with buffer not working in JOGL -



opengl - glDrawArrays with buffer not working in JOGL -

i wondering whether can help me find out why jogl code not show triangle. there no exceptions reason. missing something?

intbuffer vacantnamebuffer = intbuffer.allocate(3); gl.glgenbuffers(1, vacantnamebuffer); int vertexbuffername = vacantnamebuffer.get(); float[] trianglearray = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; floatbuffer trianglevertexbuffer = floatbuffer.wrap(trianglearray); gl.glbindbuffer(gl2.gl_array_buffer, vacantnamebuffer.get()); gl.glbufferdata( gl2.gl_array_buffer, trianglevertexbuffer.capacity() * buffers.sizeof_float, trianglevertexbuffer, gl2.gl_static_draw); gl.glenablevertexattribarray(vacantnamebuffer.get()); gl.glvertexattribpointer(0, 3, gl2.gl_float, false, 0, 0); gl.gldrawarrays(gl2.gl_triangles, 0, 3); gl.gldisablevertexattribarray(vacantnamebuffer.get()); gl.glflush();

glenablevertexattribarray expects attribute location (the number set first parameter of glvertexattribpointer) should alter to:

gl.glenablevertexattribarray(0); gl.glvertexattribpointer(0, 3, gl2.gl_float, false, 0, 0); gl.gldrawarrays(gl2.gl_triangles, 0, 3); gl.gldisablevertexattribarray(0);

opengl jogl

No comments:

Post a Comment