Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

VBOs: what am doing wrong?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 ic0de   Members   

974
Like
0Likes
Like

Posted 20 December 2011 - 11:27 PM

This is the code I wrote for drawing using vbos:


VBOS:
	GLuint VertexVBO = 0;

	glGenBuffers(1, &VertexVBO);

	glBindBuffer(GL_ARRAY_BUFFER, VertexVBO);
	glBufferData(GL_ARRAY_BUFFER, mesh.numtriangles * 3 * sizeof(float), mesh.vertices, GL_STATIC_DRAW);

	glEnableClientState(GL_VERTEX_ARRAY);

	glBindBuffer(GL_ARRAY_BUFFER, VertexVBO);
	glVertexPointer(3, GL_FLOAT, 0, 0);

	glDrawArrays(GL_TRIANGLES, 0, mesh.numtriangles*3);

	glDisableClientState(GL_VERTEX_ARRAY);

	glDeleteBuffers(1, &VertexVBO);


when I run this nothing gets drawn but if I do it like this for plain vertex arrays it works fine (albeit slower):


Vertex Arrays:

	glEnableClientState(GL_VERTEX_ARRAY);

	glVertexPointer(3, GL_FLOAT, 0,  mesh.vertices );

	glDrawArrays(GL_TRIANGLES, 0, mesh.numtriangles*3);

	glDisableClientState(GL_VERTEX_ARRAY);

What did I do wrong when trying to implement VBOS?
Currently working on new DOS game, Chuck Jones: Space Cop of the Future, Check out my Dev Blog
 

you know you program too much when you start ending sentences with semicolons;


#2 NotANumber   Members   

100
Like
0Likes
Like

Posted 21 December 2011 - 03:39 AM

I suspect that the problem might be that you're deleting the buffer diectly after telling GL to draw something. There's no way of knowing when the actual rendering happens, depending on your platform and gl driver (maybe the driver is just building a list of GOU commands that are executed during a flush or a call to SwapBuffers()).

Try creating the array at startup, and the delete it during the application shutdown.

#3 mhagain   Members   

13161
Like
1Likes
Like

Posted 21 December 2011 - 04:24 AM

mesh.numtriangles * 3 * sizeof(float) looks wrong for the size of your VBO. Each triangle has 3 vertices, and each vertex has 3 floats, so that should be * 9 instead. Your hardware and/or driver is likely recognising that your VBO isn't big enough for your draw call params and failing gracefully by drawing nothing (personally I'd prefer a big dirty crash - at least you get some indication of what you've done wrong that way).

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.