]> git.tdb.fi Git - libs/gltk.git/commitdiff
Restore ability to handle raw image files
authorMikko Rasa <tdb@tdb.fi>
Wed, 16 Jan 2013 16:53:58 +0000 (18:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 16 Jan 2013 17:01:40 +0000 (19:01 +0200)
source/resources.cpp
source/resources.h

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),
index e68d89fc178c16e79f20aaae6c262920077ec8f3..77987e88c29ad8a023c8adc7f6b6f9c98410aae6 100644 (file)
@@ -38,6 +38,9 @@ public:
        Resources();
 
        const GL::Font &get_default_font() const;
+
+private:
+       GL::Texture2D *create_texture(const std::string &);
 };
 
 } // namespace GLtk