user717572
user717572

Reputation: 3652

How to make a 2D Terrain with 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?

Upvotes: 6

Views: 1500

Answers (1)

Scott Logan
Scott Logan

Reputation: 1516

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.

Upvotes: 1

Related Questions