Vertex arrays & heightmaps
I have a problem concerning heightmaps in vertex arrays. I wanted to render the array as a triangle strip for obvious speed reasons, only I can''t figure out how to make an efficient array. What I came up with so far is this:
The data is placed in a vertex array to represent the triangle strip in the right order of rendering. So there are more vertices than actual pixels on the heightmap Cause a lot are rendered double.
This is the order in which the vertices are put in the array:
21 22/9 7 8
19 20/11 10/5 6
17 18/13 12/3 4
15 16 14/1 2
Starting in the right-bottom corner and working its way up, down for the second and third row and up for the 3rd and fourth row again.
This places a nice triangle strip in this pattern, the only problem: It only takes about twice as many vertices as needed.
The number of vertices =
pixels + (sqrt(pixels)-2) * (sqrt(pixels)-1)
That is, the number of vertices + the number of double vertices.
The number of double vertices =
(all columns exept last and first)*(all rows -1)
(-1 : see example vertex 7 and 16)
My question : How do I render a heightmap from a vertex array with the minimal amount of vertices?
Marty...
_____ /____ /|| | || MtY | ||_____|/Marty
I''m sorry, this message doesn''t take tabs... the vertex order again:
-23---24/9----10/7---8-
-21---22/11---12/5---6-
-19---20/13---14/3---4-
-17---18/15---16/1---2-
also :
The number of vertices =
Number of pixels - 2*(column size) (for first and last column)
so forget the calculations above...
Marty
-23---24/9----10/7---8-
-21---22/11---12/5---6-
-19---20/13---14/3---4-
-17---18/15---16/1---2-
also :
The number of vertices =
Number of pixels - 2*(column size) (for first and last column)
so forget the calculations above...
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
hehe, another mistake:
2*number of pixels - 2*column size...
2*number of pixels - 2*column size...
_____ /____ /|| | || MtY | ||_____|/Marty
Hey didn't you ask nearly the same question in another thread ? ;*))
Just store your vertices in an array, without bothering about the rendering order (was Data in your source code).
Then create another array (of GLuints) that will contain indexes of those vertices in the rendering order and invoke glDrawElements using this 2nd array.
Doing this, you won't need to store vertices twice...
[edited by - rodzilla on February 20, 2003 12:07:25 PM]
Just store your vertices in an array, without bothering about the rendering order (was Data in your source code).
Then create another array (of GLuints) that will contain indexes of those vertices in the rendering order and invoke glDrawElements using this 2nd array.
Doing this, you won't need to store vertices twice...
[edited by - rodzilla on February 20, 2003 12:07:25 PM]
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Yes, that was me in the other thread 
The storage isn''t the problem, it''s the order in which to render (the order to put them in the array of indices).
I''d like to create one big plane of triangles.
The way I described above, renders most verexes twice, cause it''s a strip and not a plane...
Is it possible to render planes, using something else than a triangle strip or an other way using a triangle strip, to render a plane using each vertex just once?
I guess not, but it can''t hurt to ask.
thanx, Marty

The storage isn''t the problem, it''s the order in which to render (the order to put them in the array of indices).
I''d like to create one big plane of triangles.
The way I described above, renders most verexes twice, cause it''s a strip and not a plane...
Is it possible to render planes, using something else than a triangle strip or an other way using a triangle strip, to render a plane using each vertex just once?
I guess not, but it can''t hurt to ask.
thanx, Marty
_____ /____ /|| | || MtY | ||_____|/Marty
I don''t have code for you right now, but here''s an example of how to do that.
Say you want to draw a 3x3 vertices plane :
0--1--2
3--4--5
6--7--8
You''ll have to store vertices 0 to 8 IN THAT ORDER in an array (Data) and specify the array using glVertexPointer.
Then you define the rendering order (indices in the Data array) :
GLuint r_order[] = { 0, 3, 1, 4, 2, 5, 5, 8, 4, 7, 3, 6 };
(not sure this one is correct, there may be a problem when changing rows if you''s culling front or back side, but I hope you get the idea).
And the invoke glDrawElements(GL_TRIANGLE_STRIP, 12, GL_UNSIGNED_INT, r_order) to render vertices from the vertex array specified with glVertexPointer (Data in this case) in the order specified in r_order. 2nd argument is the length of r_order, 3rd specifies the type of its elements.
I hope this is a bit clearer this time ;*))
Say you want to draw a 3x3 vertices plane :
0--1--2
3--4--5
6--7--8
You''ll have to store vertices 0 to 8 IN THAT ORDER in an array (Data) and specify the array using glVertexPointer.
Then you define the rendering order (indices in the Data array) :
GLuint r_order[] = { 0, 3, 1, 4, 2, 5, 5, 8, 4, 7, 3, 6 };
(not sure this one is correct, there may be a problem when changing rows if you''s culling front or back side, but I hope you get the idea).
And the invoke glDrawElements(GL_TRIANGLE_STRIP, 12, GL_UNSIGNED_INT, r_order) to render vertices from the vertex array specified with glVertexPointer (Data in this case) in the order specified in r_order. 2nd argument is the length of r_order, 3rd specifies the type of its elements.
I hope this is a bit clearer this time ;*))
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
More clear now, thanx.
Note that still all the vertices between rows (3,4,5 in this case) are rendered double, because it''s a strip
I think there''s no way of rendering a plane without rendering these vertices twice when using a strip. I''ll do it this way
Thanx again
Marty
Note that still all the vertices between rows (3,4,5 in this case) are rendered double, because it''s a strip

I think there''s no way of rendering a plane without rendering these vertices twice when using a strip. I''ll do it this way
Thanx again
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement