2 #ifndef __SG_TEXTURE_HXX
3 #define __SG_TEXTURE_HXX 1
15 GLubyte *texture_data;
17 GLsizei texture_width;
18 GLsizei texture_height;
20 void resize(unsigned int width = 256, unsigned int height = 256);
24 typedef struct _ImageRec {
25 unsigned short imagic;
28 unsigned short xsize, ysize, zsize;
29 unsigned int min, max;
30 unsigned int wasteBytes;
32 unsigned long colorMap;
36 unsigned int *rowStart;
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);
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);
52 SGTexture(unsigned int width, unsigned int height);
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);
61 inline bool usable() { return texture_data ? true : false; }
63 inline GLuint id() { return texture_id; }
64 inline GLubyte *texture() { return texture_data; }
66 inline int width() { return texture_width; }
67 inline int height() { return texture_height; }
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);
76 // texture pixel manipulation functions.
77 void set_pixel(GLuint x, GLuint y, sgVec3 &c);
78 sgVec3 *get_pixel(GLuint x, GLuint y);
81 inline void select() {
83 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
84 texture_width, texture_height, 0,
85 GL_RGB, GL_UNSIGNED_BYTE, texture_data );