I've written a model loader in C++ an OpenGL. I've used std::vector
s to store my vertex data, but now I want to pass it to glBufferData()
, however the data types are wildly different. I want to know if there's a way to convert between std::vector
to the documented const GLvoid *
for glBufferData()
.
Vertex type
typedef struct
{
float x, y, z;
float nx, ny, nz;
float u, v;
}
Vertex;
vector<Vertex> vertices;
glBufferData() call
glBufferData(GL_ARRAY_BUFFER, vertices.size() * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
I get the following (expected) error:
error: cannot convert ‘std::vector<Vertex>’ to ‘const GLvoid*’ in argument passing
How can I convert the vector to a type compatible with glBufferData()
?
NB. I don't care about correct memory allocation at the moment; vertices.size() * 3 * sizeof(float)
will most likely segfault, but I want to solve the type error first.
question from:
https://stackoverflow.com/questions/7173494/vbos-with-stdvector 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…