Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL 2D game question

Tags:

opengl

2d

I want to make a game with Worms-like destructible terrain in 2D, using OpenGL.

  • What is the best approach for this?
    • Draw pixel per pixel? (Uh, not good?)
    • Have the world as a texture and manipulate it (is that possible?)

Thanks in advance

like image 586
Mrfrank Avatar asked Dec 05 '22 01:12

Mrfrank


1 Answers

Thinking about the way Worms terrain looked, I came up with this idea. But I'm not sure how you would implement it in OpenGL. It's more of a layered 2D drawing approach. I'm posting the idea anyway. I've emulated the approach using Paint.NET.

First, you have a background sky layer.

alt text

And you have a terrain layer.

alt text

The terrain layer is masked so the top portion isn't drawn. Draw the terrain layer on top of the sky layer to form the scene.

alt text

Now for the main idea. Any time there is an explosion or other terrain-deforming event, you draw a circle or other shape on the terrain layer, using the terrain layer itself as a drawing mask (so only the part of the circle that overlaps existing terrain is drawn), to wipe out part of the terrain. Use a transparent/mask-color brush for the fill and some color similar to the terrain for the thick pen.

alt text

You can repeat this process to add more deformations. You could keep this layer in memory and add deformations as they occur or you could even render them in memory each frame if there aren't too many deformations to render.

alt text

like image 116
FogleBird Avatar answered Jan 01 '23 18:01

FogleBird