A fine example of shitty graphics

posted in NO
Published June 24, 2007
Advertisement
Sprite Editor

Well, I implemented a sprite extraction routine which will grab sprites from an image based on the image alpha or color or a combination of alpha and color. It's horrific in its slowness. But in my defense, I don't care (and it's really not -that- slow). I don't have any timings, so don't ask.

One of the things that really slows it down is the damned checking mechanism. It basically finds an origin for a sprite, then loops through its list of already extracted sprites, and determines if that point already exists within a sprite that's been extracted. If true, then it rejects it, if not it then continues to find the dimensions of the sprite and extracts it. It's a gross way to do it, but it works. However, it's really nice that I can lay out the sprites however I want on an image (and thus make the best use of space), and be confident that it'll never grab the same image or a piece of the same image over and over again, which my original attempt did. It made me mad.

I'm sure that's old hat to most people who've done this sort of thing before, but I haven't, so fuck off to you old hatted bastards.

Glorious artwork

So as a break from the mundane task of writing the sprite editor, I decided to write up an example application for Gorgon:

As you can see, it's fucking beautiful. Never has a more glorious piece of artwork graced a monitor. Let's see Carmack do that shit at a mac conference. Yeah, that's right, he can't.... Because it's not been ported to the Mac, and requires DirectX. [oh]

However it struck me today how all my pain and anguish over the design of this thing has paid off. It was very simple to do this. "Of course it was" you just said (yes, I can read your mind thoughts, and I know about your animal porn). You said, "Of course it was simple you fucking gimp. You drew a shitty picture in MSPaint and displayed it." OH HO HO! NO! You fail. This was all generated by Gorgon using lines, ellipses, and points. Just like yonder GW-BASIC times of olde. And it even has a simple animation of expanding/contracting sun-spots that pop up every few seconds. All generated on the fly. Yeah, OK, NOW you can be unimpressed. But it was rediculously simple to set that all up, as an example app should be.

Here's the source so you can marvel [sick] at my skills.

/// /// Main application form./// 

public partial class MainForm
: Form
{
#region Variables.
private Random _rnd = new Random(); // Random number generator.
private RenderImage _backBuffer = null; // Back buffer.
private Sprite _backBlit = null; // Sprite to blit the backbuffer.
private float _halfWidth; // Half of screen width.
private float _halfHeight; // Half of screen height.
private float _xRadius = 0; // X-radius.
private float _yRadius = 0; // Y-radius.
private float _spotX = 0; // Sun-spot X.
private float _spotY = 0; // Sun-spot Y.
private bool _flipDir = false; // Flag to flip direction.
private bool _drawSpot = false; // Flag to draw a sun-spot.
private float _time = 0; // Time accumulator.
private float _maxTime = 0; // Maximum time for accumulator.
#endregion

#region Properties.
///
/// Property to return a random floating point number between 0..1.0f.
///
/// This is just for convenience.
private float RandomValue
{
get
{
return (float)_rnd.NextDouble();
}
}
#endregion

#region Methods.
///
/// Function to draw the pretty picture.
///
private void DrawAPrettyPicture()
{
Color paintColor; // Paint color.
float sin = 0.0f; // Sin.
float cos = 0.0f; // Cosine.
int colorSwitch = 0; // Color component for the points.

// Clear the back buffer.
_backBuffer.Clear();

// First we need to lock the render target down for our drawing. This ensures that the
// drawing commands are sent to the right buffer.
_backBuffer.BeginDrawing();

// Draw some points as stars.
for (int x = 0; x < 1000; x++)
{
// Color.
colorSwitch = _rnd.Next(160) + 95;

// Get the star color.
paintColor = Color.FromArgb(colorSwitch, colorSwitch, colorSwitch);

_backBuffer.SetPoint(RandomValue * _backBuffer.Width, RandomValue * _backBuffer.Height, paintColor);
}

// Set the blending mode so we can use translucent shapes.
_backBuffer.BlendingMode = BlendingModes.Normal;

// Draw lines.
for (int x = 0; x < 360; x++)
{
cos = MathUtility.Cos(x + x);
sin = MathUtility.Sin(x + x);

// Set up a random color.
paintColor = Color.FromArgb((byte)_rnd.Next(128) + 127, _rnd.Next(64) + 191, _rnd.Next(64) + 191, 0);
_backBuffer.Line(sin + _halfWidth, cos + _halfHeight, cos * (RandomValue * _halfWidth), sin * (RandomValue * _halfHeight), paintColor);
}

// Draw a filled circle.
_backBuffer.FilledCircle(_halfWidth, _halfHeight, (_halfHeight / 2.0f) + (_rnd.Next(10) - 8), Color.Yellow);

// Draw some circles in the filled circle.
for (int x = 0; x < 25; x++)
_backBuffer.Circle((RandomValue * (_halfHeight / 2.0f)) + _halfWidth - (_halfHeight / 4.0f),
(RandomValue * (_halfHeight / 2.0f)) + _halfHeight - (_halfHeight / 4.0f), RandomValue * 5.0f, Color.Black);

// Draw some black bars.
_backBuffer.FilledRectangle(0, 0, _backBuffer.Width, _backBuffer.Height / 6.0f, Color.Black);
_backBuffer.FilledRectangle(0, _backBuffer.Height - (_backBuffer.Height / 6.0f), _backBuffer.Width, _backBuffer.Height / 6.0f, Color.Black);

// Always call this when done.
_backBuffer.EndDrawing();
}

///
/// Handles the Idle event of the Gorgon control.
///
/// The source of the event.
/// The instance containing the event data.
private void Gorgon_Idle(object sender, FrameEventArgs e)
{
// Clear the main buffer.
Gorgon.Screen.Clear();

// Blit the backbuffer to the screen.
_backBlit.Draw();

// Set up to draw a sun spot.
if ((_time > _maxTime) && (!_drawSpot))
{
_drawSpot = true;
_flipDir = false;
_xRadius = 1.0f;
_yRadius = 1.0f;
_spotX = (RandomValue * (_halfHeight / 2.0f)) + _halfWidth - (_halfHeight / 4.0f);
_spotY = (RandomValue * (_halfHeight / 2.0f)) + _halfHeight - (_halfHeight / 4.0f);
_maxTime = (RandomValue * 6.0f) + 3.0f;
_time = 0;
}

if (_drawSpot)
{
// Grow/shrink the sun-spot.
if (!_flipDir)
{
_xRadius += (e.FrameDeltaTime) * (RandomValue * 4.025f);
_yRadius += (e.FrameDeltaTime) * (RandomValue * 3.025f);
}
else
{
_xRadius -= (e.FrameDeltaTime) * (RandomValue * 2.025f);
_yRadius -= (e.FrameDeltaTime) * (RandomValue * 3.025f);
}

// Don't let the spot go too large.
if ((_xRadius > (RandomValue * 15.0f) + 5.0f) || (_yRadius > (RandomValue * 15.0f) + 5.0f))
_flipDir = true;

// Once it's down beyond a visible range, then turn it off and wait until the accumulator is filled.
if ((_xRadius < 1.0f) || (_yRadius < 1.0f))
{
_drawSpot = false;
_xRadius = 1.0f;
_yRadius = 1.0f;
}

// Draw some stuff to the screen.
Gorgon.Screen.BeginDrawing();
Gorgon.Screen.BlendingMode = BlendingModes.Normal;
// Draw the sun-spot.
Gorgon.Screen.FilledEllipse(_spotX, _spotY, _xRadius, _yRadius, Color.FromArgb((byte)_rnd.Next(127) + 128, Color.Black));
// Draw the orangy blister.
Gorgon.Screen.Ellipse(_spotX, _spotY, _xRadius, _yRadius, Color.OrangeRed);
Gorgon.Screen.EndDrawing();
}
else
_time += e.FrameDeltaTime; // Add to accumulator.
}

///
/// Raises the event.
///
/// A that contains the event data.
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);

if (e.KeyCode == Keys.Escape)
Close();
if (e.KeyCode == Keys.S)
Gorgon.FrameStatsVisible = !Gorgon.FrameStatsVisible;
}

