コード例 #1
0
ファイル: gfx.c プロジェクト: allen7575/gravit
int gfxInit() {

    int detectedBPP;
    SDL_Surface *icon;
    int ret;
    char *fileName;

    if (SDL_Init(SDL_INIT_VIDEO)) {

        conAdd(LERR, "SDL Init failed");
        conAdd(LERR, SDL_GetError());
        sdlCheck();
        return 0;

    }

    if (TTF_Init()) {

        conAdd(LERR, "SDL_ttf Init failed");
        conAdd(LERR, SDL_GetError());
        sdlCheck();
        return 0;

    }

    video.sdlStarted = 1;

    fileName = findFile(MISCDIR "/gravit.png");
    if (!fileName) {
        return 0;
    }
    icon = IMG_Load(fileName);
    if (!icon) {
        sdlCheck();
    }
    SDL_WM_SetIcon(icon, NULL);
    SDL_FreeSurface(icon);

    setTitle(0);

    video.gfxInfo = (SDL_VideoInfo*) SDL_GetVideoInfo();
    detectedBPP = video.gfxInfo->vfmt->BitsPerPixel;

    conAdd(LLOW, "Detected %i BPP", detectedBPP);

gfxInitRetry:

    if (video.screenBPP == 0)
        video.screenBPP = detectedBPP;

    ret = gfxSetResolution();
    if (ret) {

        if (ret == 1) {

            if (video.screenAA) {
                conAdd(LERR, "You have videoantialiasing on. I'm turning it off and restarting...");
                video.screenAA = 0;
                goto gfxInitRetry;
            }

            if (detectedBPP != video.screenBPP) {
                conAdd(LERR, "Your BPP setting is different to your desktop BPP. I'm restarting with your desktop BPP...");
                video.screenBPP = detectedBPP;
                goto gfxInitRetry;
            }

        }

        return 0;

    }

    conAdd(LLOW, "Your video mode is %ix%ix%i", video.screenW, video.screenH, video.gfxInfo->vfmt->BitsPerPixel );

    if (!video.screenAA && view.particleRenderMode == 1) {
        conAdd(LERR, "Warning! You don't have videoantialiasing set to 1. From what I've seen so far");
        conAdd(LERR, "this might cause particlerendermode 1 not to work. If you don't see any particles");
        conAdd(LERR, "after spawning, hit the \\ (backslash) key).");
    }

    glClearColor(0, 0, 0, 0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_LINE_SMOOTH);
    glDisable(GL_DEPTH_TEST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glCheck();

    checkPointParameters();
    checkPointSprite();

    checkDriverBlacklist();

    SDL_ShowCursor(view.showCursor);
    SDL_EnableUNICODE(SDL_ENABLE);
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);

#ifndef WITHOUT_AGAR
    AG_InitCore("gravit", 0);
    //AG_InitGraphics("sdlgl");
    if (AG_InitVideoSDL(video.sdlScreen, AG_VIDEO_OVERLAY | AG_VIDEO_OPENGL_OR_SDL) == -1)
        conAdd(LERR, "agar error while initializing main window: %s", AG_GetError() );

    video.agarStarted = 1;

    if (!view.screenSaver)
        osdInitDefaultWindows();
#endif
    
    return 1;

}
コード例 #2
0
ファイル: sdl.c プロジェクト: adsr/agar
int
main(int argc, char *argv[])
{
#ifdef HAVE_SDL
	AG_Window *win;
	SDL_Surface *screen, *bmp, *tex1, *tex2, *avatar;
	AG_Surface *agbmp, *agavatar;
	int c, useGL = 0;
	Uint32 sdlFlags = 0;
	char *optArg;
	Uint32 rmask, gmask, bmask, amask;

	if (AG_InitCore("agar-sdl-demo", 0) == -1) {
		fprintf(stderr, "AG_InitCore: %s\n", AG_GetError());
		goto fail;
	}
	while ((c = AG_Getopt(argc, argv, "?g", &optArg, NULL)) != -1) {
		switch (c) {
		case 'g':
			useGL = 1;
			break;
		default:
			printf("Usage: %s [-g]\n", agProgName);
			break;
		}
	}

	/* Set up SDL */
	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
		fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
		return (1);
	}
	if (useGL) {
		sdlFlags = SDL_RESIZABLE|SDL_OPENGL;
	} else {
		sdlFlags = SDL_RESIZABLE|SDL_SWSURFACE;
	}
	if ((screen = SDL_SetVideoMode(320, 240, 32, sdlFlags)) == NULL) {
		fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
		goto fail;
	}

	if (useGL) {
		/* Set up OpenGL viewport and projection. */
		AG_GL_InitContext(AG_RECT(0,0,320,240));
	}

	/* Initialize Agar-GUI to reuse display */
	if (AG_InitVideoSDL(screen, 0) == -1) {
		fprintf(stderr, "%s\n", AG_GetError());
		AG_Destroy();
		goto fail;
	}
	AG_BindGlobalKey(AG_KEY_ESCAPE, AG_KEYMOD_ANY, AG_QuitGUI);

	/* Display some test widgets. */
	win = AG_WindowNew(AG_WINDOW_PLAIN);
	AG_LabelNew(win, 0, "Attached to existing %s display",
	    useGL ? "SDL/OpenGL" : "SDL");

	/* Test conversion from SDL_Surface to AG_Surface. */
	if ((bmp = SDL_LoadBMP("agar.bmp")) != NULL) {
		if ((agbmp = AG_SurfaceFromSDL(bmp)) != NULL) {
			AG_PixmapFromSurface(win, 0, agbmp);
		} else {
			AG_LabelNewS(win, 0, AG_GetError());
		}
	}
#ifdef HAVE_SDL_IMAGE
	if ((tex1 = IMG_Load("test1.png")) == NULL ||
	    (tex2 = IMG_Load("test2.png")) == NULL) {
		fprintf(stderr, "IMG_Load() failed\n");
		goto fail;
	}
# if SDL_BYTEORDER == SDL_BIG_ENDIAN
        rmask = 0xff000000;
        gmask = 0x00ff0000;
        bmask = 0x0000ff00;
        amask = 0x000000ff;
# else
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0xff000000;
# endif
	avatar = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 64, 128,
                tex1->format->BitsPerPixel, rmask, gmask, bmask, amask);
	SDL_SetAlpha(tex1, 0, 0);
        SDL_BlitSurface(tex1, NULL, avatar, NULL);
	SDL_SetAlpha(tex2, SDL_SRCALPHA, 0);
        SDL_BlitSurface(tex2, NULL, avatar, NULL);
	if ((agavatar = AG_SurfaceFromSDL(avatar)) != NULL) {
		AG_PixmapFromSurface(win, 0, agavatar);
	} else {
		AG_LabelNewS(win, 0, AG_GetError());
	}
#endif /* HAVE_SDL_IMAGE */

	AG_WindowShow(win);

	AG_EventLoop();
	AG_Destroy();

	SDL_Quit();
	return (0);
fail:
	SDL_Quit();
	return (1);
#else
	fprintf(stderr, "Agar was compiled without SDL support\n");
	return (1);
#endif /* HAVE_SDL */
}