views:

628

answers:

2

What I want to do is drawing a (large) terrain with OpenGL. So I have a set of vertices, lets say 256 x 256 which I store in a vertex buffer object in the VRAM. I properly triangulated them, so I've got an index buffer for the faces.

// vertexes
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId);
glVertexPointer(3, GL_FLOAT, 0, 0);
// textures
glBindBufferARB(GL_ARRAY_BUFFER_ARB, texCoordBufferId);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
// indexes
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexBufferId);
// draw it
glDrawRangeElements(GL11.TRIANGLES, 0, size - 1, size, GL_UNSIGNED_INT, 0);

I also loaded a square texture which has to be applied to each triangle. So I've got a problem with the texture coords:

Each vertex is included in 4 triangles which means it needs 4 texture coords. But glDrawRangeElements() requires as much texture coords as vertexes.

So I don't the see the way how to do this with the VBOs. Maybe there is better concept for solving my problem or I'm just lacking a good idea.

Thanks in advance.

+3  A: 

If your texture should repeat (or mirror) itself in each quad the best way would be to use texture coordinates that match the number of the (x, y) position in your array. E.g. for the first line of vertices use these texture coordinates: (0.0, 0.0), (1.0, 0.0), (2.0, 0.0)...(255.0, 0.0).

Maurice Gilden
Thanks, that was what I was missing...
Stefan Teitge
A: 

As you probably want your texture to seamlessly tile, all you need to is to compute the proper texture coordinate for each vertex and pass them just like the vertices.

karx11erx