3 * Texture manipulation routines
5 * Copyright (c) Mark J. Kilgard, 1997.
6 * Code added in april 2003 by Erik Hofman
8 * This program is freely distributable without licensing fees
9 * and is provided without guarantee or warrantee expressed or
10 * implied. This program is -not- in the public domain.
13 #ifndef __SG_TEXTURE_HXX
14 #define __SG_TEXTURE_HXX 1
22 * A class to encapsulate all the info surrounding an OpenGL texture
23 * and also query various info and load various file formats
30 GLubyte *texture_data;
32 GLsizei texture_width;
33 GLsizei texture_height;
35 void resize(unsigned int width = 256, unsigned int height = 256);
39 typedef struct _ImageRec {
40 unsigned short imagic;
43 unsigned short xsize, ysize, zsize;
44 unsigned int min, max;
45 unsigned int wasteBytes;
47 unsigned long colorMap;
51 unsigned int *rowStart;
55 void ConvertUint(unsigned *array, unsigned int length);
56 void ConvertShort(unsigned short *array, unsigned int length);
57 void rgbtorgb(GLubyte *r, GLubyte *g, GLubyte *b, GLubyte *l, int n);
59 ImageRec *ImageOpen(const char *fileName);
60 ImageRec *RawImageOpen(const char *fileName);
61 void ImageClose(ImageRec *image);
62 void ImageGetRow(ImageRec *image, GLubyte *buf, int y, int z);
67 SGTexture(unsigned int width, unsigned int height);
70 /* Copyright (c) Mark J. Kilgard, 1997. */
71 void read_alpha_texture(const char *name);
72 void read_rgb_texture(const char *name);
73 void read_raw_texture(const char *name);
74 void read_r8_texture(const char *name);
76 inline bool usable() { return texture_data ? true : false; }
78 inline GLuint id() { return texture_id; }
79 inline GLubyte *texture() { return texture_data; }
81 inline int width() { return texture_width; }
82 inline int height() { return texture_height; }
84 // dynamic texture functions.
85 // everything drawn to the OpenGL screen after prepare is
86 // called and before finish is called will be included
87 // in the new texture.
88 void prepare(unsigned int width = 256, unsigned int height = 256);
89 void finish(unsigned int width, unsigned int height);
91 // texture pixel manipulation functions.
92 void set_pixel(GLuint x, GLuint y, sgVec3 &c);
93 sgVec3 *get_pixel(GLuint x, GLuint y);
96 inline void select() {
98 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
99 texture_width, texture_height, 0,
100 GL_RGB, GL_UNSIGNED_BYTE, texture_data );