I’m trying to understand vertex array a little bit more. In my current code I use vertex arrays to store all the information of the 2D images that I render using quads but I would like to add more shapes(triangles, points, etc). How do I go about doing that?Do I need a separate array for each primitive or can I mix them and then there is a trick to process them?Any help would be greatly appreciated. Thank!
Well, basic idea as follows: create your vertex structure, for example
float x,y,z; //coord
float s,t; //texcoord
then get your models into array of vertices. Also create array of indices for them to render in quads, triangles or triangle strips. Indices are going to separate array, because their number is not connected directly with number of vertices they reference…
Generate two buffers with glGenBuffersARB(2, vbo);
Set vertex buffer data with
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vSize, vertexArray, GL_STATIC_DRAW_ARB);
Set index buffer data with
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iSize, indexArray, GL_STATIC_DRAW_ARB);
Then draw it with glDrawRangeElements, and that’s it.
Thank you so much for taking the time to answer my question. I will study the code that you just posted and report back if I have any other questions. Thanks a ton.