LWJGL Forum

Programming => OpenGL => Topic started by: nmi on April 27, 2006, 14:36:03

Title: glDrawElements
Post by: nmi on April 27, 2006, 14:36:03
I simply want to draw a cube made of triangles, using glDrawElement. I get no error when calling Debug.drawUnitCube(), but it doesn't show anything. Here is the code :


package tools;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;


public class Debug
{
private static float[] s_cubeGeom =
{
/* Front Face (cut Z+) */
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,

/* Back Face (cut Z-) */
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,

/* Top Face (cut Y+) */
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,

/* Botton Face (cut Y-) */
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,

/* Right Face (cut X+) */
1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,

/* Left Face (cut X-) */
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f
};

private static int[] s_cubeIndices =
{
0, 1, 2, 2, 1, 3,
4, 5, 6, 6, 5, 7,
8, 9, 10, 10, 9, 11,
12, 13, 14, 14, 13, 15,
16, 17, 18, 18, 17, 19,
20, 21, 22, 22, 21, 23
};

private static FloatBuffer s_coords = BufferUtils.createFloatBuffer(s_cubeGeom.length);
private static IntBuffer s_indices = BufferUtils.createIntBuffer(s_cubeIndices.length);
static
{
s_coords.put(s_cubeGeom);
s_indices.put(s_cubeIndices);
}

public static void drawUnitCube()
{
GL11.glColor3f(1, 1, 1);
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(3, 0, s_coords);
GL11.glDrawElements(GL11.GL_TRIANGLES, s_indices);
}
}


What is wrong with this code ?
Thx.

nmi -[/code]
Title: glDrawElements
Post by: baysmith on April 28, 2006, 02:21:03
Perhaps you need to flip the buffers?

s_coords.flip();
s_indices.flip();
Title: glDrawElements
Post by: nmi on April 28, 2006, 06:07:35
It works. Many thanks !

nmi -