Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


VBOs: what am doing wrong?


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   -  Reputation: 934

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?

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


Sponsor:

#2 NotANumber   Members   -  Reputation: 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   Crossbones+   -  Reputation: 8678

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.



PARTNERS