r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

How To: Create a Simple Fireworks Effect in OpenGL and SDL

r3dux | October 31, 2010

I’m teaching the programming stream for Diploma in I.T. – Multimedia at the moment, so we’re going to be making some simple games and things over the next couple of months, but to start them off we’re doing a little bit of work on particle effects because they’re simple and fun – you just write a single class which describes the properties and behavior of your particle, and then scale it up by adding a large number of particles to get some pretty nice effects.

So instead of doing a particle fountain, I thought some fireworks might be kinda neat… Take a swiz at the video below and see what you think!

YouTube Preview Image

Full C++ source-code available after the break for those of a curious nature =D

Read the rest of this entry »

Comments
8 Comments »
Categories
Coding, How-To
Tags
Accumulation, Blur, C++, Effects, Fireworks, Motion, OpenGL, Particle, SDL, Trails
Comments rss Comments rss
Trackback Trackback

How To: Shrink/Compress a VirtualBox Windows Guest Machine

r3dux | October 28, 2010

When you create a VirtualBox virtual-machine, you get the option to choose either a fixed sized hard drive (in which case the entire amount of space is allocated and fixed immediately), or a dynamically expanding hard drive for the virtual machines OS and file storage (i.e. you specify a maximum size for the hard drive, it starts at 0 bytes, and increases as necessary up to the maximum you gave it on creation – at which point the drive is full).

Linux and Windows via VirtualBox

This is all well and good, but the problem with dynamic storage is that although it’s more than happy to increase in size, it doesn’t come down in size again when data is removed. So, to give an example, if you created a 10GB dynamic disk for a virtual machine it starts off at 0 bytes, you install a 1GB operating system and the drive is now 1GB in size (and hence taking up 1GB of space on your actual hard drive), you rip a 4.7GB DVD to the virtual drive which makes its size now 5.7GB, you delete the DVD rip so only the OS remains – and you might think that the “dynamic” drive will automatically shrink back down to 1GB, only it doesn’t. You’re holding on to 4.7GB of unrecoverable* bloat. Lucky you… =P

You could rip another DVD and re-use that space without the drive expanding any further, but really, it’s just going to increase and increase, and you’ll know in your heart of hearts that when you’re running low on disk space you could really do with that space back to your real hard drive. In VMWare you can compact the drive image as a menu option, but in VB we have to do a three step process… So, shall we?

* = unrecoverable unless you jump through the below 3 hoops, or create a new dynamic drive image, expand it to a size just over the size of your data on your original drive, then raw-copy the data across, that is… IMHO the steps below are easier!

A-B-C, Easy As…

  1. Defrag your Windows guest machine
  2. Now we need to replace all the “blank” (but still taking up space!) areas of our drive with zeros so we can recognise them to be stripped out later. Thankfully, this is really easy. Just download free (and tiny – 47KB) command-line utility SDelete from Microsoft and run it from within your virtual Windows guest machine with the following command (the -c switch is important!):
    sdelete -c
  3. Once that’s finished running shut down your virtual machine, navigate to the folder where your virtual machine hard drive is (such as ~/.VirtualBox/HardDisks) then from your host system run the following command to compress the hard drive down to a more reasonable size:
    VBoxManage modifyhd NAME-OF-YOUR-VIRTUAL-HARD-DRIVE.vdi --compact

    So if your virtual machine name (and thus by default the hard drive name) was “XP_Client_1″, then you’d use:

    VBoxManage modifyhd XP_Client_1.vdi --compact

With that done I trimmed down an excessively bloated 25GB .VDI of Windows 7 into a still excessively bloated 15GB – but that’s just in the nature of Microsoft OS’s… =P

Update: If you get an error stating things along the lines of:

VBoxManage: error: Cannot register the hard disk 'BLAH' because a hard disk 'BLAH' with UUID {LOTS-O-HEX} already exists

then you can fix it like this:

  1. Detach the drive from your virtual machine,
  2. Edit the file ~/.VirtualBox/VirtualBox.xml and remove all lines with the drive you want to compact mentioned in the HardDrives section (Note: be careful you don’t delete the virtual machine entry itself from the MachineRegistry section! Only remove the drive from the HardDrives section.),
  3. Now you’ll be able to compact the drive, and when it’s done you can re-attach the drive to your virtual machine. Good as old! =D

Snap Happy

