Archived

This topic is now archived and is closed to further replies.

Deformable 2D terrain in OpenGL

This topic is 5644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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::

Share this post


Link to post
Share on other sites
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.

_@/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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::

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites