]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/resources.cpp
Restore ability to handle raw image files
[libs/gltk.git] / source / resources.cpp
index 3e0f851d701e3b961a38b564a1280507861f0d77..045096e52dea7c31a55c872211cd781e276d3449 100644 (file)
@@ -10,7 +10,7 @@ Resources::Resources():
        default_font(0)
 {
        add_type<Graphic>().keyword("graphic");
-       add_type<GL::Texture2D>().keyword("texture");
+       add_type<GL::Texture2D>().keyword("texture").creator(&Resources::create_texture);
        add_type<GL::Font>().keyword("font");
        add_type<Style>().keyword("style");
 }
@@ -23,6 +23,23 @@ const GL::Font &Resources::get_default_font() const
        return *default_font;
 }
 
+GL::Texture2D *Resources::create_texture(const string &name)
+{
+       string ext = FS::extpart(name);
+       if(ext==".png" || ext==".jpg")
+       {
+               IO::Seekable *io = open_from_sources(name);
+               Graphics::Image image;
+               image.load_io(*io);
+               GL::Texture2D *tex = new GL::Texture2D;
+               tex->set_min_filter(GL::LINEAR);
+               tex->image(image);
+               return tex;
+       }
+       else
+               return 0;
+}
+
 
 Resources::Loader::Loader(Resources &r):
        Collection::Loader(r),