Gradients and SGFont update

SIEGE has just got a new feature – gradients.

SGGradient is a new structure which holds the data for a gradient – a smooth (or, depending on interpolation, not-so-smooth) transition of colors on a scale from 0.0 to 1.0 – of course, stops can be added in between, so that you can go from, say, 0.75 past 0.25 to 1.0. The gradients are (by design) not limited to color information, but can hold any form of info – for example, a heightmap for a side-scroller could be stored in this way. SGColorGradient will be added later on, and will be a “specialization” of SGGradient for RGBA color info.

For those wondering how to use this functionality, here is an example:

// creates a gradient with two stops: (0.0 -> 0.0) and (1.0 -> 1.0)
SGGradient* grad = sgGradientCreate();

    Add some stops; note that the stops at
    0.00 and 1.00 are automatically replaced
sgGradientSetStopKey(grad, 0.00, 1.00); // 0.00 -> 1.00
sgGradientSetStopKey(grad, 0.25, 0.75); // 0.25 -> 0.75
sgGradientSetStopKey(grad, 0.75, 0.00); // 0.75 -> 0.00
sgGradientSetStopKey(grad, 1.00, 0.50); // 1.00 -> 0.50

// ...
// draw the gradient...
size_t i;
for(i = 0; i < 640; i += 16)
    // grayscale gradient color: rgba(g, g, g, 0.0)
    sgDrawColor1f(sgGradientGetValue(grad, i / 640.0));
    sgDrawRectangleWH(i, 0, 16, 480, SG_TRUE);
// ...


…and that’s about it regarding the use! Here is a screenshot of the gradients in action (note: this is not the same gradient as the above code):

Interpolations from top to bottom: Nearest-neighbour, linear, cosine, cubic - custom interpolation functions are supported. Dim orange lines are stops.

Now that gradients are settled, onto the 2nd update: SGFont API change.

Until now, SGFont had a LOT of different functions for printing:


All of these had 9 variants, for a total of 27 functions. They have all been replaced with a set of new functions, sgFontPrintAligned*:

void sgFontPrintAligned(SGFont* font, float x, float y, SGenum align, const char* text);

// example:
// print X-cented, but on the Y baseline
sgFontPrintAligned(myfont, 320, 240, SG_ALIGN_CENTER | SG_ALIGN_BASELINE, "Hello, font world!");

// the following constants are available:
// SG_ALIGN_CENTER   - x or y-centered (used for both because its value is 0)
// SG_ALIGN_LEFT     - left-aligned on x
// SG_ALIGN_RIGHT    - right-aligned on x
// SG_ALIGN_TOP      - top-aligned on y
// SG_ALIGN_BASELINE - baseline-aligned on y
// SG_ALIGN_BOTTOM   - bottom-aligned on y

…plus variants. The “old” functions still exist, but they have been deprecated and are scheduled to be removed soon (since most are almost unused, very soon) without notice whatsoever.

Yes, there are more arguments to pass, but it is much more flexible – for example, there existed no way to print right-, top- or bottom-aligned text – there was only left/center on x and center/baseline on y. Furthermore, a switch was previous required in case certain alignments were required under certain conditions (to make sure the right function is called) – now, it is only a matter of a different argument.

Well, that pretty much concludes today’s post – I hope the new gradients and font drawing functionality will come in handy!

Posted in SIEGE.

Audio is back in

SIEGE has been without audio for quite some time, pending correction of a couple of bugs – this took quite a long while simply because I couldn’t get the bugs fixed earlier. I’ve corrected the breaking bug now, however and even some other bugs in audio, so it now works!

You can check it out in the “audio” example, but make sure you have FLAC and Vorbis libraries installed or else you will get silence since it won’t know how to load the audio files.

Streaming is not yet supported – the audio has to be preloaded as a whole – but it is planned.

There is one more feature, however, which is designed to ease the creation of “fire and forget” sound effects – sgAudioSourceDestroyLazy. You can find an example of use in the aforementioned “audio” example, but here it is for those who don’t want to bother checking:

void createExplosion(SGAudioBuffer* buffer)
     * Explosions are:
     * - high-priority sounds (10.0 priority)
     * - loud (1.0 volume)
     * - "powerful" (pitch reduced to 0.5 to make it sound "deeper")
     * - non-looping (looping set to SG_FALSE)
    SGAudioSource* source = sgAudioSourceCreate(10.0, 1.0, 0.5, SG_FALSE);
    sgAudioSourceQueueBuffer(source, buffer);

     * Newest addition - this will wait until the source
     * stops playing (looping is automatically set to SG_FALSE)
     * and then destroy the source.
Posted in SIEGE.

Particle system and more

A minor update this time – hold on to your seats though because more is coming soon!

Here are some of new features that SIEGE has got:

  • Particle system, created by tshirtman
  • AA trees (also known as Andersson trees) for mapping of value->value
  • FPS counter, frame limiter and high-precision time/sleep functions – created by bernardh
  • Depth testing can now be toggled
  • Drawing of smooth points, lines and polygons can now be toggled
  • New “Pyramid” example

As always, there are also a couple of bugfixes and other misc. changes here and there.

Screenshots for the particle system will follow later, as I have yet to create a good demo for the feature.

Posted in SIEGE.