Out of memory while drawing VBOs

Guys, i really stuck with this…(( Want to draw two simple triangles as a quad through VBO, but can see only triangle rendered through immediate mode((

App class:

package vbo;

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

import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;

import lwjgl.VBOHelper;
import app.IKeyListener;
import app.LWJGLApp;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;

public class VBOApp extends LWJGLApp implements IKeyListener {

	boolean end = false;
	
	VBOApp(String title, int width, int height) {
		super(title, width, height);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		VBOApp app = new VBOApp("VBO example", 800, 600);
		app.start();
	}

	int vertBuf = 0;
	int colBuf = 0;
	int indBuf = 0;	

	@Override
	public boolean onInit() {
		addKeyListener(this);
		
		if(!VBOHelper.checkHardwareVBOSupport()){
			return false;
		}
		
		// Buffers
		FloatBuffer vBuf = BufferUtils.createFloatBuffer(12);
		FloatBuffer cBuf = BufferUtils.createFloatBuffer(16);
		IntBuffer iBuf = BufferUtils.createIntBuffer(6);
	    
		float color[] = {1, 0, 1, 0};
		
		// First
		float first[] = {-1, -1, 0};
		vBuf.put(first);		
		cBuf.put(color);
				
		// Second
		float second[] = {-1, 1, 0};
		vBuf.put(second);				
		cBuf.put(color);
		
		// Third
		float third[] = {1, 1, 0};
		vBuf.put(third);				
		cBuf.put(color);
		
		// Fourth
		float fourth[] = {1, -1, 0};
		vBuf.put(fourth);		
		cBuf.put(color);
		
		// Indices
		int indices[] = {0, 1, 2, 0, 2, 3};
		iBuf.put(indices);
		
		// Creating buffers and filling data
		vertBuf = VBOHelper.createVBOID();
		VBOHelper.bufferData(vertBuf, vBuf, GL_STATIC_DRAW);
		
		colBuf = VBOHelper.createVBOID();
		VBOHelper.bufferData(colBuf, cBuf, GL_STATIC_DRAW);
		
		indBuf = VBOHelper.createVBOID();
		VBOHelper.bufferElementData(indBuf, iBuf, GL_STATIC_DRAW);
		
		return true;
	}
	
	@Override
	public boolean prepareFrame(long msecElapsed) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		glTranslatef(0, 0, -6.0f);

		glBegin(GL_TRIANGLES);						// Drawing Using Triangles
		glVertex3f( 0.0f, 1.0f, 0.0f);				// Top
		glVertex3f(-1.0f,-1.0f, 0.0f);				// Bottom Left
		glVertex3f( 1.0f,-1.0f, 0.0f);				// Bottom Right
		glEnd();
		
		VBOHelper.bindVBO(vertBuf, indBuf, colBuf);
		VBOHelper.drawTriangles(6);
		
		return !end;
	}

	@Override
	public void onDestroy() {
		// Destroying buffers
		VBOHelper.destroyBuffer(vertBuf);
		VBOHelper.destroyBuffer(colBuf);
		VBOHelper.destroyBuffer(indBuf);
	}

	@Override
	public void keyboardEvent(int key, boolean pressed) {
		if(key == Keyboard.KEY_ESCAPE){
			end = true;
		}		
	}

}

VBO helper class:

package lwjgl;

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

import org.lwjgl.opengl.GLContext;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;

import utils.Log;

public class VBOHelper {
	
	/**
	 * Checking CAPs
	 */
	public static boolean checkHardwareVBOSupport(){
		if(!GLContext.getCapabilities().GL_ARB_vertex_buffer_object){
			Log.hardwareNotSupport("GL_ARB_vertex_buffer_object");
		}
		return GLContext.getCapabilities().GL_ARB_vertex_buffer_object;
	}

	/**
	 * Creating, filling, destroying
	 */
	// Creating id for our VBO
	public static int createVBOID() {
		return glGenBuffers();
	}

	// Float data for our VBO (vertex, color, normal)(default usage = GL_STATIC_DRAW)
	public static void bufferData(int id, FloatBuffer data, int usage) {		
		glBindBuffer(GL_ARRAY_BUFFER, id);
		glBufferData(GL_ARRAY_BUFFER, data, usage);
	}

	// Int data for our VBO (indices)(default usage = GL_STATIC_DRAW)
	public static void bufferElementData(int id, IntBuffer data, int usage) {
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, data, usage);
	}
	
	public static void destroyBuffer(int id){
		glDeleteBuffers(id);
	}
	
	/**
	 * Binding, drawing
	 */
	// Preparing OpenGL for drawing and binding buffers
	public static void bindVBO(int vertexBufferID, int indexBufferID, int colourBufferID) {
		glEnableClientState(GL_VERTEX_ARRAY);
		glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
		glVertexPointer(3, GL_FLOAT, 0, 0);
				 
		glEnableClientState(GL_COLOR_ARRAY);
		glBindBuffer(GL_ARRAY_BUFFER, colourBufferID);
		glColorPointer(4, GL_FLOAT, 0, 0);
		 
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
	}
	
	
	public static void drawTriangles(int indexBufferSize){
		glDrawElements(GL_TRIANGLES, indexBufferSize, GL_UNSIGNED_INT, 0);
	}	
}

Maybe someone can just add some working code snippet?

Snippet 1

Snippet 2

Snippet 3

First one is a tutorial from oficial site - but i’m pretty sure it it outdated - second and third (same) are outdated too. VBOs now is in core i think…
P.S. i just cannot get into version system - what means org.lwjgl.opengl.GL15? why it does’n include for example org.lwjgl.opengl.GL11? Every time i found any tutorial it looks like OpenGL was rewrited complitedly…;((

yes VBO’s are now part of OpenGL 3.0 “org.lwjgl.opengl.GL30”; just replace the parts of the extension on those snippets with GL30.*

if you don’t like the static class names before every opengl call then just use java’s static import class and it will look like normal c opengl.

e.g.

import static org.lwjgl.opengl.GL11.*;

and then you can use all the calls from that class without using the “GL11.” bit.

thanks, i’l try…
And by the way - why they always use methods like ARBVertexBufferObject.glGenBuffersARB(buffer); instead of methods used in most of tutorials/literature like glGenBuffers()

Rewrited VBOHelper as in tutorial - still do not work…((
http://www.lwjgl.org/wiki/index.php?title=Using_Vertex_Buffer_Objects_(VBO)

Problem solved… But i don’t know how - i did it pretty the same way…:wink:

Forget to rewind buffers before sending them to OpenGL…