Jump to content
  • Advertisement
Sign in to follow this  
lightfoot

OpenGL OpenGL Worms-style rendering

This topic is 4065 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

Hey, I'm working on a game that requires a similar effect to that of worms, where the player can "dig" into the landscape using explosions or tools, however, I'm not quite sure how this works from an OpenGL perspective. When I was doing this using SDL I stored the map data in one structure then as it changes I either update the screen surface or update the screen buffer. Is there an easy way to achieve this same effect using OpenGL that can take advantage of the hardware acceleration? The display will be updating quite rapidly (especially for water and gas particles) - so I'm looking for something speedy :-p Cheers, Chris

Share this post


Link to post
Share on other sites
Advertisement
You can still approach this in GL using a pixel buffer, but that'll be fairly slow.

One way you might want to do it is using Boolean CSG operations. Here is a demo I generally reference for this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike2343
For maps the size of worms I'd look into voxels.


From what I gather, voxels are more or less nothing more than pixels in 3D form, so that would seem rather redundant in his case (a Worms-like game).

If you could, say, take your level, subtract holes from it (think CSG?), and then tessellate that (I believe GLU has a tessellator?), that would likely be quite fast for your purposes. What sorts of holes are you planning on having, though - circular, fairly random, etc?

Share this post


Link to post
Share on other sites
it sounds as if the OP wants a 2d game. in which case stencil (or alpha or even another buffer) is best suited, itll let u hollow out any shapes.
applying multiple cuts to the same geometry is messy to say the least.

also voxels aint 3d pixels

Share this post


Link to post
Share on other sites
I would take the texture representing your landscape then remove bits from it when an hole needs to be made.

Degra

Share this post


Link to post
Share on other sites
What I would do is keep the terrain texture in RGBA format. Then whenever you want to blast a hole in the terrain, you render that hole to the alpha channel by zeroing it out. Then when you render the terrain, use the alpha test to keep from rendering holes. If you want your terrain to be alpha blended in addition to having holes, then just use a separate texture altogether for the blending alpha.

Now let's say your worms use bounding spheres for collision. Take the terrain texture, and perform a Gaussian blur on the alpha channel to create a single-channel collision texture. Then whenever you want to do collision, sample from this texture and if the value is above a certain threshold the terrain is solid, otherwise it's a hole. This method might take some tweaking so that you blur the alpha just right to get the correct radius for your spheres.

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
....
also voxels aint 3d pixels


voxels = volumetric pixels; volume = width, length, height (x, y, z; irrespectively)

so it seems like voxel = 3D pixel

Share this post


Link to post
Share on other sites
as Mike2343 stated, you should look into voxels..

i dont know much about them, but i imagine it as a 2d grid, with square cells (side for example 32 pixels)
every cell would have tag, whether it is:
- free - no pixels stored, there is nothing (so it is totally ignored)
- full - all pixels, so it is not needed to store them (rendered normally)
- mixed - contains 32x32 array of pixels (render with stencil or anything)

this way you dont need to store the whole map
if you had a map of 8192x2048 pixels, that would be 256x64 cells (32x32)
each cell 32*32=1kB booleans (i think bools take 1 byte each in c++)
so there is 16k cells (256*64), that is 16MB of data

but only the mixed cells need to store the data
so lets say there is 1024 mixed cells (probably less)
now that is only 1k*1k = 1MB

(dont know about speed of stencil stuff, but it should work)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!