Questions Concerning VBO's / VAO's

Started by KaySchus, July 18, 2012, 03:35:36

Previous topic - Next topic

KaySchus

I am currently starting to use the OpenGL 3.x+ version for my game programming.  Prior to this I had done some work with LWJGL/OpenGL (All immediate mode rendering) so I have virtually no experience with shaders and the newer procedure for rendering in OpenGL.  Between the new tutorials on the wiki and various other OpenGL sources on the internet I have been able to get my shaders and basic rendering accomplished, however I am now running into some issues that stem from a lack of understanding of the concept as a whole.  

My current setup has me manually defining the vertices of two triangles and their indices to render the quad (Basically the exact same setup as in the wiki tutorials). However, I am now attempting to "package" this setup into a class which will allow me to create more quads in an easier fashion for texturing.  (My ultimate goal here is a 2D RPG that I am hoping to implement in LWJGL, if that is of any help).  My first idea, and a  very in-efficient one at that, would be to make a class that will hold all of the vertices data for the entire game.  Then, as I need to add more (Say a bullet or some other generated entity in the game) I would have to copy the current vertex data, append the new vertex to the end, put it back in a buffer, and then rebind it to my VAO in order to render the changes.  This in and of itself seems like a terrible idea as it involves copious amounts of copying and overall seems like a poor way to implement the system.

Even more than that I do not truly understand how to manipulate the location of the vertices once stored in the buffer.  I understand I can pull the vertice data, alter it by some amount, then repackage it and bind it back to the VBO/VAO but that as well seems like a poor solution to the problem.  I feel that the system must be more streamlined than that and I must, in some way, be missing out on something that would greatly simplify all of this.

Anyways, any help that can be offered would be of great assistance, it doesn't have to be a specific explanation either, I really just need a nice starting point to help me grasp this.  If I didn't explain any of this very well, or if it would be easier with sample code to show how I have implemented these ideas I can post those.  Thanks!

broumbroum

I can tell you how to go on with the actual coding of such a package. It's not as hard as you might think.
Quote from: KaySchus on July 18, 2012, 03:35:36
...(My ultimate goal here is a 2D RPG that I am hoping to implement in LWJGL, if that is of any help).  My first idea, and a  very in-efficient one at that, would be to make a class that will hold all of the vertices data for the entire game.
Is there any way to generate such an amount of vertices ? At your stage, the 2D features of your game needs a small amount of data, e.g. a quad is only 2 vertices X0Y0 - X1Y1, but it can be simplified if you decide not to fix the location, which gets you to only 2 values WIDTH and HEIGHT. etc.

Quote from: KaySchus on July 18, 2012, 03:35:36
 Then, as I need to add more (Say a bullet or some other generated entity in the game) I would have to copy the current vertex data, append the new vertex to the end, put it back in a buffer, and then rebind it to my VAO in order to render the changes.  This in and of itself seems like a terrible idea as it involves copious amounts of copying and overall seems like a poor way to implement the system.
Vertexes arrays will be used to send data to the opengl processor so that means you either keep a display list to generate your vertexes or keep up in the Java array a copy of the vertexes.
The fastest, but harder, way is to generate and store in Vertex Buffer Objects which will then render when needed. Using such VBO's means you have to keep a registry of all bindings and avoid redundancy of objects like small geometrical shapes.

Quote from: KaySchus on July 18, 2012, 03:35:36
Even more than that I do not truly understand how to manipulate the location of the vertices once stored in the buffer.  I understand I can pull the vertice data, alter it by some amount, then repackage it and bind it back to the VBO/VAO but that as well seems like a poor solution to the problem.  I feel that the system must be more streamlined than that and I must, in some way, be missing out on something that would greatly simplify all of this.
I'd recommend the http://www.songho.ca/ website tutorials (found on google, uh) which are very simple and functional. It covers most of the opengl concepts. :D

moci