Another thing you can do to decrease the disk usage of VirtualBox machines is get rid of all your snapshots if you don’t need them anymore. Each snapshot is basically an entire disk image which you can roll back to, so if you have Windows 7 installed it’s about 7GB or so after a fresh install, if you then put on 500MB of patches and take another snapshot you’re storing another 7.5GB. If you then install Office or something and that takes up 2GB and take yet another snapshot you’re burning through yet another 9.5GB, so we’re up to 23.5GB already for a single 9GB drive!

You should definitely be careful when merging snapshots into the main image (basically getting rid of the snapshots), as it has the potential to break, but more likely it has the potential to confuse and cause you to throw away data you didn’t mean to. This is because of some particularly ambiguous and misleading phrasing used in VirtualBox circles – the crux of the matter being:

  • When you restore a snapshot, it will throw the current state and/or any subsequent snapshots away and leave the machine in the state defined by the snapshot you’re restoring. This can mean a lot of changes which currently exist in the image being undone, and lot of files disappear, for example – the only copy of important documents created since the snapshot you’re restoring was made. Use with care.
  • When you delete a snapshot, it will actually merge the current state of the machine into the snapshot before removing that snapshot and leaving the machine at it’s current merged state but without the snapshot existing…

Yeah, I know it’s confusing, so just be careful, okay? If you’ve got the space available just take a copy of the .VDI file from the HardDisks folder AS WELL AS a copy of the snapshots by copying the folder with the name of your VM from the Machines folder, and then merge in the snapshots – this way if it all goes nuts you can’t throw away the knackered copy and replace it with your pristine pre-merge copies.

Cheers!

Credits: Thanks to Damien for his article at MakeTechEasier for the initial information (you can also find out how to compress Linux guests there too, but just be aware that the technique he outlines involves cloning the drives then shrinking and re-importing them) and to Alphatek’s article for the simplification!

Comments
No Comments »
Categories
How-To
Tags
Compress, Hard Disk, Hard Drive, Linux, Merge, Shrink, Snapshot, VirtualBox, Windows
Comments rss Comments rss
Trackback Trackback

Deer Tick – Twenty Miles

r3dux | October 24, 2010

Deer Tick - Black Dirt Sessions cover art

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Raindrops like bullets on my fragile skin
And the securities I’ve had are creeping within
Now I’m 20 miles outside of the place that you live
And I need one more chance now that time’s running thin

Well you are the things that make up my dreams
And I’ve spent every dime that jingles in my jeans
I deserve every stone that’s thrown out at me
And I think of your smile, I’m in love with your teeth

I’m losin’ when I am not playin’ no games
Now, would you take me back when I gamble my pain?
I’ve got no direction without her little fingers
Barbed wire, razor wire, nothing keeps me from her

Now if I had no boots, I’d trek through the mud
While mosquitos are racing to draw the first blood
If you’re runnin’ away, then I’m lookin’ for you
And if you’ve lost your way, I’m seein’ you through.
If you’re runnin’ away, then I’m lookin’ for you
And if you’ve lost your way, I’m seein’ you through.

Comments
No Comments »
Categories
Music
Tags
Deer Tick, The Black Dirt Sessions, Twenty Miles
Comments rss Comments rss
Trackback Trackback

How To: Enable “Stereo Mix” in PulseAudio and Record Absolutely Any Playing Audio

r3dux | October 23, 2010

I found these instructions on the PulseAudio Wiki a long while back, but they still work (circa Ubuntu 10.10) and are super useful to record streams/record the audio from videos (i.e. YouTube), so I thought I’d put this out here under a different heading to help people find the info…

  1. Install PulseAudio Volume Control by running the following in the Terminal:

    sudo apt-get install pavucontrol
  2. Fire up Audacity and:
    – Go to Preferences by pressing Ctrl+P (or select “Edit” -> “Preferences…” from the drop-down menu).
    – Click the “Devices” .
    – Change the Playback device to “pulse”.
    – Change the Recording device to “pulse”.

  3. Open PulseAudio Volume Control (“Applications” -> “Sound & Video” -> “PulseAudio Volume Control”) and leave it open.
    The first time you use a recording program you need to to edit the recording settings of PulseAudio Volume Control. It should remember your settings after rebooting.

  4. Open Audacity and hit the “Record” button.

  5. While Audacity is recording, open PulseAudio Volume Control and select the “Recording” tab. It will show “Alsa plug-in Audacity. Alsa capture from” and a combo-box. Choose the “Monitor of internal audio…” if you use an internal sound card.
  6. Note: You need to select another monitor if you use any playback device other than an internal sound card. For example, when I play sound with Microsoft LifeChat headphones connected to my computer via USB, I select the “Monitor of Microsoft LifeChat Analogue Stereo” to capture from it with Alsa.

  7. Check Audacity, it should be recording now.

