Draw filled 2d landscape

Started by
3 comments, last by steg 12 years, 10 months ago
Hi,

Quite new to OpenGL but using OpenGL ES on mobile. Now I know it doesn't support GL_POLYGON so I thought maybe I can just use GL_TRIANGLE_STRIP. I want to create a
random 2d landscape for a side scroller, think of the old arcade game Defender, but I want the landscape filled in. Now I am guessing that I will need to create a lot of quads to do this and
fill each of them in? Is this the best approach?

Thanks,
Steve

If it isn't working, take a bath, have a think and try again...

Advertisement
GL_POLYGON is dead meat in GL 3.0 as well.
For GL ES, use GL_TRIANGLE_STRIP or GL_TRIANGLES with glDrawElements.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanks,

Was thinking of using glDrawArray?...

Would I have to draw each part of the landscape as a series of triangles that make a quad in order to fill them?

Many thanks,
Steve

If it isn't working, take a bath, have a think and try again...

With GL_TRIANGLES and glDrawElements you can render the entire terrain with a single call.

With GL_TRIANGLE_STRIP and glDrawElements, it depends. You would either have to render each strip, one by one.
Or you can use NULL triangles and use a single call to glDrawElements. You would have to research the hardware capabilities of your target platform if it handles NULL triangles well.

I won't make performance recommendations since I don't program for embedded systems.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanks for the info.

I've now generated the landscape using GL_TRIANGLE_FAN. Landscape kind of like the old moon patrol game if you know it? Would love to know how to create 'curved' landscape that is filled in, I guess you need some form of triangulator to do this? Was thinking of generating the curve with some simple math, but dunno how you would triangulate it?!

Thanks,
Steve

Landscape on iPhone


If it isn't working, take a bath, have a think and try again...

This topic is closed to new replies.

Advertisement