Esempio n. 1
0
int update()
{
    if (get_active_screen() == NULL)
    {
        return 1;
    }

    timestamp_t current = {0};
    timestamp_set(&current);
    long dt = timestamp_diff(&current, &timer);
    if (dt > 0)
    {
        timer = current;
        screen_update(dt);
    }

    long fps_dt = timestamp_diff(&current, &fps_timer);
    LOGD("DT: %ld", fps_dt);
    if (fps_dt > 500)
    {
        fps = frames * 1000.0f / (float)fps_dt;
        fps_timer = current;
        frames = 0;
        LOGI("FPS: %.2f", fps);
    }
    else
    {
        ++frames;
    }

    char fps_str[32] = {0};
    sprintf(fps_str, "FPS: %.2f", fps);

    const rect_t fps_rect = { 8.0f, 8.0f, 256.0f, 32.0f };
    const rgba_t fps_color = { 1.0f, 0.0f, 0.0f, 0.8f };

    mat4f_t transform = {0};
    mat4_mult(&transform, &camera.proj, &camera.view);

    rect_t screen = { 0, 0, screen_size.x, screen_size.y };

    rgba_t color = {0.7f, 0.7f, 0.0f, 1.0f };

    gfx_set_target(gfx, "test_target", &screen);
    gfx_enable_depth_buffer(gfx, 1);

    gfx_clear(gfx);
    screen_render(gfx, &camera);
    gfx_set_shader(gfx, "text");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    draw_text(fps_str, &fps_rect, 0.0f, 4.9f, &fps_color);
    gfx_flush(gfx);

    static int take_screenshot = 0;
    if (take_screenshot && frames == 0)
    {
        take_screenshot = 0;

        image_t* img = NULL;
        if (gfx_take_screenshot(gfx, &img) == 0)
        {
            image_save_to_png(img, "screenshot.png");
            image_free(img);
        }
    }

    gfx_set_target(gfx, NULL, &screen);
    gfx_enable_depth_buffer(gfx, 0);
    gfx_clear(gfx);

    int32_t sampler = 0;
    rect_t uv = { 0, screen.height/buffer_size.y, screen.width/buffer_size.x, -screen.height/buffer_size.y };

    gfx_set_shader(gfx, "postprocess");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    gfx_set_uniform_1i(gfx, "uTex", 1, &sampler);
    gfx_set_texture(gfx, "test_texture", sampler);
    gfx_render_textured_rect(gfx, &screen, 1.0f, &uv);
    gfx_set_texture(gfx, NULL, sampler);

    gfx_flush(gfx);

    return 0;
}
Esempio n. 2
0
static void
set_user_icon_from_png (char *path, uint32_t bgcolor)
{
	int j, alpha;
	image_s *img = image_new_from_png (path, 1, NULL, 0, 1, 0, &alpha);
	image_s *img_sm, *img_lrg;
	struct icon_struct newicons;
	double n, scale_lrg, scale_sm;

	if (img == (image_s *)NULL)
	{
		DPRINTF (E_WARN, L_GENERAL,
				"Unable to load icon file \"%s\".\n", path);
		return;
	}

	n = (img->height > img->width) ? img->height : img->width;
	scale_lrg = 120.0 / n;
	scale_sm = 48.0 / n;

	if ((img_lrg = image_resize (img,
					xround (img->width*scale_lrg),
					xround(img->height*scale_lrg))) == (image_s *)NULL)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to rescale large icon image (%s).\n", path);
		image_free (img);
		return;
	}

	if ((img_sm = image_resize (img,
					xround(img->width*scale_sm),
					xround(img->height*scale_sm))) == (image_s *)NULL)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to rescale small icon image (%s).\n", path);
		image_free (img);
		image_free (img_lrg);
		return;
	}

	image_free (img);

	for (j = ICON_FIRST; j <= ICON_LAST; j++)
		newicons.dynamic[j] = 1;

	if ((newicons.size[ICON_PNG_LRG] = image_save_to_png (img_lrg, NULL,
			&newicons.icon[ICON_PNG_LRG], alpha, 9)) < 0)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create large PNG icon (%s).\n", path);
		newicons.icon[ICON_PNG_LRG] = icons.icon[ICON_PNG_LRG];
		newicons.size[ICON_PNG_LRG] = icons.size[ICON_PNG_LRG];
		newicons.dynamic[ICON_PNG_LRG] = icons.dynamic[ICON_PNG_LRG];
	}

	if ((newicons.size[ICON_PNG_SM] = image_save_to_png (img_sm, NULL,
			&newicons.icon[ICON_PNG_SM], alpha, 9)) < 0)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create small PNG icon (%s).\n", path);
		newicons.icon[ICON_PNG_SM] = icons.icon[ICON_PNG_SM];
		newicons.size[ICON_PNG_SM] = icons.size[ICON_PNG_SM];
		newicons.dynamic[ICON_PNG_SM] = icons.dynamic[ICON_PNG_SM];
	}

	if (alpha)
	{
		image_bgcolor_composite (img_lrg, bgcolor, -1);
		image_bgcolor_composite (img_sm, bgcolor, -1);
	}

	if (!(newicons.icon[ICON_JPEG_LRG] = image_save_to_jpeg_buf (img_lrg,
			&newicons.size[ICON_JPEG_LRG])))
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create large JPEG icon (%s).\n", path);
		newicons.icon[ICON_JPEG_LRG] = icons.icon[ICON_JPEG_LRG];
		newicons.size[ICON_JPEG_LRG] = icons.size[ICON_JPEG_LRG];
		newicons.dynamic[ICON_JPEG_LRG] = icons.dynamic[ICON_JPEG_LRG];
	}

	if (!(newicons.icon[ICON_JPEG_SM] = image_save_to_jpeg_buf (img_sm,
			&newicons.size[ICON_JPEG_SM])))
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create small JPEG icon (%s).\n", path);
		newicons.icon[ICON_JPEG_SM] = icons.icon[ICON_JPEG_SM];
		newicons.size[ICON_JPEG_SM] = icons.size[ICON_JPEG_SM];
		newicons.dynamic[ICON_JPEG_SM] = icons.dynamic[ICON_JPEG_SM];
	}

	image_free (img_sm);
	image_free (img_lrg);
	destroy_icons (&icons);
	icons = newicons;
}