2008-04-25 09:37:36 -04:00
|
|
|
#include <glib.h>
|
2008-11-07 14:32:28 -05:00
|
|
|
#include <gmodule.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
#include <stdlib.h>
|
2011-01-19 09:36:30 -05:00
|
|
|
|
|
|
|
#undef COGL_ENABLE_EXPERIMENTAL_2_0_API
|
2008-04-25 09:37:36 -04:00
|
|
|
#include <cogl/cogl.h>
|
2011-01-19 09:36:30 -05:00
|
|
|
#include <clutter/clutter.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
typedef void (*PaintFunc) (void);
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_line (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-09 13:34:23 -04:00
|
|
|
cogl_path_line (-50, -25, 50, 25);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_rect (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-13 08:20:26 -04:00
|
|
|
cogl_path_rectangle (-50, -25, 50, 25);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_rndrect(void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-13 08:20:26 -04:00
|
|
|
cogl_path_round_rectangle (-50, -25, 50, 25, 10, 5);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_polyl (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-09 13:34:23 -04:00
|
|
|
gfloat poly_coords[] = {
|
|
|
|
-50, -50,
|
|
|
|
+50, -30,
|
|
|
|
+30, +30,
|
|
|
|
-30, +40
|
2008-04-25 09:37:36 -04:00
|
|
|
};
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-05-05 06:25:11 -04:00
|
|
|
cogl_path_polyline (poly_coords, 4);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_polyg (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-01-23 08:08:46 -05:00
|
|
|
gfloat poly_coords[] = {
|
2009-03-09 13:34:23 -04:00
|
|
|
-50, -50,
|
|
|
|
+50, -30,
|
|
|
|
+30, +30,
|
|
|
|
-30, +40
|
2008-04-25 09:37:36 -04:00
|
|
|
};
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-05-05 06:25:11 -04:00
|
|
|
cogl_path_polygon (poly_coords, 4);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_elp (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-09 13:34:23 -04:00
|
|
|
cogl_path_ellipse (0, 0, 60, 40);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-27 07:18:29 -04:00
|
|
|
test_paint_curve (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-03-09 13:34:23 -04:00
|
|
|
cogl_path_move_to (-50, +50);
|
|
|
|
|
|
|
|
cogl_path_curve_to (+100, -50,
|
|
|
|
-100, -50,
|
|
|
|
+50, +50);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:41:34 -04:00
|
|
|
static PaintFunc paint_func []=
|
|
|
|
{
|
|
|
|
test_paint_line,
|
|
|
|
test_paint_rect,
|
|
|
|
test_paint_rndrect,
|
|
|
|
test_paint_polyl,
|
|
|
|
test_paint_polyg,
|
|
|
|
test_paint_elp,
|
2008-05-05 06:25:11 -04:00
|
|
|
test_paint_curve
|
2008-04-29 11:41:34 -04:00
|
|
|
};
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
static void
|
2009-01-23 18:55:44 -05:00
|
|
|
paint_cb (ClutterActor *self, ClutterTimeline *tl)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-06-04 08:05:12 -04:00
|
|
|
gint paint_index = (clutter_timeline_get_progress (tl)
|
|
|
|
* G_N_ELEMENTS (paint_func));
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_push_matrix ();
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
paint_func[paint_index] ();
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2008-11-12 08:57:58 -05:00
|
|
|
cogl_translate (100, 100, 0);
|
|
|
|
cogl_set_source_color4ub (0, 160, 0, 255);
|
2008-12-04 08:45:09 -05:00
|
|
|
cogl_path_stroke_preserve ();
|
|
|
|
|
2008-11-12 08:57:58 -05:00
|
|
|
cogl_translate (150, 0, 0);
|
|
|
|
cogl_set_source_color4ub (200, 0, 0, 255);
|
2008-05-05 06:25:11 -04:00
|
|
|
cogl_path_fill ();
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_pop_matrix();
|
|
|
|
}
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_cogl_primitives_main (int argc, char *argv[])
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *coglbox;
|
2009-01-23 18:55:44 -05:00
|
|
|
ClutterTimeline *tl;
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
clutter_init(&argc, &argv);
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2009-06-04 08:05:12 -04:00
|
|
|
tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000);
|
2009-01-23 18:55:44 -05:00
|
|
|
clutter_timeline_set_loop (tl, TRUE);
|
|
|
|
clutter_timeline_start (tl);
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_actor_set_size (stage, 400, 400);
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test");
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2009-01-23 18:55:44 -05:00
|
|
|
coglbox = clutter_group_new ();
|
2008-04-25 09:37:36 -04:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
|
2009-01-23 18:55:44 -05:00
|
|
|
g_signal_connect (coglbox, "paint", G_CALLBACK (paint_cb), tl);
|
|
|
|
/* Redraw every frame of the timeline */
|
|
|
|
g_signal_connect_swapped (tl, "new-frame",
|
|
|
|
G_CALLBACK (clutter_actor_queue_redraw), coglbox);
|
2008-05-05 06:25:11 -04:00
|
|
|
|
|
|
|
clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0);
|
|
|
|
clutter_actor_set_position (coglbox, 0, 100);
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2009-01-23 18:55:44 -05:00
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2009-01-23 18:55:44 -05:00
|
|
|
g_object_unref (tl);
|
2009-01-23 18:41:26 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|