]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/texture.hxx
Frederic Bouvier:
[simgear.git] / simgear / screen / texture.hxx
index bb99b5c2dec5932db576d465d997efb8f99bd03d..5b7c777b72bbae1c4c04bd57b49db04e12fe5ef5 100644 (file)
@@ -13,7 +13,8 @@
 #ifndef __SG_TEXTURE_HXX
 #define __SG_TEXTURE_HXX 1
 
-#include <GL/gl.h>
+#include <simgear/compiler.h>
+#include SG_GL_H
 #include <zlib.h>
 
 #include <plib/sg.h>
@@ -31,6 +32,7 @@ private:
 
     GLsizei texture_width;
     GLsizei texture_height;
+    GLsizei num_colors;
 
     void resize(unsigned int width = 256, unsigned int height = 256);
 
@@ -55,6 +57,8 @@ protected:
     void ConvertUint(unsigned *array, unsigned int length);
     void ConvertShort(unsigned short *array, unsigned int length);
     void rgbtorgb(GLubyte *r, GLubyte *g, GLubyte *b, GLubyte *l, int n);
+    void rgbatorgba(GLubyte *r, GLubyte *g, GLubyte *b, GLubyte *a,
+                    GLubyte *l, int n);
 
     ImageRec *ImageOpen(const char *fileName);
     ImageRec *RawImageOpen(const char *fileName);
@@ -80,6 +84,7 @@ public:
     /* Copyright (c) Mark J. Kilgard, 1997.  */
     void read_alpha_texture(const char *name);
     void read_rgb_texture(const char *name);
+    void read_rgba_texture(const char *name);
     void read_raw_texture(const char *name);
     void read_r8_texture(const char *name);
 
@@ -105,9 +110,9 @@ public:
 
     void bind();
     inline void select(bool keep_data = false) {
-        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
+        glTexImage2D( GL_TEXTURE_2D, 0, num_colors,
                       texture_width, texture_height, 0,
-                      GL_RGB, GL_UNSIGNED_BYTE, texture_data );
+                      (num_colors==1)?GL_LUMINANCE:(num_colors==3)?GL_RGB:GL_RGBA, GL_UNSIGNED_BYTE, texture_data );
 
         if (!keep_data) {
             delete[] texture_data;
@@ -121,7 +126,7 @@ public:
     inline bool is_resident() {
         GLboolean is_res;
         glAreTexturesResident(1, &texture_id, &is_res);
-        return is_res;
+        return is_res != 0;
     }
 };