mutter/examples/cogl-hello.c
Robert Bragg cdbc1dc9b1 examples: Remove explicit framebuffer allocations
It used to be that cogl_framebuffer_allocate() had to be done explicitly
but we have since made Cogl lazily allocate framebuffers when they are
first used if they haven't already been explicitly allocated. Developers
only need to explicitly allocate framebuffers if they are planning to
gracefully handle any errors. In cases where the program will simply
abort due to an allocation error they can simply rely on implicit
allocation which will cause an abort on error.

This updates the examples to not explicitly allocate the framebuffers
since they all just abort on error anyway.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-09 13:09:15 +00:00

51 lines
1.3 KiB
C

#include <cogl/cogl.h>
#include <glib.h>
#include <stdio.h>
CoglColor black;
int
main (int argc, char **argv)
{
CoglContext *ctx;
CoglOnscreen *onscreen;
CoglFramebuffer *fb;
GError *error = NULL;
CoglVertexP2C4 triangle_vertices[] = {
{0, 0.7, 0xff, 0x00, 0x00, 0x80},
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
};
CoglPrimitive *triangle;
ctx = cogl_context_new (NULL, &error);
if (!ctx) {
fprintf (stderr, "Failed to create context: %s\n", error->message);
return 1;
}
onscreen = cogl_onscreen_new (ctx, 640, 480);
cogl_onscreen_show (onscreen);
fb = COGL_FRAMEBUFFER (onscreen);
cogl_push_framebuffer (fb);
triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices);
for (;;) {
CoglPollFD *poll_fds;
int n_poll_fds;
gint64 timeout;
cogl_clear (&black, COGL_BUFFER_BIT_COLOR);
cogl_primitive_draw (triangle);
cogl_framebuffer_swap_buffers (fb);
cogl_poll_get_info (ctx, &poll_fds, &n_poll_fds, &timeout);
g_poll ((GPollFD *) poll_fds, n_poll_fds, 0);
cogl_poll_dispatch (ctx, poll_fds, n_poll_fds);
}
return 0;
}