• entries
3
6
• views
5373

## SDL / GLUT

I've recently started looking at OpenGL. To some extent I feel hesitant. The 3D world seems too vast for a "one man show". Nevertheless I've decided to look at a small subset of OpenGL capabilities, specifically rendering 2D primitives. I feel that OpenGL has some nice features built in already to perform some imaging magic. Overlays, blending, anti aliasing and translucency to mention a few. I'm hoping to find nice support for SVG in OpenGL, this will mean that I should be able to create resolution independent backgrounds ... which really beats standard images.

As for using OpenGL in an application (specifically a game) I've started looking at two technologies:
- SDL (http://www.libsdl.org/)
- GLUT (http://www.opengl.org/resources/libraries/glut/)

First off GLUT is a really nice tool to get an OpenGL sample up and running quickly, but that's about where it ends as far as I can see. SDL on the other hand integrates easily into OpenGL and takes over all the windowing stuff you need, but also adds everything else. That is timing, game loop, networking, better / easier event handling for keyboard and mouse ... and more.

That's about as far as I got, now to do some more reading -O-o-

## Software Engineer or Over Engineer?

I'm trying extremely hard not to over engineer anything. In fact I'm trying hard not to dive right into OOP. When I first started out developing, I picked up some game dev books and immediately tried to create my own - not so much improved - version of what the book already had. I couldn't understand why there weren't any C++ samples, mostly the beginner books did C. I now realise these guys were smart. If they had to do everything OOP they would have never finished the book ...

I have never written a game, but I've made an amazing amount of class hierarchies resembling names of Game Engine Entities, these entities looked pretty good on file. Unfortunately they never made it all the way to any type of output device ... well, maybe stdout ... or should I say cout.

The point is, if I don't get off this "plan till perfection" train now I fear that I may never see more than a blit on screen.

Wish me luck

## Fancy Cursor

I'm busy playing around with fancy cursers, i.e. hiding the default cursor and rendering one on a surface.

Here are some top level ideas that I think can be useful in making interesting cursors:
- Keep a ring buffer of the last x mouse motion events
- Use the events from the ring buffer during render time to create some type of sweeping effect of the mouse

SDL Sample (High Level):
-----------------------------------
#define MAX_MOTIONS 12SDL_MouseMotionEvent motions[MAX_MOTIONS];int last_motion = 0;int lap = 0; // have we gone around at least once?voidhandle_motion(SDL_MouseMotionEvent *e){ /* Amazingly complex ring buffer impl. */ if (last_motion > MAX_MOTIONS - 1) { lap = 1; last_motion = 0; } /* if */ motions[last_motion] = e->motion; last_motion++;}voidupdate_graphics(void){ int i; int end = lap ? MAX_MOTIONS : last_motion; /* Scale end to relative motion - good idea, bad idea? */ for (i = 0; i < end; i++) { SDL_MouseMotionEvent m = motions; putpixel(screen, m.x, m.y, color); } /* for */}
--

Its times like these that things just don't look as good as they should.