9
CoglPrimitive *triangle;
10
CoglPipeline *pipeline;
14
paint_cb (void *user_data)
16
Data *data = user_data;
18
cogl_framebuffer_clear4f (data->fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
19
cogl_framebuffer_draw_primitive (data->fb, data->pipeline, data->triangle);
20
cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));
22
/* If the driver can deliver swap complete events then we can remove
23
* the idle paint callback until we next get a swap complete event
24
* otherwise we keep the idle paint callback installed and simply
25
* paint as fast as the driver will allow... */
26
if (cogl_has_feature (data->ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT))
27
return FALSE; /* remove the callback */
33
swap_complete_cb (CoglFramebuffer *framebuffer, void *user_data)
35
g_idle_add (paint_cb, user_data);
39
main (int argc, char **argv)
42
CoglOnscreen *onscreen;
44
CoglVertexP2C4 triangle_vertices[] = {
45
{0, 0.7, 0xff, 0x00, 0x00, 0x80},
46
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
47
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
52
data.ctx = cogl_context_new (NULL, &error);
54
fprintf (stderr, "Failed to create context: %s\n", error->message);
58
onscreen = cogl_onscreen_new (data.ctx, 640, 480);
59
cogl_onscreen_show (onscreen);
60
data.fb = COGL_FRAMEBUFFER (onscreen);
62
data.triangle = cogl_primitive_new_p2c4 (data.ctx,
63
COGL_VERTICES_MODE_TRIANGLES,
64
3, triangle_vertices);
65
data.pipeline = cogl_pipeline_new (data.ctx);
67
cogl_source = cogl_glib_source_new (data.ctx, G_PRIORITY_DEFAULT);
69
g_source_attach (cogl_source, NULL);
71
if (cogl_has_feature (data.ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT))
72
cogl_onscreen_add_swap_buffers_callback (COGL_ONSCREEN (data.fb),
73
swap_complete_cb, &data);
75
g_idle_add (paint_cb, &data);
77
loop = g_main_loop_new (NULL, TRUE);
78
g_main_loop_run (loop);