Esempio n. 1
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;
}
Esempio n. 2
0
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;
}