version 1.41 | | version 1.42 |
---|
| | |
#include <GL/glu.h> | | #include <GL/glu.h> |
#include <string.h> | | #include <string.h> |
#include <math.h> | | #include <math.h> |
| | #include <stdio.h> |
#include "3d.h" | | #include "3d.h" |
#include "piggy.h" | | #include "piggy.h" |
#include "../../3d/globvars.h" | | #include "../../3d/globvars.h" |
| | |
#include "palette.h" | | #include "palette.h" |
#include "rle.h" | | #include "rle.h" |
#include "mono.h" | | #include "mono.h" |
| | #include "pngfile.h" |
| | |
#include "segment.h" | | #include "segment.h" |
#include "textures.h" | | #include "textures.h" |
| | |
| | |
// oldpal=ogl_pal; | | // oldpal=ogl_pal; |
ogl_pal=gr_current_pal; | | ogl_pal=gr_current_pal; |
ogl_loadtexture(src->bm_data,sx,sy,&tex,src->bm_flags); | | ogl_loadtexture(src->bm_data,sx,sy,&tex,src->bm_flags,0); |
// ogl_pal=oldpal; | | // ogl_pal=oldpal; |
ogl_pal=gr_palette; | | ogl_pal=gr_palette; |
OGL_BINDTEXTURE(tex.handle); | | OGL_BINDTEXTURE(tex.handle); |
| | |
| | |
//GLubyte texbuf[512*512*4]; | | //GLubyte texbuf[512*512*4]; |
GLubyte texbuf[OGLTEXBUFSIZE]; | | GLubyte texbuf[OGLTEXBUFSIZE]; |
void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight,int type, int bm_flags) | | void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight,int type, int bm_flags, int data_format) |
{ | | { |
// GLushort *tex=(GLushort *)texp; | | // GLushort *tex=(GLushort *)texp; |
int x,y,c,i; | | int x,y,c,i; |
| | |
i=dxo+truewidth*(y+dyo); | | i=dxo+truewidth*(y+dyo); |
for (x=0;x<twidth;x++){ | | for (x=0;x<twidth;x++){ |
if (x<width && y<height) | | if (x<width && y<height) |
| | if (data_format) { |
| | int j; |
| | for (j=0;j<data_format;++j) |
| | (*(texp++))=data[i*data_format+j]; |
| | i++; |
| | continue; |
| | }else |
c=data[i++]; | | c=data[i++]; |
else | | else |
c=256;//fill the pad space with transparancy (or blackness) | | c=256;//fill the pad space with transparancy (or blackness) |
| | |
//In theory this could be a problem for repeating textures, but all real | | //In theory this could be a problem for repeating textures, but all real |
//textures (not sprites, etc) in descent are 64x64, so we are ok. | | //textures (not sprites, etc) in descent are 64x64, so we are ok. |
//stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v | | //stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v |
void ogl_loadtexture(unsigned char * data, int dxo,int dyo, ogl_texture *tex, int bm_flags){ | | void ogl_loadtexture(unsigned char * data, int dxo,int dyo, ogl_texture *tex, int bm_flags, int data_format){ |
//void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,int dyo, int *texid,float *u,float *v,char domipmap,float prio){ | | //void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,int dyo, int *texid,float *u,float *v,char domipmap,float prio){ |
// int internalformat=GL_RGBA; | | // int internalformat=GL_RGBA; |
// int format=GL_RGBA; | | // int format=GL_RGBA; |
| | |
tex->v=(float)tex->h/(float)tex->th; | | tex->v=(float)tex->h/(float)tex->th; |
| | |
#ifdef GL_EXT_paletted_texture | | #ifdef GL_EXT_paletted_texture |
if (ogl_shared_palette_ok && (tex->format==GL_RGBA || tex->format==GL_RGB) && | | if (ogl_shared_palette_ok && data_format==0 && (tex->format==GL_RGBA || tex->format==GL_RGB) && |
!(tex->wantmip && GL_needmipmaps) // gluBuild2DMipmaps doesn't support paletted textures.. this could be worked around be generating our own mipmaps, but thats too much trouble at the moment. | | !(tex->wantmip && GL_needmipmaps) // gluBuild2DMipmaps doesn't support paletted textures.. this could be worked around be generating our own mipmaps, but thats too much trouble at the moment. |
) { | | ) { |
//descent makes palette entries 254 and 255 both do double duty, depending upon the setting of BM_FLAG_SUPER_TRANSPARENT and BM_FLAG_TRANSPARENT. | | //descent makes palette entries 254 and 255 both do double duty, depending upon the setting of BM_FLAG_SUPER_TRANSPARENT and BM_FLAG_TRANSPARENT. |
| | |
| | |
// if (width!=twidth || height!=theight) | | // if (width!=twidth || height!=theight) |
// glmprintf((0,"sizing %ix%i texture up to %ix%i\n",width,height,twidth,theight)); | | // glmprintf((0,"sizing %ix%i texture up to %ix%i\n",width,height,twidth,theight)); |
ogl_filltexbuf(data,texbuf,tex->lw,tex->w,tex->h,dxo,dyo,tex->tw,tex->th,tex->format,bm_flags); | | ogl_filltexbuf(data,texbuf,tex->lw,tex->w,tex->h,dxo,dyo,tex->tw,tex->th,tex->format,bm_flags,data_format); |
| | |
// Generate OpenGL texture IDs. | | // Generate OpenGL texture IDs. |
glGenTextures(1, &tex->handle); | | glGenTextures(1, &tex->handle); |
| | |
unsigned char decodebuf[512*512]; | | unsigned char decodebuf[512*512]; |
void ogl_loadbmtexture_f(grs_bitmap *bm, int flags){ | | void ogl_loadbmtexture_f(grs_bitmap *bm, int flags){ |
unsigned char *buf; | | unsigned char *buf; |
| | char *bitmapname; |
while (bm->bm_parent) | | while (bm->bm_parent) |
bm=bm->bm_parent; | | bm=bm->bm_parent; |
| | if (bm->gltexture && bm->gltexture->handle>0) |
| | return; |
buf=bm->bm_data; | | buf=bm->bm_data; |
| | if ((bitmapname=piggy_game_bitmap_name(bm))){ |
| | char filename[64]; |
| | png_data pdata; |
| | |
| | sprintf(filename, "textures/%s.png", bitmapname); |
| | if (read_png(filename, &pdata)) { |
| | printf("%s: %ux%ux%i p=%i(%i) c=%i a=%i chans=%i\n",filename, pdata.width, pdata.height, pdata.depth, pdata.paletted, pdata.num_palette, pdata.color, pdata.alpha, pdata.channels); |
| | if (pdata.depth==8 && pdata.color) { |
| | if (bm->gltexture==NULL) |
| | ogl_init_texture(bm->gltexture=ogl_get_free_texture(), pdata.width, pdata.height, flags | ((pdata.alpha)?OGL_FLAG_ALPHA:0)); |
| | ogl_loadtexture(pdata.data,0,0,bm->gltexture,bm->bm_flags,pdata.paletted?0:pdata.channels); |
| | free(pdata.data); |
| | if (pdata.palette) |
| | free(pdata.palette); |
| | return; |
| | } else { |
| | printf("%s: unsupported texture format: must be rgb, rgba, or paletted, and depth 8\n",filename); |
| | free(pdata.data); |
| | if (pdata.palette) |
| | free(pdata.palette); |
| | } |
| | } |
| | } |
if (bm->gltexture==NULL){ | | if (bm->gltexture==NULL){ |
ogl_init_texture(bm->gltexture=ogl_get_free_texture(), bm->bm_w, bm->bm_h, flags | ((bm->bm_flags&BM_FLAG_TRANSPARENT)?OGL_FLAG_ALPHA:0)); | | ogl_init_texture(bm->gltexture=ogl_get_free_texture(), bm->bm_w, bm->bm_h, flags | ((bm->bm_flags&BM_FLAG_TRANSPARENT)?OGL_FLAG_ALPHA:0)); |
} | | } |
| | |
} | | } |
buf=decodebuf; | | buf=decodebuf; |
} | | } |
ogl_loadtexture(buf,0,0,bm->gltexture,bm->bm_flags); | | ogl_loadtexture(buf,0,0,bm->gltexture,bm->bm_flags,0); |
} | | } |
void ogl_loadbmtexture(grs_bitmap *bm){ | | void ogl_loadbmtexture(grs_bitmap *bm){ |
ogl_loadbmtexture_f(bm, OGL_FLAG_MIPMAP); | | ogl_loadbmtexture_f(bm, OGL_FLAG_MIPMAP); |