31 char *buf = (
char *) malloc(strlen(tfname)+1);
35 char *s = strrchr(buf,
'.');
41 s = strrchr(buf,
'_');
46 if (strncmp(s,
"_n", 4) == 0) {
53 s = strrchr((
char *)tfname,
'/');
59 if (strstr(s,
"shadow") != NULL) {
98 bool grLoadSGI(
const char *fname, ssgTextureInfo* info)
134 GLubyte *image =
new GLubyte [sgihdr->
xsize*sgihdr->
ysize*sgihdr->
zsize];
135 GLubyte *ptr = image;
137 unsigned char *rbuf =
new unsigned char[sgihdr->
xsize];
138 unsigned char *gbuf = (sgihdr->
zsize>1) ?
new unsigned char[sgihdr->
xsize] : (
unsigned char *) NULL ;
139 unsigned char *bbuf = (sgihdr->
zsize>2) ?
new unsigned char[sgihdr->
xsize] : (
unsigned char *) NULL ;
140 unsigned char *abuf = (sgihdr->
zsize>3) ?
new unsigned char[sgihdr->
xsize] : (
unsigned char *) NULL ;
142 for (
int y = 0 ;
y < sgihdr->
ysize ;
y++) {
145 switch (sgihdr->
zsize) {
148 for (x = 0; x < sgihdr->
xsize; x++) {
157 for (x = 0; x < sgihdr->
xsize; x++) {
168 for (x = 0; x < sgihdr->
xsize; x++) {
181 for (x = 0; x < sgihdr->
xsize; x++ ) {
199 info->width = sgihdr->
xsize;
200 info->height = sgihdr->
ysize;
201 info->depth = sgihdr->
zsize;
202 info->alpha = (sgihdr->
zsize == 2 || sgihdr->
zsize == 4);
213 bool grMakeMipMaps (GLubyte *image,
int xsize,
int ysize,
int zsize,
bool mipmap)
215 if (!((xsize & (xsize-1))==0) || !((ysize & (ysize-1))==0)) {
216 ulSetError ( UL_WARNING,
"Map is not a power-of-two in size!" ) ;
222 for (
int l = 0; l < 20; l++) {
230 for (lev = 0 ;((xsize >> (lev+1)) != 0 || (ysize >> (lev+1)) != 0); lev++) {
234 int w1 = xsize >> l1;
235 int h1 = ysize >> l1;
236 int w2 = xsize >> l2;
237 int h2 = ysize >> l2;
252 texels[l2] =
new GLubyte[w2*h2*zsize];
254 for (
int x2 = 0; x2 < w2; x2++) {
255 for (
int y2 = 0; y2 < h2; y2++) {
256 for (
int c = 0; c < zsize; c++) {
258 int x1_1 = (x1 + 1) % w1;
260 int y1_1 = (y1 + 1) % h1;
261 int t1 = texels[l1][(y1*w1 + x1)*zsize + c];
262 int t2 = texels[l1][(y1_1*w1 + x1)*zsize + c];
263 int t3 = texels[l1][(y1*w1 + x1_1)*zsize + c];
264 int t4 = texels[l1][(y1_1*w1 + x1_1)*zsize + c];
277 texels[l2][(y2*w2 + x2)*zsize + c] = a;
279 texels[l2][(y2*w2 + x2)*zsize + c] = ( t1 + t2 + t3 + t4 )/4;
286 texels[lev + 1] = NULL;
288 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
289 glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST);
294 GLint textureTargetFormat;
300 textureTargetFormat = GL_COMPRESSED_LUMINANCE_ARB;
304 textureTargetFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB;
308 textureTargetFormat = GL_COMPRESSED_RGB_ARB;
312 textureTargetFormat = GL_COMPRESSED_RGBA_ARB;
317 textureTargetFormat = zsize;
324 if (xsize > tlimit || ysize > tlimit) {
328 glTexImage2D(GL_PROXY_TEXTURE_2D, map_level, textureTargetFormat, xsize, ysize, FALSE ,
329 (zsize==1)?GL_LUMINANCE:
330 (zsize==2)?GL_LUMINANCE_ALPHA:
333 GL_UNSIGNED_BYTE, NULL);
335 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &ww);
342 for (
int l = 0; texels [l] != NULL; l++) {
343 texels [l] = texels[l+1];
346 if (xsize < 8 && ysize < 8) {
353 for (
int i = 0; texels[i] != NULL; i++) {
364 if (mipmap == TRUE || i == 0) {
365 glTexImage2D ( GL_TEXTURE_2D,
366 map_level, textureTargetFormat, w, h, FALSE ,
367 (zsize==1)?GL_LUMINANCE:
368 (zsize==2)?GL_LUMINANCE_ALPHA:
371 GL_UNSIGNED_BYTE, (GLvoid *) texels[i] ) ;
void getUserTextureMaxSize(int &result)
bool doMipMap(const char *tfname, int mipmap)
void grRegisterCustomSGILoader(void)
bool isCompressARBEnabled(void)
bool grLoadSGI(const char *fname, ssgTextureInfo *info)
bool grMakeMipMaps(GLubyte *image, int xsize, int ysize, int zsize, bool mipmap)