OpenGL Worms-style rendering

Started by
13 comments, last by Nudel 16 years, 9 months ago
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
Advertisement
For maps the size of worms I'd look into voxels.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

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.
u could use the stencil buffer

eg stencil = 0 == empty, 1 == ground
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?
"I don't care if I fall as long as someone else picks up my gun and keeps on shooting."
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
I would take the texture representing your landscape then remove bits from it when an hole needs to be made.

Degra
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.
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

Beginner in Game Development?  Read here. And read here.

 

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)

This topic is closed to new replies.

Advertisement