I have a question regarding OpenGL glBufferData() method.Can I pass the vertex data in structures like std::vector ,std::list or it must be a classic ( [] )array of numbers?
Asked
Active
Viewed 1,364 times
0
-
Yes: `glBufferData(target,size,&vec[0],usage)` – Keldon Alleyne Jan 14 '12 at 18:15
2 Answers
3
You have to pass a classic array to glBufferData() (the OpenGL API is defined in C). However, you can use std::vector<> by converting it to an array with &v[0]
(also see Converting between C++ std::vector and C array without copying).
-
Got you ,thanks for the answer.I mistakenly assumed other types could be used as well.Saw a code snippet with a custom data type name.But then found the typedef which eventually was array of floats .Thanks. – Michael IV Jan 14 '12 at 18:37
1
It basically needs an array. You should be able to use a std::vector
, since it requires contiguous storage. Most others, including std::list
, won't work. For std::list
, it would need to be written to follow pointers, and know enough about the internals to be able to find the pointers -- but that's likely to vary between implementations, and may even change by passing different flags with the same implementation.

Jerry Coffin
- 476,176
- 80
- 629
- 1,111