4258214e50
This test tried to do too much, and I can't remember the last time I saw this test work. It no longer tries to create a texture from an offscreen actor and it no longer tries to use shaders. It does though show that chaining of clutter_texture_new_from_actor now works, and that animating the source actor is reflected in textures created from it. When run you should see three actors: - on the left is the pristine source actor rotating around the y-axis - in the middle is the first texture created from the source actor - and on the right a texture created from the middle actor Note: the somewhat strange bobbing of the middle and right textures is actually correct given how it was decided long ago to map the transformed (to screen space) allocation of the source actor to the texture. When the hand spins around the perspective projection of the top of the hand results in the origin of the texture bobbing up to a higher stage position, but the position of the textures is fixed. This design also means we end up reallocating our offscreen draw buffer every frame that the actors transformed size changes, which isn't ideal.
95 lines
2.7 KiB
C
95 lines
2.7 KiB
C
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <glib.h>
|
|
#include <gmodule.h>
|
|
|
|
#define STAGE_WIDTH 800
|
|
#define STAGE_HEIGHT 600
|
|
|
|
ClutterActor *
|
|
make_source (void)
|
|
{
|
|
ClutterActor *source, *actor;
|
|
GError *error = NULL;
|
|
|
|
ClutterColor yellow = {0xff, 0xff, 0x00, 0xff};
|
|
|
|
source = clutter_group_new();
|
|
actor = clutter_texture_new_from_file ("redhand.png", &error);
|
|
if (!actor)
|
|
g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
|
|
|
|
clutter_group_add (source, actor);
|
|
|
|
actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
|
|
|
|
clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
|
|
clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
|
|
clutter_group_add (source, actor);
|
|
|
|
return source;
|
|
}
|
|
|
|
G_MODULE_EXPORT int
|
|
test_fbo_main (int argc, char *argv[])
|
|
{
|
|
ClutterColor blue = {0x33, 0x44, 0x55, 0xff};
|
|
|
|
ClutterActor *fbo;
|
|
ClutterActor *onscreen_source;
|
|
ClutterActor *stage;
|
|
ClutterAnimation *animation;
|
|
int x_pos = 200;
|
|
int y_pos = 100;
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_OFFSCREEN) == FALSE)
|
|
g_error("This test requires CLUTTER_FEATURE_OFFSCREEN");
|
|
|
|
stage = clutter_stage_get_default ();
|
|
clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &blue);
|
|
|
|
/* Create the first source */
|
|
onscreen_source = make_source();
|
|
clutter_actor_show_all (onscreen_source);
|
|
clutter_group_add (stage, onscreen_source);
|
|
|
|
y_pos = (STAGE_HEIGHT/2.0) -
|
|
(clutter_actor_get_height (onscreen_source)/2.0);
|
|
clutter_actor_set_position (onscreen_source, x_pos, y_pos);
|
|
x_pos += clutter_actor_get_width (onscreen_source);
|
|
|
|
animation = clutter_actor_animate (onscreen_source,
|
|
CLUTTER_LINEAR,
|
|
5000, /* 1 second duration */
|
|
"rotation-angle-y", 360.0f,
|
|
NULL);
|
|
clutter_animation_set_loop (animation, TRUE);
|
|
|
|
/* Second hand = actor from onscreen_source */
|
|
if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
|
|
g_error("onscreen fbo creation failed");
|
|
|
|
clutter_actor_set_position (fbo, x_pos, y_pos);
|
|
x_pos += clutter_actor_get_width (fbo);
|
|
clutter_group_add (stage, fbo);
|
|
|
|
/* Third hand = actor from Second hand */
|
|
if ((fbo = clutter_texture_new_from_actor (fbo)) == NULL)
|
|
g_error("fbo from fbo creation failed");
|
|
|
|
clutter_actor_set_position (fbo, x_pos, y_pos);
|
|
x_pos += clutter_actor_get_width (fbo);
|
|
clutter_group_add (stage, fbo);
|
|
|
|
clutter_actor_show_all (stage);
|
|
clutter_main ();
|
|
|
|
return 0;
|
|
}
|