]> git.tdb.fi Git - libs/gl.git/blobdiff - source/ilwrap.cpp
Support embedding textures in datafiles
[libs/gl.git] / source / ilwrap.cpp
index be8442bee741a325199a4f45865a86bbbcea549c..a1ae1631776539ec5d2be163af3e8f86ced48549 100644 (file)
@@ -9,11 +9,15 @@ Distributed under the LGPL
 #include <msp/core/except.h>
 #include "ilwrap.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
 Image::Image()
 {
+       static bool init_done=false;
+
        if(!init_done)
        {
                ilInit();
@@ -30,13 +34,20 @@ Image::~Image()
        ilDeleteImages(1, &id);
 }
 
-void Image::load(const std::string &fn)
+void Image::load_file(const string &fn)
 {
        ilBindImage(id);
        if(!ilLoadImage(const_cast<char *>(fn.c_str())))
                throw Exception("Error loading image "+fn);
 }
 
+void Image::load_lump(const void *data, unsigned size)
+{
+       ilBindImage(id);
+       if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
+               throw Exception("Error loading image from lump");
+}
+
 PixelFormat Image::get_format() const
 {
        switch(ilGetInteger(IL_IMAGE_FORMAT))
@@ -67,7 +78,5 @@ const void *Image::get_data() const
        return ilGetData();
 }
 
-bool Image::init_done=false;
-
 } // namespace GL
 } // namespace Msp