简体   繁体   中英

What is the fastest way to show a regular grid with OpenGL using vertex buffer?

So I have a matrix of points of a digital elevation model, lets say 1024x1024 grid with a cell spacing of 1 unit.

I wan't to display this DEM with OpenGL the fastest possible way in c++ using vertex buffer. Since my data set is fragmented in tiles, I will have to do a lot of loading as I move the camera so this will need to be very fast.

What is the fastest way to show a grid like this? Do I need to do some sort of triangulation or is there a faster way to do it?

Correct in OpenGL you have to triangulate first. If you just want a simple solution, you can use the scheme pictured below.

You turn each data point into a vertex. The data point's indices become x and y coordinates; the height value becomes the z coordinate.

Now you have to create a vertex index list. The first triangle has indices [0, 1, 1024], the second [1024, 1, 1025], and so on. You draw your arrays as GL_TRIANGLES .

三角剖分方案

There are more efficient ways to triangulate height fields but I would not go there unless you really have to.

My approach would be to initialize a 1024x1024 vertex buffer with evenly spaced xz coordinates. The height can be sampled in the vertex shader by a 1024x1024 pixel height texture per patch. The vertex buffer can be re-rendered per visible patch, providing different height textures and different xz coordinate offsets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM