/*
 * build with:
 * gcc -Wall -g `pkg-config --cflags --libs clutter-0.9` test.c -o test
 *
 * usage:
 * ./test /path/to/pic1.jpg /path/to/pic2.jpg
 */

#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
#include <clutter/clutter.h>

#define SPIN()   while (g_main_context_pending (NULL)) \
                     g_main_context_iteration (NULL, FALSE);

int main (int argc, char *argv[]) {
  ClutterActor    *texture;
  ClutterActor    *stage;
  gint             i;
  gboolean        flag = TRUE;

  if (argc != 3) {
    printf ("usage: %s <img1> <img2>\n", argv[0]);
    return 1;
  }

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_actor_show_all (CLUTTER_ACTOR (stage));

  SPIN();

  for ( i=0; i<=15; i++) {
    printf ("read image from file %s\n", flag ? argv[1] : argv[2]);
    texture = clutter_texture_new_from_file ((flag ? argv[1] : argv[2]), NULL);
    clutter_container_add (CLUTTER_CONTAINER (stage), texture, NULL);
    clutter_actor_set_size (texture, 800, 600);
    clutter_actor_show (texture);

    SPIN();

    printf ("sleep\n");
    sleep( 4 );

    printf ("destroy texture %s\n", flag ? argv[1] : argv[2]);
    clutter_actor_destroy( texture );
    flag = !flag;
  }

  return EXIT_SUCCESS;
}
