Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openGL and STL?

Tags:

c++

stl

opengl

I am using openGL and am currently passing it a vertex array. The problem is that I have to create many vertices, and add them in between one another (for order). This means that using a regular array is pretty annoying/inefficient.

I want to use a data structure from STL so that I can efficiently (and easily) put new vertices at any index. The problem is that openGL expects a regular array.

Does anyone know how to go about this? Is there an easy way to convert from an STL vector to an array?

I am using openGL 1.1

Thanks

like image 853
Ori Avatar asked Sep 20 '09 01:09

Ori


1 Answers

You can use a pointer to the first address of the vector as an array pointer. STL vectors are guaranteed to keep their elements in contiguous memory. So you can just do something like:

&vertices[0]

where vertices is your vector.

like image 105
Laurence Gonsalves Avatar answered Sep 16 '22 11:09

Laurence Gonsalves