The following example demonstrates how to use TinySGGL-0.7 together with SDL.
#include <stdlib.h>
#include <SDL.h>
#include <tSGGL/SGGL.h>
int main()
{
SDL_Surface *surface;
gfx_image_t *image;
gfx_color_t color;
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) return -1;
atexit(SDL_Quit);
/* Open a 16bit 640x480 output window/screen using SDL */
surface = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if (!surface) return -2;
/* Create an SGGL surface whose data doesn't point anywhere yet */
image = gfx_create_null_image(640, 480);
if (!image) return -3;
/* Redirect the image's data to the one of surface's */
image->data = (PM_Uint16 *) surface->pixels;
/* Now we have an image ready to draw to */
if (SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
gfx_set_color(&color, 255, 16, 16); /* Red */
/* Draw a line from upper-left corner to lower-right */
gfx_line(0, 0, image->max_x, image->max_y, &color, image);
if (SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
/* Make the line visible */
SDL_Flip(surface);
/* Wait 5 seconds before quitting */
SDL_Delay(5000);
free(image);
return 0;
}