version 1.5 | | version 1.6 |
---|
| | |
pv.y+=height; | | pv.y+=height; |
break; | | break; |
case 1: | | case 1: |
glTexCoord2f(1.0, 0.0); | | glTexCoord2f(bm->glu, 0.0); |
pv.x+=width; | | pv.x+=width; |
pv.y+=height; | | pv.y+=height; |
break; | | break; |
case 2: | | case 2: |
glTexCoord2f(1.0, 1.0); | | glTexCoord2f(bm->glu, bm->glv); |
pv.x+=width; | | pv.x+=width; |
pv.y+=-height; | | pv.y+=-height; |
break; | | break; |
case 3: | | case 3: |
glTexCoord2f(0.0, 1.0); | | glTexCoord2f(0.0, bm->glv); |
pv.x+=-width; | | pv.x+=-width; |
pv.y+=-height; | | pv.y+=-height; |
break; | | break; |
| | |
glBegin(GL_QUADS); | | glBegin(GL_QUADS); |
glColor3f(1.5,1.5,1.5); | | glColor3f(1.5,1.5,1.5); |
glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo); | | glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo); |
glTexCoord2f(1.0, 0.0); glVertex2f(xo+xs, yo); | | glTexCoord2f(bm->glu, 0.0); glVertex2f(xo+xs, yo); |
glTexCoord2f(1.0, 1.0); glVertex2f(xo+xs, yo-ys); | | glTexCoord2f(bm->glu, bm->glv); glVertex2f(xo+xs, yo-ys); |
glTexCoord2f(0.0, 1.0); glVertex2f(xo, yo-ys); | | glTexCoord2f(0.0, bm->glv); glVertex2f(xo, yo-ys); |
glEnd(); | | glEnd(); |
glDisable(GL_TEXTURE_2D); | | glDisable(GL_TEXTURE_2D); |
// glDisable(GL_ALPHA_TEST); | | // glDisable(GL_ALPHA_TEST); |
| | |
// glClear(GL_COLOR_BUFFER_BIT); | | // glClear(GL_COLOR_BUFFER_BIT); |
} | | } |
| | |
| | //little hack to find the largest or equal multiple of 2 for a given number |
| | int pow2ize(int x){ |
| | int i; |
| | for (i=2;i<=4096;i*=2) |
| | if (x<=i) return i; |
| | return i; |
| | } |
| | |
GLubyte texbuf[512*512*4]; | | GLubyte texbuf[512*512*4]; |
void ogl_loadtexture(unsigned char * data, int width, int height, int *texid){ | | void ogl_loadtexture(unsigned char * data, int width, int height, int *texid,float *u,float *v){ |
int i,c; | | int x,y,c,i; |
// GLubyte *texbuf; | | |
GLubyte *texp=texbuf; | | GLubyte *texp=texbuf; |
// texbuf=(GLubyte*)malloc(width*height*4); | | int twidth=pow2ize(width),theight=pow2ize(height);//calculate smallest texture size that can accomodate us (must be multiples of 2) |
// texp=texbuf; | | |
if (width*height>sizeof(texbuf)) | | if (twidth*theight*4>sizeof(texbuf))//shouldn't happen, descent never uses textures that big. |
Error("toobig"); | | Error("texture toobig"); |
for (i=0;i<width*height;i++){ | | |
c=data[i]; | | //calculate u/v values that would make the resulting texture correctly sized |
| | *u=(float)width/(float)twidth; |
| | *v=(float)height/(float)theight; |
| | |
| | // if (width!=twidth || height!=theight) |
| | // mprintf((0,"sizing %ix%i texture up to %ix%i\n",width,height,twidth,theight)); |
| | i=0; |
| | for (y=0;y<theight;y++){ |
| | for (x=0;x<twidth;x++){ |
| | if (x<width && y<height) |
| | c=data[i++]; |
| | else |
| | c=255;//fill the pad space with transparancy |
if (c==255){ | | if (c==255){ |
(*(texp++))=0; | | (*(texp++))=0; |
(*(texp++))=0; | | (*(texp++))=0; |
| | |
(*(texp++))=255;//not transparent | | (*(texp++))=255;//not transparent |
} | | } |
} | | } |
| | } |
| | |
// glEnable(GL_TEXTURE_2D); | | // glEnable(GL_TEXTURE_2D); |
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | | // glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| | |
width, height, 0, GL_RGBA, | | width, height, 0, GL_RGBA, |
GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. | | GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. |
texbuf);*/ | | texbuf);*/ |
gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, | | gluBuild2DMipmaps( GL_TEXTURE_2D, 4, twidth, |
height, GL_RGBA, GL_UNSIGNED_BYTE, texbuf); | | theight, GL_RGBA, GL_UNSIGNED_BYTE, texbuf); |
r_texcount++; | | r_texcount++; |
mprintf((0,"ogl_loadtexture(%p,%i,%i,%p):%i (%i)\n",data,width,height,texid,*texid,r_texcount)); | | mprintf((0,"ogl_loadtexture(%p,%i,%i,%p):%i u=%f v=%f (%i)\n",data,twidth,theight,texid,*texid,*u,*v,r_texcount)); |
| | |
} | | } |
unsigned char decodebuf[512*512]; | | unsigned char decodebuf[512*512]; |
| | |
} | | } |
buf=decodebuf; | | buf=decodebuf; |
} | | } |
ogl_loadtexture(buf,bm->bm_w,bm->bm_h,&bm->gltexture); | | ogl_loadtexture(buf,bm->bm_w,bm->bm_h,&bm->gltexture,&bm->glu,&bm->glv); |
} | | } |
void ogl_freebmtexture(grs_bitmap *bm){ | | void ogl_freebmtexture(grs_bitmap *bm){ |
if (bm->gltexture>=0){ | | if (bm->gltexture>=0){ |