Skip to main content
GameDev.net gamedev.net
🔒 Locked

My VBO is not drawing anything.

Started by Zomgbie Jan 1, 2011 at 3:34 PM 7 replies 4.5k views
Original Post
Zomgbie
Zomgbie
Hello!

I've got a little problem with an nasty VBO, it's not drawing anything at all. The problem definitely lies somewhere in my VBO code, cause if i swith to immediate mode it's all fine.

I'm using GLee for handling the extensions. But this puzzles me a little bit. I'm only including GLee.h in my header files, and GLee.c in my project. Is that enough?

Here's where i bind the poor VBO (vertexBuffer is defined as a GLuint)
	/* Setup our vertex buffer */	GLfloat objectVertices[] = {0.0f, 0.0f, 32.0f, 0.0f, 32.0f, 32.0f, 0.0f, 32.0f};	/* Setup the particle vertex data */	glGenBuffers(1, &(this->vertexBuffer));	/* Fill the buffer */	glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer);	glBufferData(GL_ARRAY_BUFFER, sizeof(objectVertices), objectVertices, GL_STATIC_DRAW);


And here's where i draw it
	/* Bind the buffer */	glBindBuffer(GL_ARRAY_BUFFER, gameManager->graphManager->vertexBuffer);	/* Vertex pointer */	glVertexPointer(2, GL_FLOAT, 0, 0);	/* Push the matrix */	glPushMatrix();	/* Translate to our position */	glTranslatef(this->x, this->y, 0.0f);	/* Enable the client states we need */	glEnableClientState(GL_VERTEX_ARRAY);	//glEnableClientState(GL_TEXTURE_COORD_ARRAY);	/* Draw the object */	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);	/* Disable our stats */	//glDisableClientState(GL_TEXTURE_COORD_ARRAY);	glDisableClientState(GL_VERTEX_ARRAY);	/* Pop it back */	glPopMatrix();	/* Unbind the buffer */	glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);


As you may see, all i'm trying to do is draw a simple cube.
Omg, zombie! Zomgbie.
karwosts
karwosts
Hmm after a quick lookover your vertex buffer commands look correct to me.

Have you tried calling glGetError?

Also I have to assume that if you can compile and run without crashing than your GLee is working right, though I haven't used it myself before.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Zomgbie
Zomgbie
Calling glGetError after binding my VBO the first time, returns an invalid operation. This comes from somewhere previous in my code though, since if i call it before binding i get the same result. Just don't want to leave anything out.

Calling glGetError after binding my buffer for drawing use, returns an out of memory error. This seems more of a likely cause to me.

Edit
So google (http://www.g-truc.net/article/vbo-en.pdf) tells me that:
"In the specific case where the whole memory size of the graphic card is lower that the size we are asking to reserve for a single VBO, a GL_OUT_OF_MEMORY error is thrown and could be retrieving with the common function glGetError"

This seems very unlikely. Ideas?
Omg, zombie! Zomgbie.
karwosts
karwosts
You need to find the exact place the first error is coming from.

Once an error occurs it stays until you call glGetError, so you have to find the line that you're calling that is causing the error. It's got nothing to do with your glBindBuffer if the error is present before you call it.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
rolfm
rolfm
It seems to me like you have not put enough data into your buffer. objectVertices has only 8 values, should this not be 9? Like {x,y,z,x,y,z,x,y,z}? I usually test these things by drawing GL_POINTS since its behaviour is a bit more predictable in some situations.


EDIT:
This example calls glVertexPointer after enabling client state this seems more logical to me

http://www.songho.ca/opengl/gl_vertexarray.html
karwosts
karwosts
Quote:
Original post by rolfm
It seems to me like you have not put enough data into your buffer. objectVertices has only 8 values, should this not be 9? Like {x,y,z,x,y,z,x,y,z}? I usually test these things by drawing GL_POINTS since its behaviour is a bit more predictable in some situations.


He's got 2D vertices, not 3D. 4 vertices at 2 coordinates per vertex.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Zomgbie
Zomgbie
Quote:
Original post by rolfm
It seems to me like you have not put enough data into your buffer. objectVertices has only 8 values, should this not be 9? Like {x,y,z,x,y,z,x,y,z}? I usually test these things by drawing GL_POINTS since its behaviour is a bit more predictable in some situations.


I'm not drawing in 3D space, just 2D. So i'm omitting the Z position.

Quote:
Original post by karwosts
You need to find the exact place the first error is coming from.

Once an error occurs it stays until you call glGetError, so you have to find the line that you're calling that is causing the error. It's got nothing to do with your glBindBuffer if the error is present before you call it.


Considering the gl errors, i've started debugging the code carefully to find where exactly the invalid operation takes part. But, funny thing, when i call glGetError before running any opengl calls what so ever, it still returns an invalid operation. What could that possibly be?

Edit
Thinking i might do something wrong when checking for errors. Does this look right?
	/* Check for errors */	GLenum			error;	error = glGetError();	switch (error) {		case GL_NO_ERROR:			fprintf(this->logFile, "[graphHandler]:\t\tError: No error!\n");		break;		case GL_INVALID_ENUM:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_INVALID_ENUM\n");		break;		case GL_INVALID_VALUE:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_INVALID_VALUE\n");		break;		case GL_INVALID_OPERATION:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_INVALID_OPERATION\n");		break;		case GL_STACK_OVERFLOW:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_STACK_OVERFLOW\n");		break;		case GL_STACK_UNDERFLOW:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_STACK_UNDERFLOW\n");		break;		case GL_OUT_OF_MEMORY:			fprintf(this->logFile, "[graphHandler]:\t\tError: GL_OUT_OF_MEMORY\n");		break;	}
Omg, zombie! Zomgbie.
karwosts
karwosts
Quote:
But, funny thing, when i call glGetError before running any opengl calls what so ever, it still returns an invalid operation. What could that possibly be?


You have to have a context created first, so you can't just call it on the first line of the program. If you do get it right after the context creation you can put up your source and I'll take a look.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Zomgbie
Zomgbie
"You have to have a context created first" got me thinking. Turns out i constructed my VBO before i setup my context. Gah, stupid mistake. Thanks a million though for all your help!

I'd make you a cake if i could!
Omg, zombie! Zomgbie.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.