///
/// Raises the event.
///
/// A that contains the event data.
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);

// Perform clean up.
Gorgon.Terminate();
}

///
/// Raises the event.
///
/// An that contains the event data.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

try
{
// Initialize Gorgon
// Set it up so that we won't be rendering in the background, but allow the screensaver to activate.
Gorgon.Initialize(false, true);

// Display the logo.
Gorgon.LogoVisible = true;
Gorgon.FrameStatsVisible = false;

// Set a 512x512 video mode bound to the form client area.
ClientSize = new Size(512, 512);
Gorgon.SetMode(this);

// Create our backbuffer and blitter.
_backBuffer = Gorgon.RenderTargets.CreateRenderImage("BackBuffer", Gorgon.Screen.Width, Gorgon.Screen.Height);

// Set an ugly background color.
_backBuffer.BackgroundColor = Color.FromArgb(0,0,64);

// Get half width/height.
_halfWidth = _backBuffer.Width / 2.0f;
_halfHeight = _backBuffer.Height / 2.0f;

// Create the blitting sprite.
_backBlit = new Sprite("Blitter", _backBuffer);

// Assign idle event.
Gorgon.Idle += new FrameEventHandler(Gorgon_Idle);

// Assign a device reset event so our backbuffer will be resized.
Gorgon.DeviceReset += new EventHandler(Gorgon_DeviceReset);

// Draw the image.
DrawAPrettyPicture();

// Set up the maximum time for the time accumulator.
_maxTime = (RandomValue * 6.0f) + 3.0f;

// Begin rendering.
Gorgon.Go();
}
catch (SharpException sEx)
{
UI.ErrorBox(this, "Unable to initialize the application.", sEx.ErrorLog);
}
catch (Exception ex)
{
UI.ErrorBox(this, "Unable to initialize the application.", ex);
}
}

///
/// Handles the DeviceReset event of the Gorgon control.
///
/// The source of the event.
/// The instance containing the event data.
private void Gorgon_DeviceReset(object sender, EventArgs e)
{
// Update the backbuffer.
_backBuffer.SetDimensions(Gorgon.Screen.Width, Gorgon.Screen.Height);

// Change the blit size.
_backBlit.Width = Gorgon.Screen.Width;
_backBlit.Height = Gorgon.Screen.Height;

// Get half width/height.
_halfWidth = _backBuffer.Width / 2.0f;
_halfHeight = _backBuffer.Height / 2.0f;

// Turn off spot.
_drawSpot = false;

// Update the image.
DrawAPrettyPicture();
}
#endregion

#region Constructor.
///
/// Constructor.
///
public MainForm()
{
InitializeComponent();
}
#endregion
}




Nothing to it. A retarded monkey could get this. Hell even -I- understand it and we all know that I'm a few rungs below retarded monkeys on the evolutionary (or intelligently designed, for the simple minded) ladder.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Gorgon 3.2

10148 views

Gorgon v3.1.46.255

3341 views

Gorgon v3.1.45.248

2975 views

Gorgon v3.1.29.243

4258 views

Gorgon v3.1

4082 views

Gorgon Update #10

2982 views

Gorgon Update #9

3182 views

Gorgon Update #8

2924 views

Gorgon Update #7

3144 views

v3.0 Release

3705 views
Advertisement