Simple working VBO in LWJGL

It’s come to this, I’ve been learning Open GL (via LWJGL) for the last few months and managed to learn enough from website and the Open GL documentation to write code using display lists, normals, colors, textures, and transparency.
However, all my attempts to learn about Buffer Objects and server side memory have been thwarted by blank black windows.

Below is some code, but first here’s some information about my current progress.
I have tried adding calls to glGetError, but did not see any errors.
I have also tried calling glGetBufferSubData on both the VBO and EBO and I printed the contents and found it to be identical to the input buffers.
Note: The code tries to render without custom shaders using calls to *Pointer (fixed pipeline or something).
I feel apprehensive about switching to shaders because I have had similar blank black windows when trying to test shaders.

Here’s the simplest version of my current efforts to create a VBO with EBO and render using *Pointer and glDrawElements:


final int maxFps = 60;
final int numberVertices = 6;
final int vertexSize = 3;
final int normalSize = 3;
final int colorSize = 1;
final int paddingSize = 1;
final int interleavingElementSize = (vertexSize+normalSize+colorSize+paddingSize);

public VBODemo() {
   int[] vboEbo = initGL();
   gameLoop(vboEbo[0], vboEbo[1]);

Open GL initialization

/** initGL, initialize Open GL display and create vbo
 * @return two ints, the first is the vbo created and the second is the ibo created
private int[] initGL() {
   try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setTitle("Vertex Buffer Test");
   } catch (LWJGLException e) {

   GL11.glOrtho(-2, 2, -2, 2, 4, -4);


   // Create the data buffer with vertex, normal, and color elements interleaving
   int color = Color.GREEN.getRGB();
   ByteBuffer vertexData; // Format vertex3f(x,y,z),normal3f(x,y,z),color4b(x,y,z,0),padding4b
   vertexData = BufferUtils.createByteBuffer(interleavingElementSize * numberVertices * 4);
   // Vertices 0,1, -1,-1, 1,-1,

   // Create the buffer of indices for each vertex
   ByteBuffer indexData;
   indexData = BufferUtils.createByteBuffer(numberVertices * 4);

   // Create the buffer objects for the vertex data and the list of indices
   int buffer = createBO(vertexData, GL15.GL_ARRAY_BUFFER, GL15.GL_STATIC_DRAW);
   int element = createBO(indexData, GL15.GL_ELEMENT_ARRAY_BUFFER, GL15.GL_STATIC_DRAW);

   return new int[] {buffer, element};


private void gameLoop(int buffer, int element) {
   while(!Display.isCloseRequested()) {

      renderVBO(buffer, element);



private int createBO(ByteBuffer vertexData, int targetType, int drawType) {
   int id = GL15.glGenBuffers();
   GL15.glBindBuffer(targetType, id); // Bind the new buffer
   GL15.glBufferData(targetType, vertexData, drawType); // Upload the buffer data
   GL15.glBindBuffer(targetType, 0); // Unbind the buffer once data uploading is done
   return id;


private void renderVBO(int vbo, int ebo) {
   // Bind buffers
   GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
   GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo);
   // Enable attribute types
   // Bind attribute types
   GL11.glNormalPointer(GL11.GL_FLOAT, 32, 12);
   GL11.glColorPointer(4, GL11.GL_BYTE, 32, 24);
   GL11.glVertexPointer(vertexSize, GL11.GL_FLOAT, 32, 0);
   // Draw attributes from GL_ARRAY_BUFFER using indices from GL_ELEMENT_ARRAY_BUFFER
   GL11.glDrawElements(GL11.GL_TRIANGLES, numberVertices, GL11.GL_INT, 0);
   // Disable attribute types
   // Unbind buffers
   GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
   GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

As I mentioned, the code currently renders a blank black window. I don’t understand most of the method calls in renderVBO() so I am thinking that there may be an error in that method.
I would love to learn how to render buffer objects correctly so that I can continue learning about Open GL! :smiley:

I have spent quite a lot of time trying to find out how to use Open GL Buffer Objects with VertexPointer(), NormalPointer(), etc. without using shaders, and I have not found a solution.
If someone with the same question comes across this in the future, all I can recommend is switch to shaders, I know it’s not fun, but hopefully these resources will help:

Good example shader source code.

Dozens of tutorials covering modern Open GL topics

If you are trying to use generic attributes in your code and custom variables in your shaders (trying to render using EnableVertexAttribArray() and VertexAttribPointer()), then these pages might be helpful.

Explanation of using BindAttribLocation() and GetAttribLocation() to work with attribute/in variables from a shader.

More information about generic vertex attributes in shaders and in code.