glDrawElements and a black screen

Hi,

I am trying to use glDrawElements, but the result is a black screen. Can someone take a look at my code and tell me what is wrong with the code, please?

Thanks

public class testApplet extends JApplet implements GLEventListener
{
public void init()
{
GLCapabilities glc = new GLCapabilities();

  GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(glc);
  getContentPane().setSize(35, 35);
  getContentPane().add(canvas, BorderLayout.CENTER);
  canvas.addGLEventListener(this);

}

void setupPointers(GL gl)
{
int vertices[] =
{
25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325
};
float colors[] =
{
(float) 1.0, (float) (float) 0.2, (float) 0.2, (float) 0.2, (float) 0.2, (float) 1.0, (float) 0.8, (float) 1.0, (float) 0.2, (float) 0.75,
(float) 0.75, (float) 0.75, (float) 0.35, (float) 0.35, (float) 0.35, (float) 0.5, (float) 0.5, (float) 0.5
};

  IntBuffer verticesBuffer = BufferUtils.newIntBuffer(6 * 2);
  FloatBuffer colorsBuffer = BufferUtils.newFloatBuffer(6 * 3);
  verticesBuffer.put(vertices);
  verticesBuffer.flip();
  colorsBuffer.put(colors);

  gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
  gl.glEnableClientState(GL.GL_COLOR_ARRAY);

  gl.glVertexPointer(2, GL.GL_INT, 0, verticesBuffer);
  gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsBuffer);

}

public void display(GLDrawable gld)
{
GL gl = gld.getGL();
int indices[] = {0, 1, 3, 4};

  gl.glDrawElements(GL.GL_POLYGON, 4, GL.GL_UNSIGNED_INT, indices);

  gl.glFlush();

}

public void displayChanged(GLDrawable gld, boolean arg1, boolean arg2)
{
}

public void init(GLDrawable gld)
{
gld.setGL(new DebugGL(gld.getGL()));
setupPointers(gld.getGL());
gld.getGL().glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gld.getGL().glShadeModel(GL.GL_FLAT);
}

public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4)
{
}
}

I got it working :slight_smile: