代码之家  ›  专栏  ›  技术社区  ›  user69969

杂波值如何加载纹理

  •  1
  • user69969  · 技术社区  · 11 年前

    我正在尝试加载一个文件夹图标作为纹理。我现在几乎什么都试过了,但由于某种原因我无法让它发挥作用

    我想 this thread 这正是我想要的,但它太先进了。我现在想要简单一点。

    出于某种原因,我不能 this 工作/翻译。

    这就是我最终得到的代码。现在不知道该怎么办。

    class nicholas
    {
    
    Gtk.Window window;
    GtkClutter.Embed clutter;
    Clutter.Rectangle r;
    Clutter.Texture t;
    
    public nicholas () 
    {
        window = new Gtk.Window ();
        clutter = new GtkClutter.Embed ();
        var stage = clutter.get_stage () as Clutter.Stage;
    
        stage.background_color = Clutter.Color.from_string ("black");
    
        var o = new     Cogl.Texture.from_file("/usr/share/icons/gnome/48x48/places/folder.png",     Cogl.TextureFlags.NONE, Cogl.PixelFormat.ANY);
        t = new Clutter.Texture.set_cogl_texture(o);
        t.x = 80;
        t.y = 80;
        stage.add_child (t);
    
        window.add (clutter);
        window.destroy.connect (Gtk.main_quit);
        window.set_default_size (500, 300);
        window.show_all ();
        }
        }
        public static void main (string [] args)
        {
        GtkClutter.init (ref args);
    
        nicholas nicholas = new nicholas ();
    
        Gtk.main ();
        }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   nemequ    11 年前

    我看不出Emmanuele的答案有什么太先进的地方,这里有一个Vala端口,有一些额外的代码可以实际使用 Clutter.Image 作为一个 Clutter.Actor 的内容:

    private static Clutter.Actor create_clutter_actor_from_file (string filename) throwsGLib.Error {
      Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file (filename);
      Clutter.Image image = new Clutter.Image ();
      image.set_data (pixbuf.get_pixels (),
                      pixbuf.has_alpha ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
                      pixbuf.width,
                      pixbuf.height,
                      pixbuf.rowstride);
      Clutter.Actor actor = new Clutter.Actor ();
      actor.content = image;
      actor.set_size (pixbuf.width, pixbuf.height);
      return actor;
    }