Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a 2D Terrain with opengl?

Tags:

opengl

I want to make a simple 2d terrain with just a few bumps and height changes:

terrain with le car

I thought about just using random numbers to describe the height of a certain vertex, but I don't see how I can make one mesh from this. I'm looking for a way to find the vertex and indices buffers for the terrain.
How do I do this?

like image 263
user717572 Avatar asked May 02 '12 23:05

user717572


1 Answers

You could just use GL_POLYGON with a list of all the vertices with the first and last vertice below the view.

if you want to use a triangle mesh you'll have to create a point directly below each height point(out of view) then the pattern(for clockwise ordering) would be:

for (number of height points-1)
    //vertices
     vertice below height;
     height vertice;
     next_height vertice;

     next height vertice;
     vertice below next height;
     vertice below height;

then working out the indices depends on how you store the vertices, but there will be a similar pattern in the array.

like image 81
Scott Logan Avatar answered Oct 19 '22 06:10

Scott Logan