1 #include <clutter/clutter.h>
2 
3 #include <errno.h>
4 #include <stdlib.h>
5 #include <glib.h>
6 #include <gmodule.h>
7 
8 #define STAGE_WIDTH   800
9 #define STAGE_HEIGHT  600
10 
11 ClutterActor *
make_source(void)12 make_source (void)
13 {
14   ClutterActor *source, *actor;
15   GError *error = NULL;
16   gchar *file;
17 
18   ClutterColor  yellow = {0xff, 0xff, 0x00, 0xff};
19 
20   source  = clutter_group_new ();
21 
22   file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
23   actor = clutter_texture_new_from_file (file, &error);
24   if (!actor)
25     g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
26 
27   g_free (file);
28 
29   clutter_container_add_actor (CLUTTER_CONTAINER (source), actor);
30 
31   actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
32 
33   clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
34   clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
35   clutter_container_add_actor (CLUTTER_CONTAINER (source), actor);
36 
37   return source;
38 }
39 
40 G_MODULE_EXPORT int
test_fbo_main(int argc,char * argv[])41 test_fbo_main (int argc, char *argv[])
42 {
43   ClutterActor     *fbo;
44   ClutterActor     *onscreen_source;
45   ClutterActor     *stage;
46   ClutterAnimation *animation;
47   int               x_pos = 200;
48   int               y_pos = 100;
49 
50   if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
51     return 1;
52 
53   if (clutter_feature_available (CLUTTER_FEATURE_OFFSCREEN) == FALSE)
54     g_error("This test requires CLUTTER_FEATURE_OFFSCREEN");
55 
56   stage = clutter_stage_new ();
57   clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
58   clutter_actor_set_background_color (stage, CLUTTER_COLOR_SkyBlue);
59   clutter_stage_set_title (CLUTTER_STAGE (stage), "Texture from Actor");
60   g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
61 
62   /* Create the first source */
63   onscreen_source = make_source();
64   clutter_actor_show_all (onscreen_source);
65   clutter_container_add_actor (CLUTTER_CONTAINER (stage), onscreen_source);
66 
67   y_pos = (STAGE_HEIGHT/2.0) -
68           (clutter_actor_get_height (onscreen_source)/2.0);
69   clutter_actor_set_position (onscreen_source, x_pos, y_pos);
70   x_pos += clutter_actor_get_width (onscreen_source);
71 
72   animation = clutter_actor_animate (onscreen_source,
73                                      CLUTTER_LINEAR,
74                                      5000, /* 1 second duration */
75                                      "rotation-angle-y", 360.0f,
76                                      NULL);
77   clutter_animation_set_loop (animation, TRUE);
78 
79   /* Second hand = actor from onscreen_source */
80   if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
81     g_error("onscreen fbo creation failed");
82 
83   clutter_actor_set_position (fbo, x_pos, y_pos);
84   x_pos += clutter_actor_get_width (fbo);
85   clutter_container_add_actor (CLUTTER_CONTAINER (stage), fbo);
86 
87   /* Third hand = actor from Second hand */
88   if ((fbo = clutter_texture_new_from_actor (fbo)) == NULL)
89     g_error("fbo from fbo creation failed");
90 
91   clutter_actor_set_position (fbo, x_pos, y_pos);
92   x_pos += clutter_actor_get_width (fbo);
93   clutter_container_add_actor (CLUTTER_CONTAINER (stage), fbo);
94 
95   clutter_actor_show_all (stage);
96   clutter_main ();
97 
98   return 0;
99 }
100 
101 G_MODULE_EXPORT const char *
test_fbo_describe(void)102 test_fbo_describe (void)
103 {
104   return "Create a texture from an actor.";
105 }
106