OpenGL VBO
-
hey,
I'm working with VBO's and trying to understand why the following code works with std::vector<GLfloat> vertices
and doesn't work with std::vector<GLfloat> vertices = new std::vector<GLfloat>();
@
std::vector<GLfloat> vertices;vertices.push_back(0.0f);
vertices.push_back(0.0f);
vertices.push_back(-2.0f);GLuint bufferID;
glGenBuffers(1,&bufferID);
glBindBuffer(GL_ARRAY_BUFFER,bufferID);
glBufferData(GL_ARRAY_BUFFER,sizeof(float)*3,&vertices[0],GL_STATIC_DRAW);glVertexPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);glPointSize(4);
glDrawArrays(GL_POINTS,0,1);
glDisableClientState(GL_VERTEX_ARRAY);
glDeleteBuffers(1,&bufferID);
@using new:
@
std::vector<GLfloat> *vertices2 = new std::vector<GLfloat>();vertices.push_back(0.0f);
vertices.push_back(0.0f);
vertices.push_back(-2.0f);GLuint bufferID;
glGenBuffers(1,&bufferID);
glBindBuffer(GL_ARRAY_BUFFER,bufferID);
glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*3,&vertices2[0],GL_STATIC_DRAW);
//also tried glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*3,vertices2,GL_STATIC_DRAW);
glVertexPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);glPointSize(4);
glDrawArrays(GL_POINTS,0,1);
glDisableClientState(GL_VERTEX_ARRAY);
glDeleteBuffers(1,&bufferID);
@ -
Hi,
In the first case, you are giving the address of the first element of the vector in the second case since you have a pointer to a vector, you are giving the address of the vector itself.
-
I also thought this could be the problem, but I don't know the solution how I get the adress of the vector element with *vector = new vector() version
-
You need to deference it first
@&(*vector)[0]@
But it looks like you are going in unknown territory. Why not simply use a QVector ?
-
I tried this one, but for
@&vector->at(1)@
and
@&(*vector)[1]@i get the same address as output.
I'm not using QVector because, it's a Non-QT Project
-
and if I use @&vector@ it's a different address than the both i posted above.
-
ok but @&vector[0]@
is an different address,
mby
@ &vector->at(0) @
(or
@&(*vector)[0] @
seem to be the same)
will work in openlgl I'll try that
but i think I alrdy tried &vector-at(0) and It didn't work, we'll see