Deformable 2D terrain in OpenGL

Started by
5 comments, last by eldee 21 years, 9 months ago
Ok, i''m making a fairly simple war type game with deformable terrain.. ala worms/scorched earth/ect.. I''m using openGL for this, since my 2D engine is written using alot of OGL features.. so i''ll reitterate this before ever asking my question- i''m not posting today to ask ''whats the best api to use'' or ''which api do you think i should rewrite my engine in'' The question i have is this: What''s the most efficient way to deform the terrain? right now i''ve got it working pretty nice with height based deformations (a 1D array storing height of terrain that decreases upon collision or whatnot). I''ve been trying to think of a way to expand this to include width as well, that way i can allow players to ''drill holes'' and whatnot. there are a couple of methods i''ve thought of (and this is all just theory by the way). the simplist way that i can think of is to actually change the alpha values of the texture data from within OpenGL itself (and i dont even know if this is even possible.. if its not, it seems a bit slow to destroy/recreate a texture each time a collision happens). The other way i''ve thought about is using polygons.. but i cant think of a way to do it efficiently- for example you start off with one big polygon.. a hill or something. someone drills through the bottom of the hill, now you have two polygons. i suppose i could always just cap the number of polygons and store each polys info in an array... not really sure where to go with it. Someone suggested a quadtree type setup, but im not really sure how to incorporate that into it. if anybody''s done anything like this in GL or has any good ideas, let me know. -eldee ;another space monkey; [ Forced Evolution Studios ]

::evolve::

-eldee;another space monkey;[ Forced Evolution Studios ]
Advertisement
oi
-eldee;another space monkey;[ Forced Evolution Studios ]
Random idea: perhaps a landscape based on meta-balls? +itive fields to create the landscape and -itive fields added by explosions. Could get a tad slow with lots of deformation to rebuild the mesh but since its turn-based you could probably get away with a second or two pause.

_@/
i think you mentioned it, to change the alpha of the image upon each collision/explosion/etc.

just have 2 textured quads, one on top of the other, the top one is the undug dirt (light colored or whatever) and the bottom is dark colored tunnels. then when a collision occures, you edit the alpha of the top quad to show the bottom quad. this seems like a pretty resonable method.

hrm.. but how would i go about changing the alpha
values of the texture once it''s already been generated
in OpenGL?
the theory is sound, i just dont know if it''s possible (or
if it is, if it''s even worth it because of speed or
whatnot). any ideas?

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

-eldee;another space monkey;[ Forced Evolution Studios ]
well if u have a 2bit alpha map, then it wouldnt be that much to load or to change.

and i dont know how to change the alpha map, but im pretty sure its possible, you could just ask a question on how to change it on a different forum or maybe even in this on
many possible ways. heres one
devide the screen up into textures of say size 256x256.
these are 8bit luminance (greyscale) textures (though youll only use black + white)
*make white pixels where terrain is, black where its empty
every frame
-draw these textures first with GL_REPLACE
-enable blending with GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR (i think)
-draw the terrain (it will only get drawn where the white pixels are)
--------------
to deform terrain (one possible way)
*draw the black/white terrain
*draw the explosion in black
*find out which of the 256x256 textures the explosion happened in
*bind that texture + update it with glCopyTexSubImage2D(..)

this will go very fast even with a tnt

the key idea with this technique is the colour terrain texture doesnt change at all



http://uk.geocities.com/sloppyturds/gotterdammerung.html

This topic is closed to new replies.

Advertisement