Ejemplo n.º 1
0
CoglTexture *
meta_cogl_texture_new_from_file_wrapper         (const char *filename,
                                           CoglTextureFlags  flags,
                                            CoglPixelFormat  internal_format)
{
    CoglTexture *texture = NULL;

    if (hardware_supports_npot_sizes ())
      {
        texture = COGL_TEXTURE (cogl_texture_2d_new_from_file (cogl_context,
                                                               filename,
#if COGL_VERSION < COGL_VERSION_ENCODE (1, 18, 0)
                                                               COGL_PIXEL_FORMAT_ANY,
#endif
                                                               NULL));
      }
    else
      {
        texture = cogl_texture_new_from_file (filename,
                                              flags,
                                              internal_format,
                                              NULL);
      }

    return texture;
}
Ejemplo n.º 2
0
CoglTexture *
st_cogl_texture_new_from_file_wrapper         (const char *filename,
                                         CoglTextureFlags  flags,
                                          CoglPixelFormat  internal_format)
{
    CoglTexture *texture = NULL;
    CoglError *error = NULL;

    if (hardware_supports_npot_sizes ())
      {
        texture = COGL_TEXTURE (cogl_texture_2d_new_from_file (cogl_context,
                                                               filename,
#if COGL_VERSION < COGL_VERSION_ENCODE (1, 18, 0)
                                                               COGL_PIXEL_FORMAT_ANY,
#endif
                                                               &error));
      }
    else
      {
        texture = cogl_texture_new_from_file (filename,
                                              flags,
                                              internal_format,
                                              &error);
      }

    if (error)
      {
        g_debug ("cogl_texture_(2d)_new_from_file failed: %s\n", error->message);
        cogl_error_free (error);
      }

    return texture;
}
Ejemplo n.º 3
0
static void
st_background_effect_set_property (GObject      *gobject,
                                   guint         prop_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  StBackgroundEffect *self = ST_BACKGROUND_EFFECT (gobject);

  switch (prop_id)
    {
    case PROP_BUMPMAP:

      self->bumpmap_location = g_value_dup_string (value);

      if (self->bg_bumpmap != NULL)
        {
          cogl_handle_unref (self->bg_bumpmap);
          self->bg_bumpmap = NULL;
        }

      if (self->bumpmap_location == NULL)
        {
          break;
        }

      GFile *file = g_file_new_for_path (g_strdup (self->bumpmap_location));
      if (g_file_query_exists (file, NULL))
        {
          self->bg_bumpmap = cogl_texture_new_from_file (self->bumpmap_location,
                                                         COGL_TEXTURE_NO_SLICING,
                                                         COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                                         NULL);
        }

      g_object_unref (file);

      if (self->bg_bumpmap != NULL)
        {
          self->bumptex_width_i = cogl_texture_get_width (self->bg_bumpmap);
          self->bumptex_height_i = cogl_texture_get_height (self->bg_bumpmap);

          cogl_pipeline_set_layer_texture (self->pipeline0, 1, self->bg_bumpmap);
        }
      else
        {
          cogl_pipeline_set_layer_null_texture (self->pipeline0,
                                                1,
                                                COGL_TEXTURE_TYPE_2D);
        }

      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
      break;
    }
}
Ejemplo n.º 4
0
G_MODULE_EXPORT int
test_clip_main (int argc, char **argv)
{
  CallbackData data;
  ClutterActor *stub_actor, *label;
  gchar *file;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  data.current_clip.type = CLIP_NONE;
  data.clips = NULL;

  data.stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (data.stage), "Clipping");
  g_signal_connect (data.stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  stub_actor = clutter_rectangle_new ();
  clutter_container_add (CLUTTER_CONTAINER (data.stage), stub_actor, NULL);

  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  data.hand = cogl_texture_new_from_file (file,
                                          COGL_TEXTURE_NONE,
                                          COGL_PIXEL_FORMAT_ANY,
                                          NULL);
  g_free (file);

  label = clutter_text_new_with_text ("Sans 12px", instructions);
  clutter_text_set_line_wrap (CLUTTER_TEXT (label), TRUE);
  clutter_actor_set_width (label, clutter_actor_get_width (data.stage) - 310);
  clutter_actor_set_y (label,
                       clutter_actor_get_height (data.stage)
                       - clutter_actor_get_height (label));
  clutter_container_add (CLUTTER_CONTAINER (data.stage), label, NULL);

  g_signal_connect (stub_actor, "paint", G_CALLBACK (on_paint), &data);

  g_signal_connect (data.stage, "button-press-event",
                    G_CALLBACK (on_button_press), &data);
  g_signal_connect (data.stage, "button-release-event",
                    G_CALLBACK (on_button_release), &data);
  g_signal_connect (data.stage, "motion-event",
                    G_CALLBACK (on_motion), &data);
  g_signal_connect (data.stage, "key-press-event",
                    G_CALLBACK (on_key_press), &data);

  clutter_actor_show (data.stage);

  clutter_main ();

  cogl_handle_unref (data.hand);

  free_clips (&data);

  return 0;
}
Ejemplo n.º 5
0
G_MODULE_EXPORT int
test_cogl_shader_arbfp_main (int argc, char *argv[])
{
  ClutterActor *stage;
  char *file;
  GError *error;
  ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_new ();

  clutter_stage_set_title (CLUTTER_STAGE (stage), "Assembly Shader Test");
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  error = NULL;
  redhand = cogl_texture_new_from_file (file, 0, COGL_PIXEL_FORMAT_ANY,
                                        &error);
  if (redhand == COGL_INVALID_HANDLE)
    g_error ("image load failed: %s", error->message);

  material = cogl_material_new ();
  cogl_material_set_layer (material, 0, redhand);

  set_shader_num (0);
  g_signal_connect_after (stage, "paint", G_CALLBACK (paint_cb), NULL);

  clutter_actor_set_reactive (stage, TRUE);
  g_signal_connect (stage, "button-release-event",
                    G_CALLBACK (button_release_cb), NULL);
  g_signal_connect (stage, "key-release-event",
                    G_CALLBACK (key_release_cb), NULL);

  g_signal_connect (stage, "delete-event",
                    G_CALLBACK (destroy_window_cb), NULL);

  timeout_id = clutter_threads_add_timeout (1000, timeout_cb, NULL);

  clutter_threads_add_idle (idle_cb, stage);

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
static void
icon_cb (MxToggle   *toggle,
         GParamSpec *pspec,
         MxWindow   *window)
{
    gboolean use_custom = mx_toggle_get_active (toggle);

    if (use_custom)
    {
        CoglHandle texture = cogl_texture_new_from_file ("redhand.png",
                             COGL_TEXTURE_NONE,
                             COGL_PIXEL_FORMAT_ANY,
                             NULL);
        if (texture)
            mx_window_set_icon_from_cogl_texture (window, texture);
        cogl_handle_unref (texture);
    }
    else
        mx_window_set_icon_name (window, "window-new");
}
Ejemplo n.º 7
0
gboolean
glide_image_set_from_file (GlideImage *image,
			   const gchar *filename,
			   GError **error)
{
  GlideImagePrivate *priv;
  CoglHandle new_texture = COGL_INVALID_HANDLE;
  GError *internal_error = NULL;
  CoglTextureFlags flags = COGL_TEXTURE_NONE;
  
  priv = image->priv;
  if (priv->filename)
    g_free (priv->filename);
  priv->filename = g_strdup (filename);
  
  new_texture = cogl_texture_new_from_file (filename,
					    flags,
					    COGL_PIXEL_FORMAT_ANY,
					    &internal_error);
  
  if (internal_error == NULL && new_texture == COGL_INVALID_HANDLE)
    {
      g_set_error (&internal_error, CLUTTER_TEXTURE_ERROR,
		   CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
		   "Failed to create COGL texture");
    }
  if (internal_error != NULL)
    {
      g_propagate_error (error, internal_error);
      
      return FALSE;
    }
  
  glide_image_set_cogl_texture (image, new_texture);
  
  cogl_handle_unref (new_texture);
  
  return TRUE;
}
Ejemplo n.º 8
0
G_MODULE_EXPORT int
test_cogl_multitexture_main (int argc, char *argv[])
{
  GError            *error = NULL;
  ClutterActor	    *stage;
  ClutterColor       stage_color = { 0x61, 0x56, 0x56, 0xff };
  TestMultiLayerMaterialState *state = g_new0 (TestMultiLayerMaterialState, 1);
  gfloat             stage_w, stage_h;
  gchar            **files;
  gfloat             tex_coords[] =
    {
    /* tx1  ty1  tx2  ty2 */
         0,   0,   1,   1,
         0,   0,   1,   1,
         0,   0,   1,   1
    };

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_new ();
  clutter_actor_get_size (stage, &stage_w, &stage_h);

  clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl: Multi-texturing");
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  /* We create a non-descript actor that we know doesn't have a
   * default paint handler, so that we can easily control
   * painting in a paint signal handler, without having to
   * sub-class anything etc. */
  state->group = clutter_group_new ();
  clutter_actor_set_position (state->group, stage_w / 2, stage_h / 2);
  g_signal_connect (state->group, "paint",
		    G_CALLBACK(material_rectangle_paint), state);

  files = g_new (gchar*, 4);
  files[0] = g_build_filename (TESTS_DATADIR, "redhand_alpha.png", NULL);
  files[1] = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  files[2] = g_build_filename (TESTS_DATADIR, "light0.png", NULL);
  files[3] = NULL;

  state->alpha_tex =
    cogl_texture_new_from_file (files[0],
                                COGL_TEXTURE_NO_SLICING,
				COGL_PIXEL_FORMAT_ANY,
				&error);
  if (!state->alpha_tex)
    g_critical ("Failed to load redhand_alpha.png: %s", error->message);

  state->redhand_tex =
    cogl_texture_new_from_file (files[1],
                                COGL_TEXTURE_NO_SLICING,
				COGL_PIXEL_FORMAT_ANY,
				&error);
  if (!state->redhand_tex)
    g_critical ("Failed to load redhand.png: %s", error->message);

  state->light_tex0 =
    cogl_texture_new_from_file (files[2],
                                COGL_TEXTURE_NO_SLICING,
				COGL_PIXEL_FORMAT_ANY,
				&error);
  if (!state->light_tex0)
    g_critical ("Failed to load light0.png: %s", error->message);

  state->light_tex1 =
    cogl_texture_new_from_file (files[2],
                                COGL_TEXTURE_NO_SLICING,
				COGL_PIXEL_FORMAT_ANY,
				&error);
  if (!state->light_tex1)
    g_critical ("Failed to load light0.png: %s", error->message);

  g_strfreev (files);

  state->material0 = cogl_material_new ();
  cogl_material_set_layer (state->material0, 0, state->alpha_tex);
  cogl_material_set_layer (state->material0, 1, state->redhand_tex);
  cogl_material_set_layer (state->material0, 2, state->light_tex0);

  state->material1 = cogl_material_new ();
  cogl_material_set_layer (state->material1, 0, state->alpha_tex);
  cogl_material_set_layer (state->material1, 1, state->redhand_tex);
  cogl_material_set_layer (state->material1, 2, state->light_tex1);

  state->tex_coords = tex_coords;

  cogl_matrix_init_identity (&state->tex_matrix0);
  cogl_matrix_init_identity (&state->tex_matrix1);
  cogl_matrix_init_identity (&state->rot_matrix0);
  cogl_matrix_init_identity (&state->rot_matrix1);

  cogl_matrix_translate (&state->rot_matrix0, 0.5, 0.5, 0);
  cogl_matrix_rotate (&state->rot_matrix0, 10.0, 0, 0, 1.0);
  cogl_matrix_translate (&state->rot_matrix0, -0.5, -0.5, 0);

  cogl_matrix_translate (&state->rot_matrix1, 0.5, 0.5, 0);
  cogl_matrix_rotate (&state->rot_matrix1, -10.0, 0, 0, 1.0);
  cogl_matrix_translate (&state->rot_matrix1, -0.5, -0.5, 0);

  clutter_actor_set_anchor_point (state->group, 86, 125);
  clutter_container_add_actor (CLUTTER_CONTAINER(stage),
			       state->group);

  state->timeline = clutter_timeline_new (2812);

  g_signal_connect (state->timeline, "new-frame", G_CALLBACK (frame_cb), state);

  clutter_actor_animate_with_timeline (state->group,
                                       CLUTTER_LINEAR,
                                       state->timeline,
                                       "rotation-angle-y", 30.0,
                                       "signal-after::completed",
                                       animation_completed_cb, state,
                                       NULL);

  /* start the timeline and thus the animations */
  clutter_timeline_start (state->timeline);

  clutter_actor_show_all (stage);

  clutter_main();

  cogl_handle_unref (state->material1);
  cogl_handle_unref (state->material0);
  cogl_handle_unref (state->alpha_tex);
  cogl_handle_unref (state->redhand_tex);
  cogl_handle_unref (state->light_tex0);
  cogl_handle_unref (state->light_tex1);
  g_free (state);

  return 0;
}
Ejemplo n.º 9
0
int
main (int argc, char **argv)
{
  CoglContext *ctx;
  CoglOnscreen *onscreen;
  CoglFramebuffer *fb;
  GError *error = NULL;
  Data data;
  PangoRectangle hello_label_size;
  float fovy, aspect, z_near, z_2d, z_far;
  CoglDepthState depth_state;
  CoglBool has_swap_notify;

  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);
  fb = COGL_FRAMEBUFFER (onscreen);
  data.fb = fb;
  data.framebuffer_width = cogl_framebuffer_get_width (fb);
  data.framebuffer_height = cogl_framebuffer_get_height (fb);

  data.timer = g_timer_new ();

  cogl_onscreen_show (onscreen);

  cogl_framebuffer_set_viewport (fb,
                                 0, 0,
                                 data.framebuffer_width,
                                 data.framebuffer_height);

  fovy = 60; /* y-axis field of view */
  aspect = (float)data.framebuffer_width/(float)data.framebuffer_height;
  z_near = 0.1; /* distance to near clipping plane */
  z_2d = 1000; /* position to 2d plane */
  z_far = 2000; /* distance to far clipping plane */

  cogl_framebuffer_perspective (fb, fovy, aspect, z_near, z_far);

  /* Since the pango renderer emits geometry in pixel/device coordinates
   * and the anti aliasing is implemented with the assumption that the
   * geometry *really* does end up pixel aligned, we setup a modelview
   * matrix so that for geometry in the plane z = 0 we exactly map x
   * coordinates in the range [0,stage_width] and y coordinates in the
   * range [0,stage_height] to the framebuffer extents with (0,0) being
   * the top left.
   *
   * This is roughly what Clutter does for a ClutterStage, but this
   * demonstrates how it is done manually using Cogl.
   */
  cogl_matrix_init_identity (&data.view);
  cogl_matrix_view_2d_in_perspective (&data.view, fovy, aspect, z_near, z_2d,
                                      data.framebuffer_width,
                                      data.framebuffer_height);
  cogl_framebuffer_set_modelview_matrix (fb, &data.view);

  /* Initialize some convenient constants */
  cogl_matrix_init_identity (&identity);
  cogl_color_set_from_4ub (&white, 0xff, 0xff, 0xff, 0xff);

  /* rectangle indices allow the GPU to interpret a list of quads (the
   * faces of our cube) as a list of triangles.
   *
   * Since this is a very common thing to do
   * cogl_get_rectangle_indices() is a convenience function for
   * accessing internal index buffers that can be shared.
   */
  data.indices = cogl_get_rectangle_indices (ctx, 6 /* n_rectangles */);
  data.prim = cogl_primitive_new_p3t2 (ctx, COGL_VERTICES_MODE_TRIANGLES,
                                       G_N_ELEMENTS (vertices),
                                       vertices);
  /* Each face will have 6 indices so we have 6 * 6 indices in total... */
  cogl_primitive_set_indices (data.prim,
                              data.indices,
                              6 * 6);

  /* Load a jpeg crate texture from a file */
  printf ("crate.jpg (CC by-nc-nd http://bit.ly/9kP45T) ShadowRunner27 http://bit.ly/m1YXLh\n");
  data.texture = cogl_texture_new_from_file (COGL_EXAMPLES_DATA "crate.jpg",
                                             COGL_TEXTURE_NO_SLICING,
                                             COGL_PIXEL_FORMAT_ANY,
                                             &error);
  if (!data.texture)
    g_error ("Failed to load texture: %s", error->message);

  /* a CoglPipeline conceptually describes all the state for vertex
   * processing, fragment processing and blending geometry. When
   * drawing the geometry for the crate this pipeline says to sample a
   * single texture during fragment processing... */
  data.crate_pipeline = cogl_pipeline_new (ctx);
  cogl_pipeline_set_layer_texture (data.crate_pipeline, 0, data.texture);

  /* Since the box is made of multiple triangles that will overlap
   * when drawn and we don't control the order they are drawn in, we
   * enable depth testing to make sure that triangles that shouldn't
   * be visible get culled by the GPU. */
  cogl_depth_state_init (&depth_state);
  cogl_depth_state_set_test_enabled (&depth_state, TRUE);

  cogl_pipeline_set_depth_state (data.crate_pipeline, &depth_state, NULL);

  /* Setup a Pango font map and context */

  data.pango_font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new (ctx));

  cogl_pango_font_map_set_use_mipmapping (data.pango_font_map, TRUE);

  data.pango_context =
    pango_font_map_create_context (PANGO_FONT_MAP (data.pango_font_map));

  data.pango_font_desc = pango_font_description_new ();
  pango_font_description_set_family (data.pango_font_desc, "Sans");
  pango_font_description_set_size (data.pango_font_desc, 30 * PANGO_SCALE);

  /* Setup the "Hello Cogl" text */

  data.hello_label = pango_layout_new (data.pango_context);
  pango_layout_set_font_description (data.hello_label, data.pango_font_desc);
  pango_layout_set_text (data.hello_label, "Hello Cogl", -1);

  pango_layout_get_extents (data.hello_label, NULL, &hello_label_size);
  data.hello_label_width = PANGO_PIXELS (hello_label_size.width);
  data.hello_label_height = PANGO_PIXELS (hello_label_size.height);

  data.swap_ready = TRUE;

  has_swap_notify =
    cogl_has_feature (ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT);

  if (has_swap_notify)
    cogl_onscreen_add_swap_buffers_callback (COGL_ONSCREEN (fb),
                                             swap_notify_cb,
                                             &data);

  while (1)
    {
      CoglPollFD *poll_fds;
      int n_poll_fds;
      int64_t timeout;

      if (data.swap_ready)
        {
          paint (&data);
          cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));
        }

      cogl_poll_get_info (ctx, &poll_fds, &n_poll_fds, &timeout);

      if (!has_swap_notify)
        {
          /* If the winsys doesn't support swap event notification
             then we'll just redraw constantly */
          data.swap_ready = TRUE;
          timeout = 0;
        }

      g_poll ((GPollFD *) poll_fds, n_poll_fds,
              timeout == -1 ? -1 : timeout / 1000);

      cogl_poll_dispatch (ctx, poll_fds, n_poll_fds);
    }

  return 0;
}
Ejemplo n.º 10
0
int
main (int argc, char **argv)
{
  gtk_init( &argc, &argv );

  g_type_init ();

  gfx_lib_setup ();

  g_testtex = cogl_texture_new_from_file ("testtex_sr.bmp", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL);
  g_xassert (g_testtex != COGL_INVALID_HANDLE);

  //cogl_ortho (-1.0f, 1.0f, -1.0f, 1.0f, -5.0f, 100.0f);
  cogl_perspective (45.0f, 1.0f, 0.1f, 100.0f);
  cogl_set_source_texture (g_testtex);

  /**
   * WHY IS THIS NOT ENABLED BY DEFAULT
   */
  cogl_set_depth_test_enabled (TRUE);

  /**
   * Enabling this shows polygons actually missing not just culled out?
   * cogl_set_backface_culling_enabled (TRUE);
   */

  /**
   * Initialize g_state
   */
  struct NxState state = {0};
  g_state = g_new0 (struct NxState, 1);
  *g_state = state;

  g_state->dr_n = 1.0f;
  g_state->dr_f = 100.0f;
  g_state->vp_w = 100.0f;
  g_state->vp_h = 100.0f;
  g_state->vp_x = 0.0f;
  g_state->vp_y = 0.0f;

  NxMat z_mat;
  nx_mat_init_identity (&z_mat);
  nx_mat_translate (&z_mat, 0.0f, 0.0f, -30.0f);

  g_state->p_mat = z_mat;
  g_state->w_mat = z_mat;

  MaiModel *model;
  struct aiScene *scene;
  model = mai_model_new_from_file ("../misc/mtest1.dae", &scene);
  aiReleaseImport (scene);

  MaiAnimInstance *mai;
  g_xassert (model->anims->len > 0);
  mai = mai_anim_instance_new_from_anim (
                                         g_mai_anim_ptr_array_index (model->anims, 0),
                                         model->name_node_map,
                                         model->nodes);

  struct SrNodeGraph *sr_model;
  sr_node_graph_from_model (model, &sr_model);

  MaiInfoWin *iw;
  iw = MAI_INFO_WIN (mai_info_win_new ());

  mai_info_win_clear_model (iw);
  mai_info_win_fill_model_from_node_graph (iw, sr_model);
  mai_info_win_fill_model_from_model (iw, model);

  mai_info_win_show (iw);

  int frame;
  for (frame=0; frame<600; ++frame)
    {
      ALLEGRO_KEYBOARD_STATE aks;

      gfx_display_clear ();

      context_switch_allegro ();
      al_get_keyboard_state (&aks);
      sr_update_global_ypr (&aks);
      al_clear_to_color (al_map_rgb (0, 0, 0));

      mai_info_win_iteration (iw, FALSE);

      /**
       * Allegro drawing origin top left.
       * Compensate (Want positive x/y go northwest).
       */
      NxMat comp;
      comp = g_state->w_mat;
      nx_mat_scale (&comp, -1.0f, 1.0f, -1.0f);

      struct SrNodeGraph *sr_model_aux;
      GHashTable *ht;

      sr_node_graph_copy (&sr_model_aux, sr_model);

      sr_skeletal_anim_node_graph (mai, sr_model_aux);
      sr_skeletal_anim_verts (model, mai, sr_model_aux, &ht);

      GList *model_keys;
      model_keys = g_hash_table_get_keys (ht);

      for (GList *k = model_keys; k != NULL; k = k->next)
        {
          char *name;
          GArray *vts_a;
          MaiNode *mn_a;

          name = k->data;

          vts_a = g_hash_table_lookup (ht, name);
          g_xassert (vts_a);
          g_array_ref (vts_a);

          mn_a = g_object_ref (MAI_NODE (
              g_hash_table_lookup (model->name_node_map, name)));
          g_xassert (mn_a);

          sr_skeletal_draw_node_trans (&comp, sr_model_aux,
                                       mn_a, vts_a);

          g_object_unref (mn_a);
          g_array_unref (vts_a);
        }

      g_list_free (model_keys);

      g_hash_table_unref (ht);

      sr_node_graph_free (sr_model_aux);

      mai->current_frame += mai->current_frame == 29 ? -29 : 1;

      gfx_display_transfer ();

      al_rest (0.05f);
    }

  return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
static void
st_background_effect_init (StBackgroundEffect *self)
{
  CoglContext *ctx;
  StBackgroundEffectClass *klass = ST_BACKGROUND_EFFECT_GET_CLASS (self);

  if (G_UNLIKELY (klass->base_pipeline == NULL))
    {
      ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());

      klass->base_pipeline = cogl_pipeline_new (ctx);
    }
    
  self->pipeline0 = cogl_pipeline_copy (klass->base_pipeline);
  self->pipeline1 = cogl_pipeline_copy (klass->base_pipeline);
  self->pipeline2 = cogl_pipeline_copy (klass->base_pipeline);
  self->pipeline3 = cogl_pipeline_copy (klass->base_pipeline);
  self->pipeline4 = cogl_pipeline_copy (klass->base_pipeline);

  CoglSnippet *snippet;
  snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP,
                              box_blur_glsl_declarations,
                              NULL);

  cogl_snippet_set_replace (snippet, box_blur_glsl_shader);
  cogl_pipeline_add_layer_snippet (self->pipeline0, 0, snippet);
  cogl_pipeline_add_layer_snippet (self->pipeline1, 0, snippet);
  cogl_pipeline_add_layer_snippet (self->pipeline3, 0, snippet);
  cogl_object_unref (snippet);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline0, 0,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline0, 1,
                                     COGL_PIPELINE_WRAP_MODE_REPEAT);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline1, 0,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline2, 0,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline3, 0,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_pipeline_set_layer_wrap_mode (self->pipeline4, 0,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_pipeline_set_cull_face_mode (self->pipeline0,
                                    COGL_PIPELINE_CULL_FACE_MODE_NONE);

  cogl_pipeline_set_cull_face_mode (self->pipeline1,
                                    COGL_PIPELINE_CULL_FACE_MODE_NONE);

  cogl_pipeline_set_cull_face_mode (self->pipeline2,
                                    COGL_PIPELINE_CULL_FACE_MODE_NONE);

  cogl_pipeline_set_cull_face_mode (self->pipeline3,
                                    COGL_PIPELINE_CULL_FACE_MODE_NONE);

  cogl_pipeline_set_cull_face_mode (self->pipeline4,
                                    COGL_PIPELINE_CULL_FACE_MODE_NONE);

  cogl_pipeline_set_layer_filters (self->pipeline0, 0,
                                   COGL_PIPELINE_FILTER_LINEAR,
                                   COGL_PIPELINE_FILTER_LINEAR);

  cogl_pipeline_set_layer_filters (self->pipeline0, 1,
                                   COGL_PIPELINE_FILTER_NEAREST,
                                   COGL_PIPELINE_FILTER_NEAREST);

  cogl_pipeline_set_layer_filters (self->pipeline1, 0,
                                   COGL_PIPELINE_FILTER_LINEAR,
                                   COGL_PIPELINE_FILTER_LINEAR);

  cogl_pipeline_set_layer_filters (self->pipeline2, 0,
                                   COGL_PIPELINE_FILTER_LINEAR,
                                   COGL_PIPELINE_FILTER_LINEAR);

  cogl_pipeline_set_layer_filters (self->pipeline3, 0,
                                   COGL_PIPELINE_FILTER_LINEAR,
                                   COGL_PIPELINE_FILTER_LINEAR);

  cogl_pipeline_set_layer_filters (self->pipeline4, 0,
                                   COGL_PIPELINE_FILTER_LINEAR,
                                   COGL_PIPELINE_FILTER_LINEAR);

  cogl_pipeline_set_layer_null_texture (self->pipeline0,
                                        0,
                                        COGL_TEXTURE_TYPE_2D);

  cogl_pipeline_set_layer_null_texture (self->pipeline1,
                                        0,
                                        COGL_TEXTURE_TYPE_2D);

  cogl_pipeline_set_layer_null_texture (self->pipeline2,
                                        0,
                                        COGL_TEXTURE_TYPE_2D);

  cogl_pipeline_set_layer_null_texture (self->pipeline3,
                                        0,
                                        COGL_TEXTURE_TYPE_2D);
  
  cogl_pipeline_set_layer_null_texture (self->pipeline4,
                                        0,
                                        COGL_TEXTURE_TYPE_2D);

  self->pixel_step_uniform0 =
    cogl_pipeline_get_uniform_location (self->pipeline0, "pixel_step");

  self->BumpTex_uniform =
    cogl_pipeline_get_uniform_location (self->pipeline0, "BumpTex");

  self->bump_step_uniform =
    cogl_pipeline_get_uniform_location (self->pipeline0, "bump_step");

  self->pixel_step_uniform1 =
    cogl_pipeline_get_uniform_location (self->pipeline1, "pixel_step");

  self->pixel_step_uniform2 =
    cogl_pipeline_get_uniform_location (self->pipeline3, "pixel_step");

  cogl_pipeline_set_blend (self->pipeline0,
                           "RGBA = ADD(SRC_COLOR, DST_COLOR*0)",
                           NULL);

  cogl_pipeline_set_blend (self->pipeline1,
                           "RGBA = ADD (SRC_COLOR*DST_COLOR[A], DST_COLOR*(1-DST_COLOR[A]))",
                           NULL);

  cogl_pipeline_set_color4ub (self->pipeline1,
                              0xff,
                              0xff,
                              0xff,
                              0xff);

  cogl_pipeline_set_alpha_test_function (self->pipeline2,
                                         COGL_PIPELINE_ALPHA_FUNC_LESS,
                                         0.004f);

  cogl_pipeline_set_color_mask (self->pipeline2,
                                COGL_COLOR_MASK_ALPHA);

  cogl_pipeline_set_blend (self->pipeline2,
                           "RGBA = ADD(SRC_COLOR, DST_COLOR*0)",
                           NULL);

  cogl_pipeline_set_alpha_test_function (self->pipeline3,
                                         COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
                                         0.004f);
    
  cogl_pipeline_set_color_mask (self->pipeline3,
                                COGL_COLOR_MASK_ALL);

  cogl_pipeline_set_blend (self->pipeline3,
                           "RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))",
                           NULL);

  cogl_pipeline_set_alpha_test_function (self->pipeline4,
                                         COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
                                         0.004f);
    
  cogl_pipeline_set_color_mask (self->pipeline4,
                                COGL_COLOR_MASK_ALL);

  cogl_pipeline_set_blend (self->pipeline4,
                           "RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))",
                           NULL);


  self->bg_texture = NULL;

  self->bg_sub_texture = NULL;

  self->bumpmap_location = "/usr/share/cinnamon/bumpmaps/frost.png";

  self->bg_bumpmap = cogl_texture_new_from_file (self->bumpmap_location,
                                                 COGL_TEXTURE_NO_SLICING,
                                                 COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                                 NULL);
  if (self->bg_bumpmap != NULL)
    {
      self->bumptex_width_i = cogl_texture_get_width (self->bg_bumpmap);
      self->bumptex_height_i = cogl_texture_get_height (self->bg_bumpmap);

      cogl_pipeline_set_layer_texture (self->pipeline0, 1, self->bg_bumpmap);
    }
  else
    {
      cogl_pipeline_set_layer_null_texture (self->pipeline0,
                                            1,
                                            COGL_TEXTURE_TYPE_2D);
    }

  cogl_pipeline_set_layer_combine (self->pipeline0,1,
                                   "RGBA = REPLACE (PREVIOUS)",
                                   NULL);

  self->old_time = 0;

  self->opacity = 0;

}
Ejemplo n.º 12
0
int
main (int argc, char **argv)
{
  ClutterActor *stage;
  ClutterActor *fader;
  ClutterConstraint *constraint;
  CoglHandle tex0, tex1;
  GError *error = NULL;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

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

  tex0 = cogl_texture_new_from_file (argv[1],
                                     COGL_TEXTURE_NO_SLICING |
                                     COGL_TEXTURE_NO_ATLAS,
                                     COGL_PIXEL_FORMAT_ANY,
                                     &error);
  if (tex0 == COGL_INVALID_HANDLE)
    {
      g_print ("error opening %s: %s\n", argv[1], error->message);
      g_clear_error (&error);
      return 1;
    }

  tex1 = cogl_texture_new_from_file (argv[2],
                                     COGL_TEXTURE_NO_SLICING |
                                     COGL_TEXTURE_NO_ATLAS,
                                     COGL_PIXEL_FORMAT_ANY,
                                     &error);
  if (tex1 == COGL_INVALID_HANDLE)
    {
      cogl_handle_unref (tex0);
      g_print ("error opening %s: %s\n", argv[2], error->message);
      g_clear_error (&error);
      return 1;
    }

  fader = foo_fader_new ();

  foo_fader_set_texture_0 (FOO_FADER (fader), tex0);
  foo_fader_set_texture_1 (FOO_FADER (fader), tex1);

  cogl_handle_unref (tex0);
  cogl_handle_unref (tex1);

  stage = clutter_stage_get_default ();
  clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE);

  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (button_press_event_cb),
                    fader);

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), fader);

  constraint =
    clutter_bind_constraint_new (stage,
                                 CLUTTER_BIND_SIZE,
                                 0.0f);
  clutter_actor_add_constraint (fader, constraint);

  /* massive hack --- nothing to see here! */
  foo_fader_set_progress (FOO_FADER (fader), 0.00001f);

  clutter_actor_show (stage);

  clutter_main ();

  return 0;
}
static void
test_coglbox_init (TestCoglbox *self)
{
  TestCoglboxPrivate *priv;
  guint            width;
  guint            height;
  guint            rowstride;
  CoglPixelFormat  format;
  gint             size;
  guchar          *data;
  gint             x,y,t;
  guchar          *pixel;
  
  self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self);
  
  /* Load image from file */
  
  priv->cogl_tex_id[0] =
    cogl_texture_new_from_file ("redhand.png", 40, FALSE,
                                COGL_PIXEL_FORMAT_ANY, NULL);
  
  if (priv->cogl_tex_id[0] == COGL_INVALID_HANDLE)
    {
      printf ("Failed loading redhand.png image!\n");
      return;
    }
  
  printf("Texture loaded from file.\n");
  
  /* Obtain pixel data */
  
  format = cogl_texture_get_format (priv->cogl_tex_id[0]);
  g_assert(format == COGL_PIXEL_FORMAT_RGBA_8888 ||
           format == COGL_PIXEL_FORMAT_ARGB_8888);

  width = cogl_texture_get_width (priv->cogl_tex_id[0]);
  height = cogl_texture_get_height (priv->cogl_tex_id[0]);
  size = cogl_texture_get_data (priv->cogl_tex_id[0],
				format, 0, NULL);
  
  printf("size: %dx%d\n", width, height);
  printf("format: 0x%x\n", format);
  printf("bytesize: %d\n", size);
  
  data = (guchar*) g_malloc (sizeof(guchar) * size);
  
  cogl_texture_get_data (priv->cogl_tex_id[0],
			 format, 0, data);
  rowstride = cogl_texture_get_rowstride (priv->cogl_tex_id[0]);
  
  /* Create new texture from modified data */
  
  priv->cogl_tex_id[1] =
    cogl_texture_new_from_data (width, height, 0, FALSE,
                                format, format,
				rowstride, data);
  
  if (priv->cogl_tex_id[1] == COGL_INVALID_HANDLE)
    {
      printf ("Failed creating image from data!\n");
      return;
    }
  
  printf ("Texture created from data.\n");
  
  /* Modify data (swap red and green) */
  
  for (y=0; y<height; ++y)
    {
      for (x=0; x<width; ++x)
	{
	  pixel = data + y * rowstride + x * 4;
	  if (format == COGL_PIXEL_FORMAT_RGBA_8888)
	    {
	      t = pixel[0];
	      pixel[0] = pixel[1];
	      pixel[1] = t;
	    }
	  else
	    {
	      t = pixel[1];
	      pixel[1] = pixel[2];
	      pixel[2] = t;
	    }
	}
    }
  
  
  cogl_texture_set_region (priv->cogl_tex_id[1],
			   0, 0, 0, 0,
			   100, 100, width, height,
			   format, 0, data);
  
  cogl_texture_set_region (priv->cogl_tex_id[1],
			   100, 100, 100, 100,
			   100, 100, width, height,
			   format, 0, data);
  
  printf ("Subregion data updated.\n");
}