Sge2d

Sge2d
Platform Cross-platform
Type Game engine
License MIT license
Website http://93i.de/cms/products/game-engines/sdl-game-engine/

Sge2d is an open source platform independent MIT licensed framework for programming 2d games in C/C++. It aims for low dependencies and easy portability. Its main focus is providing an easy API and providing features useful for commercial game development.

Since release 20110122 it is possible to use the library from C++

Example

The following example opens a window in the dimension 320×240, reads a bitmap font from an encrypted file and prints hello world limited to 30 frames per second.

#include <sge.h>
 
// struct to hold font data
typedef struct {
	SGEFONT *font;
} MainStateData;
 
// redraw function of current state
void on_redraw(SGEGAMESTATE *state) {
	// get state data
	SGEEVENTSTATE es = state->manager->event_state;
	MainStateData *data = (MainStateData*)state->data;
 
	// quit if return (or start on gp2x) is pressed
	if (es.start.released) {
		sgeGameStateManagerQuit(state->manager);
		return;
	}
 
	// clear screen and print hello world at 50/50
	sgeClearScreen();
	sgeFontPrintBitmap(data->font, screen, 50, 50, "Hello world");
 
	// finally display the screen
	sgeFlip();
}
 
// game entry point
int run(int argc, char *argv[]) {
	SGEGAMESTATEMANAGER *manager;
	SGEGAMESTATE *mainstate;
	MainStateData data;
	SGEFILE *f;
 
	// initialize engine and set up resolution and depth
	sgeInit(NOAUDIO,NOJOYSTICK);
	sgeOpenScreen("Wikipedia example",320,240,32,NOFULLSCREEN);
	sgeHideMouse();
 
	// load the font from our encrypted data file with secret password asdf
	f=sgeOpenFile("data.d","asdf");
	data.font=sgeFontNewFile(f, SGEFONT_BITMAP, "font.png");
	sgeCloseFile(f);
 
	// add a new game state with redraw function and data struct
	mainstate = sgeGameStateNew();
	mainstate->onRedraw = on_redraw;
	mainstate->data = &data;
 
	// initialize state manager with default state
	manager = sgeGameStateManagerNew();
	sgeGameStateManagerChange(manager, mainstate);
 
	// start the game running with 30 frames per seconds
	sgeGameStateManagerRun(manager, 30);
 
	// close the screen and quit
	sgeCloseScreen();
	return 0;
}

Requirements

See also

External links