Advertisement Jump to content
Sign in to follow this  


This topic is 3463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can you help me with this VBO, I can't figure it out correctly : The cpyArray is declared like so : cpyArray[ROW][COL][3]; where row = 32, col =32.



Share this post

Link to post
Share on other sites
I assume the array resembles a grid.

1. You don't specify texture coordinates, so you shouldn't enable GL_TEXTURE_COORD_ARRAY
2. Your array only has row*col vertices, so the last parameter of glDrawArrays should be ROW * COL (otherwise you'd read outside the VBO)
3. 4 consecutive vertices are used for one quad, so unless you specify most of the vertices multiple times (up to 4x) your grid will have gaps. I assume you want to use indices instead, i.e. glDrawElements(...)
4. Keep in mind that a quad must be planar, i.e. all vertices have to be in the same plane (e.g. same y-coord). If you want different heights for the vertices use 2 triangles instead.

Share this post

Link to post
Share on other sites
Looking at your code it seems like you are using just vertex array, not vertex buffer objects (VBO). Here is a tutorial that demonstrates the use of VBOs:
(Note that in the article they somehow forgot the glEnableClientState calls, although they can be found in the code samples)

To use VBOs you have to call glBindBuffer with GL_ARRAY_BUFFER. Make sure GL_ARRAY_BUFFER is bound before calling glVertexPointer. When using VBOs as opposed to vertex arrays, the last parameter of glVertexPointer is relative to the beginning of the buffer object (so 0 in most cases). The buffer is called by calling glBufferData, which copies the vertex data to the GPU memory.

Share this post

Link to post
Share on other sites
Sorry, I have the wrong terminology. This is just a test to get vertex arrays
working with rendering terrain.

I draw the quads like this

for( i = 0; i < ROW-1-stepRow; i+=stepRow)
float x0 = (float)i/ROW;
float x1 = (float)(i+1)/ROW;

for(j = 0; j < COL-1-stepCol; j+=stepCol)
float y0 = (float)j/COL;
float y1 = (float)(j+1)/COL;

//counter clockwise


But am not sure how to convert this array so either glDrawElements or
glDrawArray accepts it correctly.

Share this post

Link to post
Share on other sites
To use it with glDrawElements you have to create a index buffer.

The indices can be calculated like this:

for(int c = 0; c < (COLS - 1); x++)
for(int r = 0; r < (ROWS - 1); r++)
//indices: 1st triangle of quad
int i1t1 = r * COLS + c;
int i2t1 = (r + 1) * COLS + c;
int i3t1 = r * COLS + c + 1

//indices: 2nd triangle of quad
int i1t2 = (r + 1) * COLS + c;
int i2t2 = (r + 1) * COLS + c + 1;
int i3t2 = r * COLS + c + 1

And you should reread the documentation for glDrawArrays and glDrawElements. You have to specify the number of indices or vertices, not the number of floats. And any number you specify has to be less than or equal to the number of indices/vertices you use.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!