Sling a note in the comments if you’re having any difficulty enabling recording of the “stereo-mix” output – not that you should come up against any problems, but I’m happy to work on clarifying the wording if it’s necessary…

Cheers!

Comments
11 Comments »
Categories
Linux, Music
Tags
Audacity, PulseAudio, Record, Stereo Mix, Stream
Comments rss Comments rss
Trackback Trackback

How To: Draw Motion-Blur/Trails using the Accumulation Buffer in OpenGL

r3dux | October 21, 2010

I read that this is the slow/old-school/borderline-retarded way of going about adding motion blur to your scenes, but I haven’t started learning GLSL yet, so for the time being at least, this works :D

OpenGL Accumulation Buffer Motion-Blur/Trails

The trick is that you have to perform the following actions in this specific order in your drawing function for it to work:

  1. Clear the colour buffer (i.e. the screen) and the depth buffer (really, the colour buffer doesn’t need to be cleared because we’re over-writing it later, but the depth buffer definitely does!).
  2. Copy the accumulation buffer over the top of the colour buffer. (i.e. the contents of the colour buffer gets overwritten with the contents of the accumulation buffer).
  3. Clear the accumulation buffer.
  4. Draw your geometry.
  5. Copy the colour buffer onto the accumulation buffer. (i.e. the contents of the accumulation buffer gets overwritten with the contents of the colour buffer).

The relevant section of code from my drawScene() function is:

    // Clear the draw and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    // Take the contents of the current accumulation buffer and copy it to the colour buffer with each pixel multiplied by a factor
    // i.e. we clear the screen, draw the last frame again (which we saved in the accumulation buffer), then draw our stuff at its new location on top of that
    glAccum(GL_RETURN, 0.95f);
 
    // Clear the accumulation buffer (don't worry, we re-grab the screen into the accumulation buffer after drawing our current frame!)
    glClear(GL_ACCUM_BUFFER_BIT);
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
    // Translate everything into the screen (z-axis) by -windowDepth
    glTranslatef(0.0f, 0.0f, -windowDepth);
 
    // Apply oscillating rotation to the matrix around the Z-axis.
    // Multiplying by 100 is just a fudge factor to increase the total rotation amount
    glRotatef(cos(deg2rad(Star::rotationAmount)) * 100, 0.0f, 0.0f, 1.0f);
 
    vector<star>::iterator starIter; // This needs to be a standard iterator not a constant iterator so we can modify what's being pointed to!!
 
    // Do the actual drawing...
    for (starIter = stars.begin(); starIter != stars.end(); starIter++)
    {
        // Change the point size to the stars size property
        glPointSize(starIter->getStarSize());
 
        glBegin(GL_POINTS); // This needs to be inside the loop so the PointSize change (above) takes effect
 
            // Set the colour
            glColor3f(starIter->getRedComponent(), starIter->getGreenComponent(), starIter->getBlueComponent());
 
            // Draw the point
            glVertex3f(starIter->getX(), starIter->getY(), starIter->getZ());
 
        glEnd();
 
        // Move the star closer (or reset it if it's too close) ready for the next frame
        starIter->moveStar();
    }
 
    // Swap the buffers so we can see what we've drawn without -watching- it being drawn
    SDL_GL_SwapBuffers();</star>

Note: See that </star> tag at the end of the above code snippet? That doesn’t exist. It’s an artifact produced by WordPress in combination with the WP-Syntax plugin and is somehow related (I think) to escaping HTML entities and auto-completion of mismatching XHTML. Don’t believe me? Click the title of the post or the read more link below and find the same section of code in the full listing – for some reason it doesn’t appear there… Odd, huh?

Update: Uploaded a screen capture of the program running to YouTube so you can see it in action without having to compile it yourself:
YouTube Preview Image

Full source-code available after the jump for those interested…

Read the rest of this entry »

Comments
No Comments »
Categories
Coding
Tags
Accumulation, Buffer, C++, Motion-Blur, OpenGL, SDL, Trails
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Class Convert CS4 Effect Error Film Flash GLSL Gnome Hack How-To install Jaunty Java Kinect Linkage Linux Mash-Up Microsoft Motion OpenGL Particle Problem PS3 Remix Retro script Slides Sound Systems Texture Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“The only way to have a friend is to be one.”

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox