I am new in jogl and try to render rectangle by using VBO.
There are given two array: first arrey is
float vertex[] = {-2.0f, -2.0f, -2.0f,
2.0f, -2.0f, -2.0f,
-2.0f, -2.0f, 2.0f,
2.0f, -2.0f, 2.0f
};
second array is
float colors[] = {1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f
};
and then I try to initialize vertex buffers
pointsbf = Buffers.newDirectFloatBuffer(vertex.length);
colorsbf = Buffers.newDirectFloatBuffer(colors.length);
pointsbf.put(vertex);
colorsbf.put(colors);
pointsbf.rewind();
colorsbf.rewind();
the code above has been written in INIT() function;
The code bellow has been written in DISPLAY() function;
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, pointsbf);
gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsbf);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, totalNumVerts);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
but the code after running shows just black screen(((