I've been working on a game engine using SDL & OpenGL since yesterday and it's gotten to the first milestone (opening a window and handling events). I wanted to learn OpenGL and I thought a good way of doing that would be to write a game engine that uses it. I picked SDL because I've been kind of nostalgic about it recently (I don't know why). So my game engine is in C now.
What do you think? Does it look useful? Easy to use? etc. (please be honest).
The API is supposed to somewhat resemble OpenGL immediate mode, and I'm trying to make it possible to use it with a minimum of code.
Here's an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <SGE/SGE.h>
int main()
{
sgeInit();
sgeSetVideoMode(640, 480, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
sgeSetEventMode(SGE_POLLING);
int running = 1;
while (running) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = 0;
break;
}
}
}
sgeQuit();
return 0;
}
|
You might notice the line
sgeSetEventMode(SGE_POLLING)
. I don't like libraries that force you to use callback functions for event handling, because I prefer to poll for events myself. But I think some people probably prefer callbacks. For that reason, my game engine lets you pick by setting the "event (handling) mode" to SGE_CALLBACKS or SGE_POLLING. Although it's a very small thing, I thought it was a cool idea.
I think I'm about 1% of the way into writing it, since currently it's just a (partial) wrapper around SDL (I'm intentionally not wrapping SDL entirely, that would be kind of pointless). I need to finish writing the lower level stuff so I can build the higher level parts on top.
Edit: I put it on GitHub:
https://github.com/ChrisSwinchatt/SGE
Event callbacks & a screen refresh function are available now. It's still just an SDL wrapper but I'm very happy with what I've written so far.