Blobby Objects in OpenGL

BlitzMax Forums/BlitzMax Tutorials/Blobby Objects in OpenGL

ImaginaryHuman(Posted 2005) [#1]
Hi folks. Recently I posted a tutorial on how to render fast 2D blobby objects in BlitzMax in realtime, in this thread:

http://www.blitzbasic.com/Community/posts.php?topic=45716

I decided to release a more complex version of my blob routines that uses lots of direct OpenGL and almost no Max2D commands. This version loads and needs four pre-rendered blob-field images (examples included below) which are 512x512 grayscale RGB images in PNG format. It also loads a `filler` image texture which is a 256x256 color RGB image in PNG format (example also included below).

This version can actually load 4 different blob-field images at once so you can experiment with using the same one four times or more than one kind. These blob images are based on a standard blob field as generated by the included `DrawSquare512` and `DrawBall512` programs. Using those programs you can generate the basic blob field - I use a screengrab to save them to disk as PNG's. They have been loaded into image processing graphics software and manipulated, for example applying a simple `twist/twirl/spin` effect. There are many effects you could apply, for example a wave or ripple effect. Effects that move the pixels around, preserving the basic content, are the best and still produce a blob effect.

This version doesn't include animation but I have since implemented an animated version that loads 20 frames of a cyclic animation, produced with image processing software applied to the standard blob field image with a rippling wave effect.

You can move the mouse around to move all of the blobs. Positioning the mouse near the lower right at about 3/4 of the width and height of the screen produces a fairly stationary shape.

I haven't tidied up the code too much and there is some old/optional bits that are commented out. There's also some extraneous OpenGL calls near the start that may not be needed - but I found that the `default` state of the OpenGL machine was different on different platforms, so I'm just making sure things are set up right.

For me this runs okay on an iMac 1GHz G4 with an nVidea GeForce 4MX at around 30fps with vblank synching. You may need a comparable gfx card performance (750 million texels/second or so at least, I would guess - the GeForce 4MX is 1 billion texels/second).

Feel free to use this for whatever purpose you like, no strings attached. I hope it will work on your system with no problems.

These are four different blob field images that you will need. Currently the code will load all four but you could change it to load only one repeatedly. The reason I applied a `twist` effect to the blob field is that it produces much smaller blobs and is still smooth. It took a lot of experimentation to come up with this effect.








You also will need this filler texture image (or something similar). Any 256x256 PNG will do but it should be RGB not RGBA (no alpha). This image is just faded out at the edges so as to smoothly blend together. Other images that I found interesting were based on clouds or fractals.


This is the main program and is freeware. I apologize for any untidyness or `procedural coding` technique, it's not very object-oriented. The blob images are uploaded as GL_ALPHA textures, which are just one 8-bit color component per pixel. This saves on storage space, and allows use of particular blend modes later on. The filler image is regular color texture. The rendering code within the main loop - you can comment out whole sections if you'd like to see the effect that each part has. There are also some flags at the top of the code to turn certain things on and off. You can also modify the rotation angle increments and the kind of colors that are produced at other points in the code.


This is the program you use to generate a basic blob field image, freeware also. This one generates circular blob fields (standard blobby objects). This produces blobs that form nicely curved outlines as standard. The commented-out code at the end adds various extra little effects to it (just experiments).


And this one generates a blob field image based on squares - this produces a very interesting bubbling blob effect of many different shapes and sizes (of course freeware too). I have never seen this done before so maybe I can lay claim to actually inventing this! Since it is based on squares you might think it couldn't produce a blob shape, but it actually does, and goes further to add a lot of variety.


The effect should end up looking something like this:


All these files are free for your use in whatever manner. :-)


BlitzSupport(Posted 2005) [#2]
Thanks AD, that's very generous, but I'm getting the same problem here that occurred with the old Blobs + OpenGL demo -- the screen's all black... :(


Koekelas(Posted 2005) [#3]
I'm still experimenting whit the previous examples and here you are whit yet another excellent tutorial. I'm glad you decided to continue working on this. Thank you very much AngleDaniel.

Btw, it works fine here. Mac power I guess.


Nicolas.


ImaginaryHuman(Posted 2005) [#4]
James - I will try to figure out what might be wrong, but I can't really test it if it's running fine for me here. Are you on a Mac too?


Sarge(Posted 2005) [#5]
AngelDaniel i have the same problem on WindowsXP it seems to be a dark backround i can hardly see the objects. I tried glDrawBuffer(GL_Front) i can see it like that but all messed up.


Koekelas(Posted 2005) [#6]
AngelDaniel, can you tell us how you did that twist effect on the first three metaballs?


Nicolas.


LAB[au](Posted 2005) [#7]
I have the same problem as Sarge... on Win2K (Geforce FX5900) I can see only colored "ball48.png" textures rotating, but very dark and nothing else. Strange...


BlitzSupport(Posted 2005) [#8]
Angel, that was on XP, so I guess you can't do much. It does work on the Mac -- slow in 1024 x 768, but decent in 640 x 480.

(I don't know enough 'raw' OpenGL to debug it myself on XP!)


ImaginaryHuman(Posted 2005) [#9]
Oh ok. I can't help too much with the problem if it's produced only on the PC. Perhaps some other handy OpenGL-familiar coders can help to find the problem. Otherwise you could just go through and comment out various sections and see if you can find which part is wrong. I'm glad it works okay on the Macs. Since OpenGL is *supposed* to be standard on all implementations, and this doesn't use any extra extensions, I would've thought it should work the same on the PC. But you know how Microsoft can be ;-D Having said that the software rendered on my iBook has different default state than the hardware driver on my iMac.

Nicolas - the twist is just your average `twirl` or `spin` image-processing effect. Load the standard plain square image into whatever image processing software, for example Gimp or Photoshop, and just apply the filter to it. Simple as that. Other filters of interest for effects are ripple and wave effects.


Koekelas(Posted 2005) [#10]
Thanks AngelDaniel. I'm not that handy whit Gimp. I combined the two tutorials and I came up whit more or less the same result as above but whit much lesser OpenGL.


Nicolas.


ImaginaryHuman(Posted 2005) [#11]
Understandable. The second program in the original tutorial more or less achieved all the same steps in the pipeline, it would just be a matter of loading in a square-based blob image and moving the stuff around.