]> git.mxchange.org Git - simgear.git/blob - simgear/screen/texture.hxx
Fixup for windows machines
[simgear.git] / simgear / screen / texture.hxx
1
2 #ifndef __SG_TEXTURE_HXX
3 #define __SG_TEXTURE_HXX 1
4
5 #include <GL/gl.h>
6 #include <zlib.h>
7
8 #include <plib/sg.h>
9
10 class SGTexture {
11
12 private:
13
14     GLuint texture_id;
15     GLubyte *texture_data;
16
17     GLsizei texture_width;
18     GLsizei texture_height;
19
20     void resize(unsigned int width = 256, unsigned int height = 256);
21
22 protected:
23
24     typedef struct _ImageRec {
25         unsigned short imagic;
26         unsigned short type;
27         unsigned short dim;
28         unsigned short xsize, ysize, zsize;
29         unsigned int min, max;
30         unsigned int wasteBytes;
31         char name[80];
32         unsigned long colorMap;
33         gzFile file;
34         GLubyte *tmp;
35         unsigned long rleEnd;
36         unsigned int *rowStart;
37         int *rowSize;
38     } ImageRec;
39
40     void ConvertUint(unsigned *array, unsigned int length);
41     void ConvertShort(unsigned short *array, unsigned int length);
42     void rgbtorgb(GLubyte *r, GLubyte *g, GLubyte *b, GLubyte *l, int n);
43
44     ImageRec *ImageOpen(const char *fileName);
45     ImageRec *RawImageOpen(const char *fileName);
46     void ImageClose(ImageRec *image);
47     void ImageGetRow(ImageRec *image, GLubyte *buf, int y, int z);
48
49 public:
50
51     SGTexture();
52     SGTexture(unsigned int width, unsigned int height);
53     ~SGTexture();
54
55     /* Copyright (c) Mark J. Kilgard, 1997.  */
56     void read_alpha_texture(const char *name);
57     void read_rgb_texture(const char *name);
58     void read_raw_texture(const char *name);
59     void read_r8_texture(const char *name);
60
61     inline bool usable() { return texture_data ? true : false; }
62
63     inline GLuint id() { return texture_id; }
64     inline GLubyte *texture() { return texture_data; }
65
66     inline int width() { return texture_width; }
67     inline int height() { return texture_height; }
68
69     // dynamic texture functions.
70     // everything drawn to the OpenGL screen after prepare is
71     // called and before finish is called will be included
72     // in the new texture.
73     void prepare(unsigned int width = 256, unsigned int height = 256);
74     void finish(unsigned int width, unsigned int height);
75
76     // texture pixel manipulation functions.
77     void set_pixel(GLuint x, GLuint y, sgVec3 &c);
78     sgVec3 *get_pixel(GLuint x, GLuint y);
79
80     void bind();
81     inline void select() {
82         // if (texture_data)
83             glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
84                           texture_width, texture_height, 0,
85                           GL_RGB, GL_UNSIGNED_BYTE, texture_data );
86     }
87 };
88
89 #endif
90