コード例 #1
0
ファイル: gradient.c プロジェクト: tinyserver/siege
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;
}
コード例 #2
0
ファイル: coldet.c プロジェクト: tinyserver/siege
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;
}
コード例 #3
0
ファイル: atlas.c プロジェクト: SIEGE/siege
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;
}
コード例 #4
0
ファイル: main_step3.c プロジェクト: SIEGE/siege
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;
}
コード例 #5
0
ファイル: physics.c プロジェクト: tinyserver/siege
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;
}