Thanks to others advice, I now have my program up and running. The code excerpts below show (hopefully) the key parts of what I am currently doing, but now I am interested to see if someone can show me a more EFFICIENT way to do the same task. I read something from Cas talking about the pointers to the vertex arrays working at top efficiency when they have a stride of 32 bytes, but I never got that off the ground.
So…anyone is welcome to give me some code, OR, to tell me that they think the way I’m doing this is acceptable.
You’ll notice I only have vertex data and color data, and this is due to the fact that I am only a beginner, so if someone wants to offer a solution that uses vertex, texture, and normal data that would be great.
This program draws a 3 sided pyramid with no bottom.
// "global" arrays
float[] vertexArray = {0, 0, 1,
1, 0, -1,
-1, 0, -1,
0, 1, 0};
float[] colorArray = {0, 0, 1,
0, 0, 1,
0, 0, 1,
1, 0, 0};
int[] geometryArray = {3, 0, 1,
3, 2, 0,
3, 1, 2};
FloatBuffer vertexBuffer;
FloatBuffer colorBuffer;
//-------------------------------------------
public void init (...)
{
//...
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
ByteBuffer buffer =
ByteBuffer.allocateDirect( vertexArray.length * 4) ;
buffer = buffer.order(ByteOrder.nativeOrder());
vertexBuffer = buffer.asFloatBuffer();
buffer =
ByteBuffer.allocateDirect( colorArray.length * 4) ;
buffer = buffer.order(ByteOrder.nativeOrder());
colorBuffer = buffer.asFloatBuffer();
vertexBuffer.put(vertexArray);
colorBuffer.put(colorArray);
vertexBuffer.position(0);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
colorBuffer.position(0);
gl.glColorPointer(3, GL.GL_FLOAT, 0, colorBuffer);
//-------------------------------------------
public void display(...)
{
//...
gl.glDrawRangeElements(GL.GL_TRIANGLES,
0,
3,
9,
GL.GL_UNSIGNED_INT,
geometryArray);
Thanks much for the help on this and everything else folks…if not for input from Cas and others I would never have gotten even THIS little program off the ground!