int main(void) { sgLoadModule("SDL"); sgLoadModule("OpenGL"); sgInit(0); sgWindowOpen(640, 480, 32, 0); sgWindowSetTitle("SIEGE Gradient Demo"); SGGradient* grad = sgGradientCreate(); sgGradientSetStopKey(grad, 0.00, 1.0); sgGradientSetStopKey(grad, 0.25, 0.5); sgGradientSetStopKey(grad, 0.30, 0.0); sgGradientSetStopKey(grad, 0.50, 1.0); sgGradientSetStopKey(grad, 0.70, 1.0); sgGradientSetStopKey(grad, 0.75, 0.5); sgGradientSetStopKey(grad, 1.00, 1.0); size_t i; while(sgLoop(NULL)) { for(i = 0; i < 640; i += STEP) { grad->interp = _sgGradientInterpNearest; sgDrawColor2f(1.0, sgGradientGetValue(grad, i / (640.0 - STEP))); sgDrawRectangleWH(i, 480 / 4 * 0, STEP, 480 / 4, SG_TRUE); grad->interp = _sgGradientInterpLinear; sgDrawColor2f(1.0, sgGradientGetValue(grad, i / (640.0 - STEP))); sgDrawRectangleWH(i, 480 / 4 * 1, STEP, 480 / 4, SG_TRUE); grad->interp = _sgGradientInterpCosine; sgDrawColor2f(1.0, sgGradientGetValue(grad, i / (640.0 - STEP))); sgDrawRectangleWH(i, 480 / 4 * 2, STEP, 480 / 4, SG_TRUE); grad->interp = _sgGradientInterpCubic; sgDrawColor2f(1.0, sgGradientGetValue(grad, i / (640.0 - STEP))); sgDrawRectangleWH(i, 480 / 4 * 3, STEP, 480 / 4, SG_TRUE); } sgDrawColor4f(1.0, 0.75, 0.0, 0.25); for(i = 0; i < grad->numvals; i++) sgDrawLine(grad->vals[i].x * 640, 0, grad->vals[i].x * 640, 480); sgWindowSwapBuffers(); sgDrawClear(); } sgGradientDestroy(grad); sgDeinit(); return 0; }
int main(void) { sgLoadModule("SDL"); sgLoadModule("OpenGL"); sgLoadModule("STB-Image"); sgInit(0); sgWindowOpen(640, 480, 32, 0); sgWindowSetTitle("SIEGE Collision Detection Example"); SGSprite* pacman = sgSpriteCreateFile("data/sprites/Pacman.png"); SGMask* pacmanm = sgMaskCreateSprite(pacman); SGSprite* support = sgSpriteCreateFile("data/sprites/SupportBar.png"); SGMask* supportm = sgMaskCreateSprite(support); SGint mx, my; while(sgLoop(NULL)) { sgMouseGetPos(&mx, &my); mx -= mx % 2; my -= my % 2; sgDrawColor4f(1.0, 1.0, 1.0, 1.0); if(sgMaskCheckCollision(supportm, 320, 240, pacmanm, mx, my)) sgDrawColor4f(1.0, 0.0, 0.0, 1.0); //sgMaskDrawDBG(supportm, 320, 240, SG_TRUE); //sgMaskDrawDBG(pacmanm, mx, my, SG_TRUE); sgSpriteDraw2f(support, 320, 240); sgSpriteDraw2f(pacman, mx, my); sgDrawColor4f(1.0, 1.0, 1.0, 1.0); sgMaskDrawDBG(supportm, 480, 360, SG_TRUE); sgMaskDrawDBG(pacmanm, 544, 360, SG_TRUE); sgWindowSwapBuffers(); sgDrawClear(); } sgMaskDestroy(supportm); sgSpriteDestroy(support); sgMaskDestroy(pacmanm); sgSpriteDestroy(pacman); sgDeinit(); return 0; }
int main(void) { sgInit(0); sgWindowOpen(WIDTH, HEIGHT, 32, 0); sgWindowSetTitle("SIEGE Atlas Demo"); SGAtlas* atlas = sgAtlasCreate(ASIZE, ASIZE, 32); SGAtlasArea* area; size_t i; size_t num = 0; for(i = 0; i < NUMTEST; i++) { area = sgAtlasAreaReserve(atlas, BORDER + 12 + rand() % 5, BORDER + 12 + rand() % 5, SG_FALSE); if(area) { fillArea(atlas, area); num++; } } printf("Successfully inserted: %u/%u items\n", (unsigned int)num, NUMTEST); while(sgLoop(NULL)) { sgDrawColor1f(1.0); sgAtlasDrawDBG(atlas, (WIDTH - ASIZE) / 2, (HEIGHT - ASIZE) / 2, 0, SG_FALSE); sgDrawColor3f(0.0, 1.0, 0.0); sgAtlasDrawDBG(atlas, (WIDTH - ASIZE) / 2, (HEIGHT - ASIZE) / 2, 0, SG_TRUE); sgWindowSwapBuffers(); sgDrawClear(); } sgAtlasDestroy(atlas); sgDeinit(); return 0; }
int main() { sgLoadModule("SDL"); sgLoadModule("OpenGL"); sgLoadModule("Freetype"); sgInit(0); sgWindowOpen(640, 480, 32, 0); SGFont* font = sgFontCreate("data/fonts/DejaVuLGCSans.ttf", 24.0, 127); SGint ret; while(sgLoop(&ret)) { sgFontPrintCentered(font, sgWindowGetWidth() / 2, sgWindowGetHeight() / 2, "hello, world"); sgWindowSwapBuffers(); sgDrawClear(); } sgFontDestroy(font); sgDeinit(); return ret; }
int main(void) { sgLoadModule("SDL"); sgLoadModule("OpenGL"); sgLoadModule("STB-Image"); sgLoadModule("Chipmunk"); sgLoadModule("STB-TrueType"); sgInit(0); sgWindowOpen(640, 480, 32, 0); sgWindowSetTitle("SIEGE Physics Demo - Press F1 for debug overlay"); sgWindowSetFPSLimit(60.0f); space = sgPhysicsSpaceGetDefault(); sgPhysicsSpaceSetIterations(space, 10); sgPhysicsSpaceSetDamping(space, 0.75); sgPhysicsSpaceSetGravity(space, 0.0, 25.0); sprCrateSmall = sgSpriteCreateFile("data/sprites/CrateSmall.png"); sprFloorMetalPlate = sgSpriteCreateFile("data/sprites/FloorMetalPlate.png"); sprHazardWall = sgSpriteCreateFile("data/sprites/HazardWall.png"); sprPacman = sgSpriteCreateFile("data/sprites/Pacman.png"); sprStrongboxSmall = sgSpriteCreateFile("data/sprites/StrongboxSmall.png"); sprSupportBar = sgSpriteCreateFile("data/sprites/SupportBar.png"); SGFont* font = sgFontCreate("data/fonts/DejaVuSans.ttf", 7.0, 0, 127); SGuint i; for(i = 32; i < 640; i += 64) createFloor(sprFloorMetalPlate, i, 448); for(i = 224; i < 448; i += 64) createFloor(sprSupportBar, i, 384); for(i = 224; i < 448; i += 64) createFloor(sprHazardWall, i, 320); controller = sgEntityCreate(); controller->evMouseButtonLeftPress = evMouseButtonLeftPress; controller->evMouseButtonRightPress = evMouseButtonRightPress; controller->evKeyboardKeyPress = evKeyboardKeyPress; controller->evKeyboardKeyRepeat = evKeyboardKeyRepeat; SGlong accum = SG_NANOSECONDS_IN_A_SECOND, origin = sgGetTime(); SGfloat fps = 0.0; while(sgLoop(NULL)) { accum += sgGetTime() - origin; if(overlay) for(i = 0; i < numboxes; i++) boxDrawDBG(boxes[i]); if(accum >= SG_NANOSECONDS_IN_A_SECOND) { accum = 0; origin = sgGetTime(); fps = sgWindowGetFPS(); } sgFontPrintf(font, 1.0, 10.0, "FPS: %.2f", fps); sgWindowSwapBuffers(); sgDrawClear(); } sgSpriteDestroy(sprCrateSmall); sgSpriteDestroy(sprFloorMetalPlate); sgSpriteDestroy(sprHazardWall); sgSpriteDestroy(sprPacman); sgSpriteDestroy(sprStrongboxSmall); sgSpriteDestroy(sprSupportBar); sgFontDestroy(font); sgDeinit(); free(boxes); return 0; }
/* -------------------------------------------------------------------------- * * Client Initialisation * * -------------------------------------------------------------------------- */ void client_init(void) { int i; SDL_RWops *rwops; const sgVersion *sgver; const SDL_version *sdlver; client_log(STATUS, "Starte "PACKAGE" v"VERSION"..."); /* GUI Library initialisieren */ sgver = sgLinkedVersion(); client_log(STATUS, "Initialisiere sgUI v%u.%u.%u", sgver->major, sgver->minor, sgver->patch); sgInit(); /* Such-Pfade adden... Alle Dateien des Tichu-Clients werden über die libsgui geöffnet Auf windows starten wir immer aus dem Programm-Verzeichnis, wir müssen also nur unsere Unterverzeichnisse kennen: */ sgAddFilePath("data"); sgAddFilePath("sounds"); sgAddFilePath("images"); /* Auf *NIXes wird immer an einen festen Pfad installiert: */ #ifdef DATADIR sgAddFilePath(DATADIR "/data"); sgAddFilePath(DATADIR "/sounds"); sgAddFilePath(DATADIR "/images"); #endif /* Vielleicht sollten wir die folgenden Pfade nur für debug-builds absuchen (#ifdef DEBUG) */ sgAddFilePath("client/data"); sgAddFilePath("client/sounds"); sgAddFilePath("client/images"); sgAddFilePath("tichu/client/data"); sgAddFilePath("tichu/client/sounds"); sgAddFilePath("tichu/client/images"); sgAddFilePath("../data"); sgAddFilePath("../sounds"); sgAddFilePath("../images"); client_path = sgGetFilePath(); /* cursors themes laden */ sgOpenCursorThemes(); /* Konfigurationsdatei öffnen */ client_ini = ini_open(CLIENT_INI, INI_READ); #ifdef DEBUG ini_dump(client_ini); #endif /* DEBUG */ if(!client_ini) client_log(ERROR, "Fehler beim Öffnen der Konfigurationsdatei %s!", CLIENT_INI); /* SDL Initialisation */ sdlver = SDL_Linked_Version(); client_log(STATUS, "Initialisiere SDL v%u.%u.%u", sdlver->major, sdlver->minor, sdlver->patch); if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE)) client_log(ERROR, "Kann SDL nicht initialisieren!"); client_subsystems = SDL_WasInit(SDL_INIT_EVERYTHING); client_getmodes(); client_configure(); #if MDEBUG_ENABLE mdebug_init(); #endif /* MDEBUG_ENABLE */ /* Netzwerk initialisieren */ net_init(); /* Module welche auf SDL basieren initialisieren */ sound_init(); // card_init("data/cards.ini", "data/cards-alpha.png"); /* net read/error funktionen */ net_register(NET_READ, client_event); net_register(NET_ERROR, client_event); #ifdef WIN32 /* Im Windows-Taskbar sieht ein 32x32 Icon am besten aus */ client_load_icon("dragon-32.png"); #else /* Unter Fluxbox und XFCE macht sich ein 16x16 Icon am Besten :P * * Oooops, unter der neuen Fluxbox mit all dem Antialias Gewixe * aber nicht, dort wäre auch ein 32x32 angebracht. * * Aber wie finden wir raus welchen WM wir runnen auf X11? * Naja, vorerst einmal scheissegal :P */ client_load_icon("dragon-16.png"); #endif /* WIN32 */ /* Window-Manager Titel setzen */ SDL_WM_SetCaption("Tichu SDL Client v"VERSION, NULL); /* Fonts laden und der GUI übergeben */ for(i = 0; i < 3; i++) { rwops = client_open_rwops(client_config.font[i], CLIENT_READ); client_font[i] = sgLoadFontRWops(rwops); } /* Einen Puffer für die Kommandozeile und Chatkonsole reservieren */ client_buffer = strdup(client_ascii); if(sound_status & SOUND_AVAIL) { sound_configure(client_ini); /* Soundeffekte laden */ ui_loadsounds(); /* Soundtracks laden */ sound_mus_scan(); if(sound_playlist.head) sound_mus_play((struct sound_mus *)sound_playlist.head); } /* Kartendaten laden */ card_configure(client_ini); card_init(); /* Fächerkonfiguration laden */ fan_configure(client_ini); }