array vs pointer to array question

Hi,
I'm confused about the following situation:

The following code when I use an array works fine

1
2
3
4
5
6
7
8
//declare vertex
glm::vec2 vertex[1000];   //a very large size

//load the vertex
...

//send vertex to buffer
glBufferSubData( GL_ARRAY_BUFFER, 0 ,sizeof(vertex[0])*vertexSize,vertex );


but if I use a pointer to array

1
2
3
4
5
6
7
8
9
10
11
12
//declare vertex
glm::vec2 * vertex;


//allocate vertex
vertex = new glm::vec2[vertexSize];

//load the vertex
...

//send vertex to buffer
glBufferSubData( GL_ARRAY_BUFFER, 0 ,sizeof(vertex[0])*vertexSize,vertex );

the code does not work as intended.

What I'm doing wrong?

From the openGL reference, the signature of the method is:
void glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data);

thanks in advance
Last edited on
What is waterVertex?
ups...waterVertex is of the same type as vertex.
Last edited on
And vertexSize does not change between the array is allocated and glBufferSubData is called?
the code does not work as intended.
Will you be a little more specific please.
vertexSize, once set, remains constant during the whole program, but it is unknown at compile time
When I use a pointer to array, the screen is blank as if no data was copied to the opengl array buffer.

I have printed vertex in both examples before calling glBufferSubData to check if they contain the same data, and they do. That's why I was thinking that there is something wrong between glBufferSubData and glm::vec2 * vertex.
Last edited on
Topic archived. No new replies allowed.