Пример #1
0
static void
SDLGL_CaptureOutput(AG_DriverSDLGL *sgl)
{
	char path[AG_PATHNAME_MAX];
	AG_DriverSw *dsw = (AG_DriverSw *)sgl;
	AG_Surface *s;

	Snprintf(path, sizeof(path), sgl->outPath, sgl->outFrame);
	glReadPixels(0, 0, dsw->w, dsw->h, GL_RGBA, GL_UNSIGNED_BYTE,
	    sgl->outBuf);

	if (AG_PackedPixelFlip(sgl->outBuf, dsw->h, dsw->w*4) == -1) {
		goto fail_disable;
	}
	s = AG_SurfaceFromPixelsRGBA(sgl->outBuf,
	    dsw->w, dsw->h, 32,
	    0x000000ff, 0x0000ff00, 0x00ff0000, 0);
	if (s == NULL)
		goto fail;

	switch (sgl->outMode) {
	case AG_SDLGL_OUT_JPEG:
		if (AG_SurfaceExportJPEG(s, path) == -1) {
			goto fail;
		}
		break;
	case AG_SDLGL_OUT_PNG:
		if (AG_SurfaceExportPNG(s, path) == -1) {
			goto fail;
		}
		break;
	}

	if (++sgl->outFrame == sgl->outLast) {
		Verbose("Reached last frame; terminating\n");
		AG_Terminate(0);
	}
	AG_SurfaceFree(s);
	return;
fail:
	AG_SurfaceFree(s);
fail_disable:
	AG_Verbose("%s; disabling capture\n", AG_GetError());
	sgl->outMode = AG_SDLGL_OUT_NONE;
}
Пример #2
0
static int
SDLGL_OpenVideo(void *obj, Uint w, Uint h, int depth, Uint flags)
{
	char buf[16];
	AG_Driver *drv = obj;
	AG_DriverSw *dsw = obj;
	AG_DriverSDLGL *sgl = obj;
	Uint32 sFlags = SDL_OPENGL;
	int newDepth;

	/* Set the requested display options. */
	if (flags & AG_VIDEO_RESIZABLE) { sFlags |= SDL_RESIZABLE; }
	if (flags & AG_VIDEO_ANYFORMAT) { sFlags |= SDL_ANYFORMAT; }
	if (flags & AG_VIDEO_HWPALETTE) { sFlags |= SDL_HWPALETTE; }
	if (flags & AG_VIDEO_DOUBLEBUF) { sFlags |= SDL_DOUBLEBUF; }
	if (flags & AG_VIDEO_FULLSCREEN) { sFlags |= SDL_FULLSCREEN; }
	if (flags & AG_VIDEO_NOFRAME) { sFlags |= SDL_NOFRAME; }
	
	if (flags & AG_VIDEO_OVERLAY)
		dsw->flags |= AG_DRIVER_SW_OVERLAY;
	if (flags & AG_VIDEO_BGPOPUPMENU)
		dsw->flags |= AG_DRIVER_SW_BGPOPUP;

	/* Apply the output capture settings. */
	if (AG_Defined(drv, "out")) {
		char *ext;

		AG_GetString(drv, "out", buf, sizeof(buf));
		if ((ext = strrchr(buf, '.')) != NULL &&
		    ext[1] != '\0') {
			if (Strcasecmp(&ext[1], "jpeg") == 0 ||
			    Strcasecmp(&ext[1], "jpg") == 0) {
				sgl->outMode = AG_SDLGL_OUT_JPEG;
				if ((sgl->outPath = TryStrdup(buf)) == NULL)
					return (-1);
			} else if (Strcasecmp(&ext[1], "png") == 0) {
				sgl->outMode = AG_SDLGL_OUT_PNG;
				if ((sgl->outPath = TryStrdup(buf)) == NULL)
					return (-1);
			} else {
				AG_SetError("Invalid out= argument: `%s'", buf);
				return (-1);
			}
			if (AG_Defined(drv, "outFirst")) {
				AG_GetString(drv, "outFirst", buf, sizeof(buf));
				sgl->outFrame = atoi(buf);
			} else {
				sgl->outFrame = 0;
			}
			if (AG_Defined(drv, "outLast")) {
				AG_GetString(drv, "outLast", buf, sizeof(buf));
				sgl->outLast = atoi(buf);
			}
		}
	}
	
	/* Apply the default resolution settings. */
	if (w == 0 && AG_Defined(drv, "width")) {
		AG_GetString(drv, "width", buf, sizeof(buf));
		w = atoi(buf);
	}
	if (h == 0 && AG_Defined(drv, "height")) {
		AG_GetString(drv, "height", buf, sizeof(buf));
		h = atoi(buf);
	}
	if (depth == 0 && AG_Defined(drv, "depth")) {
		AG_GetString(drv, "depth", buf, sizeof(buf));
		depth = atoi(buf);
	}

	/* Set the video mode. Force hardware palette in 8bpp. */
	Verbose(_("SDLGL: Setting mode %dx%d (%d bpp)\n"), w, h, depth);
	newDepth = SDL_VideoModeOK(w, h, depth, sFlags);
	if (newDepth == 8) {
		Verbose(_("Enabling hardware palette"));
		sFlags |= SDL_HWPALETTE;
	}
	if ((sgl->s = SDL_SetVideoMode((int)w, (int)h, newDepth, sFlags))
	    == NULL) {
		AG_SetError("Setting %dx%dx%d mode: %s", w, h, newDepth,
		    SDL_GetError());
		return (-1);
	}
	SDL_EnableUNICODE(1);

	if ((drv->videoFmt = AG_SDL_GetPixelFormat(sgl->s)) == NULL) {
		goto fail;
	}
	dsw->w = sgl->s->w;
	dsw->h = sgl->s->h;
	dsw->depth = (Uint)drv->videoFmt->BitsPerPixel;

	Verbose(_("SDLGL: New display (%dbpp)\n"),
	     (int)drv->videoFmt->BitsPerPixel);
	
	/* Initialize clipping rectangles. */
	if (InitClipRects(sgl, dsw->w, dsw->h) == -1)
		goto fail;
	
	/* Create the cursors. */
	if (AG_SDL_InitDefaultCursor(sgl) == -1 ||
	    AG_InitStockCursors(drv) == -1)
		goto fail;

	/* Initialize the GL viewport. */
	AG_GL_InitContext(
	    AG_RECT(0, 0, AGDRIVER_SW(sgl)->w, AGDRIVER_SW(sgl)->h));

	if (!(dsw->flags & AG_DRIVER_SW_OVERLAY)) {
		ClearBackground();
	}

	/* Initialize the output capture buffer. */
	Free(sgl->outBuf);
	if ((sgl->outBuf = AG_TryMalloc(dsw->w*dsw->h*4)) == NULL) {
		AG_Verbose("Out of memory for buffer; disabling capture\n");
		sgl->outMode = AG_SDLGL_OUT_NONE;
	}

	/* Toggle fullscreen if requested. */
	if (AG_CfgBool("view.full-screen")) {
		if (!SDL_WM_ToggleFullScreen(sgl->s))
			AG_SetCfgBool("view.full-screen", 0);
	}
	return (0);
fail:
	if (drv->videoFmt) {
		AG_PixelFormatFree(drv->videoFmt);
		drv->videoFmt = NULL;
	}
	return (-1);
}
Пример #3
0
static void
UpdateFaces(AG_Event *event)
{
	AG_Variable *bFont;
	AG_Font **pFont;
	AG_FontSelector *fs = AG_SELF();
	char fontPath[AG_SEARCHPATH_MAX], *pFontPath = &fontPath[0];
	AG_TlistItem *ti;
	char *s;
	int i;
	const int stdSizes[] = { 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
	                         22,24,26,28,32,48,64 };
	const int nStdSizes = sizeof(stdSizes) / sizeof(stdSizes[0]);
	
	bFont = AG_GetVariable(fs, "font", &pFont);
	AG_PushTextState();

	fs->flags &= ~(AG_FONTSELECTOR_UPDATE);

	for (i = 0; i < agBuiltinFontCount; i++) {
		AG_StaticFont *font = agBuiltinFonts[i];

		ti = AG_TlistAdd(fs->tlFaces, NULL, "_%s", font->name);
		ti->p1 = font;
		if (*pFont != NULL &&
		    strcmp(ti->text, OBJECT(*pFont)->name) == 0)
			ti->selected++;
	}

	AG_CopyCfgString("font-path", fontPath, sizeof(fontPath));
	while ((s = AG_Strsep(&pFontPath, ":")) != NULL) {
		AG_Dir *dir;
		int i;

		if ((dir = AG_OpenDir(s)) == NULL) {
			AG_Verbose(_("Ignoring: %s\n"), AG_GetError());
			continue;
		}
		for (i = 0; i < dir->nents; i++) {
			char path[AG_FILENAME_MAX];
			AG_FileInfo info;
			char *file = dir->ents[i], *pExt;

			if (file[0] == '.' ||
			    (pExt = strrchr(file, '.')) == NULL) {
				continue;
			}
			if (strcmp(pExt, ".ttf") != 0 &&
			    strcmp(pExt, ".TTF") != 0)
				continue;

			Strlcpy(path, s, sizeof(path));
			Strlcat(path, AG_PATHSEP, sizeof(path));
			Strlcat(path, file, sizeof(path));

			if (AG_GetFileInfo(path, &info) == -1 ||
			    info.type != AG_FILE_REGULAR) {
				continue;
			}
			ti = AG_TlistAddS(fs->tlFaces, NULL, file);
			if (*pFont != NULL &&
			    strcmp(file, OBJECT(*pFont)->name) == 0)
				ti->selected++;
		}
		AG_CloseDir(dir);
	}

	/* XXX */
	for (i = 0; i < nStdSizes; i++) {
		ti = AG_TlistAdd(fs->tlSizes, NULL, "%d", stdSizes[i]);
		if (*pFont != NULL &&
		    stdSizes[i] == (*pFont)->size)
			ti->selected++;
	}
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Regular"));
	if (*pFont != NULL && (*pFont)->flags == 0) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Italic"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_ITALIC) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_BOLD) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold Italic"));
	if (*pFont != NULL && (*pFont)->flags == (AG_FONT_BOLD|AG_FONT_ITALIC)) { ti->selected++; }

	UpdatePreview(fs);

	AG_UnlockVariable(bFont);
}