VBO doesn't show up on the screen

Hi, I’m new to LWJGL and OpenGL. I know the basics like intermediate mode and shaders. I have an out-of-focus idea on GL_PROJECTION, GL_MODELVIEW and glLoadIdentity() (I haven’t completely nailed these ones yet). I recently started using VBOs as I’m aware that the intermediate mode is deprecated. I managed to get it working in a simple program, but now I have hit a wall as to what the problem may be. I’m hoping that somebody will tell me where I’m going wrong(because I definitely do).

Here’s the main code:


	public static void main(String[] args) {
		
		Program app = new Program(800, 600, "VBO 3D Test", false); //creates a window
		
		Camera cam = new Camera(60, 800 / 600); //fov, aspect
		cam.setPosition(5, 5, 5);
		cam.look(0, 0, 0); //this calls gluLookAt(), the parameters are the position where the camera looks
		
		Tile t = new Tile();

		while(!Display.isCloseRequested()) {
			
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

			t.draw(); //draws a white, horizontal rectangle at 0,0,0 (it should show up, but doesn't)

			//any intermediate mode here -will- show up on the screen
			
			Display.update();
			Display.sync(60);
		}
		
		app.destroy();
	}

Methods from class Tile:


	private void generateVBO() {
		
		vboFloor = glGenBuffers();
		
		floorVertexData = BufferUtils.createFloatBuffer(4 * 3);
		floorVertexData.put(new float[]{-0.5f, 0, -0.5f,
				0.5f, 0, -0.5f,
				0.5f, 0, 0.5f,
				-0.5f, 0, 0.5f});
		floorVertexData.flip();
		
		glBindBuffer(GL_ARRAY_BUFFER, vboFloor);
		glBufferData(vboFloor, floorVertexData, GL_STATIC_DRAW);
		
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}
	
	public void draw() {

		glBindBuffer(GL_ARRAY_BUFFER, vboFloor);
		glVertexPointer(3, GL_FLOAT, 0, 0L);
		
		glEnableClientState(GL_VERTEX_ARRAY);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
		glDisableClientState(GL_VERTEX_ARRAY);
		
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

When creating the display I use:


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

I don’t know why the VBO doesn’t show up on the screen, the exact same code works in the other project, the only difference is that previously I have used glOrtho because it was a 2D project, now it’s in 3D (my first attempt at 3D in OpenGL btw). If you need any other snippets just say it. Any help is really appreciated!

Why the triangle_fan if you’re drawing 4 vertices?

And its ‘immediate’ not ‘intermediate’.

Camera cam = new Camera(60, 800 / 600); 

800/600 = 1, try floating point: 800.0f / 600.0f

@Riven
Thanks I didn’t notice that, it doesn’t solve the problem though :frowning:

@trollwarrior1
Sorry for the blunder :-X
I tried triangle_fan, triangle_strip, triangles and even quads, but none of them work. I know it’s something to do with the VBO because any immediate mode code in the Tile’s draw method works as expected.

Isn’t there anything else wrong with this code?

Could it be that you render a black shape on a black background? You never define any color.

No :clue: I used glColor3f(1f, 1f, 1f) in the draw method before drawing the VBO and even glClearColor(1f, 0f, 0f, 1f) before the main loop just to be sure, but no dice. I must be doing something wrong either with the creation of the VBO or setting up of the matrices so I’ll post a stripped down version of my whole project. Thank you for helping me with this problem :slight_smile: Oh, and as @trollwarrior1 mentioned, is there any problem with using triangle_fan with only 4 vertices?

I don’t know if there is a problem, but since you were using 4 vertices I assumed that you were drawing quads… Maybe its just me who has no idea how those modes work :stuck_out_tongue:

Ah ok, I just got a little confused because according to this

http://www.uchidacoonga.com/wp-content/uploads/2012/03/triangle_fan.png

it’s possible to render a quad using 4 vertices :smiley:

Anyway, here’s the dump: http://pastebin.java-gaming.org/a11a33c4e95

Use my tutorial as a place to start from:

Thanks, I guess I tried to jump too far ahead and it caught up to me. I’ll use your tutorial and the build upon it. Thank you for your help.

Your problem is that you’re overwriting all of your vertex data with your color data with [icode]glBufferData();[/icode]

Sorry, I would help you more but I’m on my phone right now. I can help you more tomorrow if you still need it. (After you read Riven’s tutorial of course)

Does the OP actually call generateVBO() method from someplace else not shown in his code?

It’s in the constructor of his tile class.

Hi all, I managed to find the bug(2 bugs actually) and I got it fixed.

Firstly, after comparing my working project with my non-working project side by side, I noticed that

glBufferData(vboFloor, floorVertexData, GL_STATIC_DRAW)

should in fact be

glBufferData(GL_ARRAY_BUFFER, floorVertexData, GL_STATIC_DRAW)

I’m embarrassed I didn’t find this typo(mislearned information) quicker.

Secondly as @Longarmx has pointed out, I only had one VBO buffer which I used for both vertex and color data(and it wasn’t interleaved so it obviously didn’t work).

Thank you everybody for helping me out with this issue ;D