Hey guys,
can anyone tell me why this code will not render (it should display a box)?
public FloatBuffer createFloatBuffer(int length) {
return ByteBuffer.allocateDirect(length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
....
// rendering code starts
float boxnorms[] ={0,0,1, 0,0,1, 0,0,1, 0,0,1,
0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
0,1,0, 0,1,0, 0,1,0, 0,1,0,
0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0,
1,0,0, 1,0,0, 1,0,0, 1,0,0,
-1,0,0, -1,0,0, -1,0,0, -1,0,0};
float x = 1, y = 1, z = 1;
float points[] = new float[72];
// front
points[0] = x; points[1] = y; points[2] = z; points[3] = -x; points[4] = y; points[5] = z;
points[6] = -x; points[7] = -y; points[8] = z; points[9] = x; points[10] = -y; points[11] = z;
// back
points[12] = x; points[13] = -y; points[14] = -z; points[15] = -x; points[16] = -y; points[17] = -z;
points[18] = -x; points[19] = y; points[20] = -z; points[21] = x; points[22] = y; points[23] = -z;
// top
points[24] = -x; points[25] = y; points[26] = z; points[27] = x; points[28] = y; points[29] = z;
points[30] = x; points[31] = y; points[32] = -z; points[33] = -x; points[34] = y; points[35] = -z;
// down
points[36] = -x; points[37] = -y; points[38] = -z; points[39] = x; points[40] = -y; points[41] = -z;
points[42] = x; points[43] = -y; points[44] = z; points[45] = -x; points[46] = -y; points[47] = z;
// right
points[48] = x; points[49] = -y; points[50] = z; points[51] = x; points[52] = -y; points[53] = -z;
points[54] = x; points[55] = y; points[56] = -z; points[57] = x; points[58] = y; points[59] = z;
// left
points[60] = -x; points[61] = -y; points[62] = z; points[63] = -x; points[64] = y; points[65] = z;
points[66] = -x; points[67] = y; points[68] = -z; points[69] = -x; points[70] = -y; points[71] = -z;
// create buffers
FloatBuffer vertexBuffer, normalBuffer;
vertexBuffer = createFloatBuffer(72 * 3);
normalBuffer = createFloatBuffer(72 * 3);
// draw vertices/normals
gl.glVertexPointer (3, GL.GL_FLOAT, 0, vertexBuffer);
gl.glNormalPointer (GL.GL_FLOAT, 0, normalBuffer);
Im sure im not doing the buffers right, I’ve tried a lot of searching and thats where i found that createFloatBuffer() method, but nothing is being drawn on screen Just to note If i draw using glBegin(…) and glVertex3f() etc the box is drawn fine.
Any help is really appreciated