| version 1.11 | | version 1.12 |
|---|
| | |
| #include "powerup.h" | | #include "powerup.h" |
| #include "polyobj.h" | | #include "polyobj.h" |
| | | |
| | | unsigned char *ogl_pal=gr_palette; |
| | | |
| int GL_texmagfilt=GL_NEAREST; | | int GL_texmagfilt=GL_NEAREST; |
| int GL_texminfilt=GL_NEAREST; | | int GL_texminfilt=GL_NEAREST; |
| | |
| mprintf((0,"finished caching\n")); | | mprintf((0,"finished caching\n")); |
| } | | } |
| | | |
| int r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc; | | int r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc,r_ubitbltc,r_upixelc; |
| int r_texcount=0; | | int r_texcount=0; |
| #define f2glf(x) (f2fl(x)) | | #define f2glf(x) (f2fl(x)) |
| /* | | |
| bool g3_draw_line(g3s_point *p0,g3s_point *p1) | | bool g3_draw_line(g3s_point *p0,g3s_point *p1) |
| { | | { |
| int c; | | int c; |
| | | |
| if (p0->p3_codes & p1->p3_codes) | | |
| return 0; | | |
| | | |
| // r_polyc++; | | |
| c=grd_curcanv->cv_color; | | c=grd_curcanv->cv_color; |
| | | OGL_DISABLE(GL_TEXTURE_2D); |
| glColor3f(PAL2Tr(c),PAL2Tg(c),PAL2Tb(c)); | | glColor3f(PAL2Tr(c),PAL2Tg(c),PAL2Tb(c)); |
| glBegin(GL_LINES); | | glBegin(GL_LINES); |
| glVertex2f(p0->p3_sx/(float)grd_curscreen->sc_w,p0->p3_sy/(float)grd_curscreen->sc_h); | | glVertex3f(f2glf(p0->p3_vec.x),f2glf(p0->p3_vec.y),-f2glf(p0->p3_vec.z)); |
| glVertex2f(p1->p3_sx/(float)grd_curscreen->sc_w,p1->p3_sy/(float)grd_curscreen->sc_h); | | glVertex3f(f2glf(p1->p3_vec.x),f2glf(p1->p3_vec.y),-f2glf(p1->p3_vec.z)); |
| glEnd(); | | glEnd(); |
| return 1; | | return 1; |
| } | | } |
| */ | | |
| /* | | |
| int g3_draw_sphere(g3s_point *pnt,fix rad){ | | int g3_draw_sphere(g3s_point *pnt,fix rad){ |
| if (! (pnt->p3_codes & CC_BEHIND)) { | | int c; |
| if (! (pnt->p3_flags & PF_PROJECTED)) | | c=grd_curcanv->cv_color; |
| g3_project_point(pnt); | | OGL_DISABLE(GL_TEXTURE_2D); |
| } | | glPointSize(f2glf(rad)); |
| | | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |
| | | glBegin(GL_POINTS); |
| | | glVertex3f(f2glf(pnt->p3_vec.x),f2glf(pnt->p3_vec.y),-f2glf(pnt->p3_vec.z)); |
| | | glEnd(); |
| return 0; | | return 0; |
| | | |
| }*/ | | } |
| | | |
| bool g3_draw_poly(int nv,g3s_point **pointlist) | | bool g3_draw_poly(int nv,g3s_point **pointlist) |
| { | | { |
| int c; | | int c; |
| | |
| r_tpolyc++; | | r_tpolyc++; |
| /* if (bm->bm_w !=64||bm->bm_h!=64) | | /* if (bm->bm_w !=64||bm->bm_h!=64) |
| printf("g3_draw_tmap w %i h %i\n",bm->bm_w,bm->bm_h);*/ | | printf("g3_draw_tmap w %i h %i\n",bm->bm_w,bm->bm_h);*/ |
| //glEnable(GL_TEXTURE_2D); | | |
| OGL_ENABLE(GL_TEXTURE_2D); | | OGL_ENABLE(GL_TEXTURE_2D); |
| if (bm->gltexture<0) | | if (bm->gltexture<0) |
| ogl_loadbmtexture(bm); | | ogl_loadbmtexture(bm); |
| glBindTexture(GL_TEXTURE_2D, bm->gltexture); | | glBindTexture(GL_TEXTURE_2D, bm->gltexture); |
| // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | | |
| // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | | |
| OGL_TEXREPEAT(); | | OGL_TEXREPEAT(); |
| glBegin(GL_TRIANGLE_FAN); | | glBegin(GL_TRIANGLE_FAN); |
| for (c=0;c<nv;c++){ | | for (c=0;c<nv;c++){ |
| | |
| glVertex3f(f2glf(pointlist[c]->p3_vec.x),f2glf(pointlist[c]->p3_vec.y),-f2glf(pointlist[c]->p3_vec.z)); | | glVertex3f(f2glf(pointlist[c]->p3_vec.x),f2glf(pointlist[c]->p3_vec.y),-f2glf(pointlist[c]->p3_vec.z)); |
| } | | } |
| glEnd(); | | glEnd(); |
| // glDisable(GL_TEXTURE_2D); | | |
| return 0; | | return 0; |
| } | | } |
| | | |
| | |
| // printf("g3_draw_bitmap: %f,%f,%f - ",f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); | | // printf("g3_draw_bitmap: %f,%f,%f - ",f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); |
| // printf("(%f,%f,%f) ",f2glf(View_position.x),f2glf(View_position.y),-f2glf(View_position.z)); | | // printf("(%f,%f,%f) ",f2glf(View_position.x),f2glf(View_position.y),-f2glf(View_position.z)); |
| | | |
| //glEnable(GL_TEXTURE_2D); | | |
| OGL_ENABLE(GL_TEXTURE_2D); | | OGL_ENABLE(GL_TEXTURE_2D); |
| if (bm->gltexture<0) | | if (bm->gltexture<0) |
| ogl_loadbmtexture(bm); | | ogl_loadbmtexture(bm); |
| glBindTexture(GL_TEXTURE_2D, bm->gltexture); | | glBindTexture(GL_TEXTURE_2D, bm->gltexture); |
| | | |
| //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | | |
| //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | | |
| OGL_TEXCLAMP(); | | OGL_TEXCLAMP(); |
| | | |
| glBegin(GL_QUADS); | | glBegin(GL_QUADS); |
| | |
| // printf("%f,%f,%f ",f2glf(v1.x),f2glf(v1.y),-f2glf(v1.z)); | | // printf("%f,%f,%f ",f2glf(v1.x),f2glf(v1.y),-f2glf(v1.z)); |
| } | | } |
| glEnd(); | | glEnd(); |
| // glDisable(GL_TEXTURE_2D); | | |
| // printf("\n"); | | // printf("\n"); |
| | | |
| return 0; | | return 0; |
| } | | } |
| bool ogl_ubitmapm_c(int x, int y,grs_bitmap *bm,int c) | | bool ogl_ubitmapm_c(int x, int y,grs_bitmap *bm,int c) |
| { | | { |
| GLfloat xo,yo,xs,ys; | | GLfloat xo,yo,xf,yf; |
| r_ubitmapc++; | | r_ubitmapc++; |
| | | x+=grd_curcanv->cv_bitmap.bm_x; |
| | | y+=grd_curcanv->cv_bitmap.bm_y; |
| xo=x/(float)last_width; | | xo=x/(float)last_width; |
| xs=bm->bm_w/(float)last_width; | | xf=(bm->bm_w+x)/(float)last_width; |
| yo=1.0-y/(float)last_height; | | yo=1.0-y/(float)last_height; |
| ys=bm->bm_h/(float)last_height; | | yf=1.0-(bm->bm_h+y)/(float)last_height; |
| // printf("g3_draw_bitmap: %f,%f,%f - ",f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); | | // printf("g3_draw_bitmap: %f,%f,%f - ",f2glf(pos->x),f2glf(pos->y),-f2glf(pos->z)); |
| // printf("(%f,%f,%f) ",f2glf(View_position.x),f2glf(View_position.y),-f2glf(View_position.z)); | | // printf("(%f,%f,%f) ",f2glf(View_position.x),f2glf(View_position.y),-f2glf(View_position.z)); |
| | | |
| | |
| glAlphaFunc(GL_GREATER,0.0);*/ | | glAlphaFunc(GL_GREATER,0.0);*/ |
| | | |
| OGL_ENABLE(GL_TEXTURE_2D); | | OGL_ENABLE(GL_TEXTURE_2D); |
| //glEnable(GL_TEXTURE_2D); | | |
| if (bm->gltexture<0) | | if (bm->gltexture<0) |
| ogl_loadbmtexture(bm); | | ogl_loadbmtexture(bm); |
| glBindTexture(GL_TEXTURE_2D, bm->gltexture); | | glBindTexture(GL_TEXTURE_2D, bm->gltexture); |
| | | |
| // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | | |
| // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | | |
| OGL_TEXCLAMP(); | | OGL_TEXCLAMP(); |
| | | |
| glBegin(GL_QUADS); | | glBegin(GL_QUADS); |
| if (c<0) | | if (c<0) |
| glColor3f(1.0,1.0,1.0); | | glColor3f(1.0,1.0,1.0); |
| else | | else |
| glColor3f(PAL2Tr(c),PAL2Tg(c),PAL2Tb(c)); | | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |
| glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo); | | glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo); |
| glTexCoord2f(bm->glu, 0.0); glVertex2f(xo+xs, yo); | | glTexCoord2f(bm->glu, 0.0); glVertex2f(xf, yo); |
| glTexCoord2f(bm->glu, bm->glv); glVertex2f(xo+xs, yo-ys); | | glTexCoord2f(bm->glu, bm->glv); glVertex2f(xf, yf); |
| glTexCoord2f(0.0, bm->glv); glVertex2f(xo, yo-ys); | | glTexCoord2f(0.0, bm->glv); glVertex2f(xo, yf); |
| glEnd(); | | glEnd(); |
| // glDisable(GL_TEXTURE_2D); | | |
| // glDisable(GL_ALPHA_TEST); | | // glDisable(GL_ALPHA_TEST); |
| | | |
| return 0; | | return 0; |
| | |
| bool ogl_ubitmapm(int x, int y,grs_bitmap *bm){ | | bool ogl_ubitmapm(int x, int y,grs_bitmap *bm){ |
| return ogl_ubitmapm_c(x,y,bm,-1); | | return ogl_ubitmapm_c(x,y,bm,-1); |
| } | | } |
| | | #if 0 |
| | | //also upsidedown, currently. |
| | | bool ogl_ubitblt_notrans(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest) |
| | | { |
| | | GLfloat xo,yo,xs,ys; |
| | | |
| | | xo=dx/(float)last_width; |
| | | xs=w/(float)last_width; |
| | | //yo=1.0-dy/(float)last_height; |
| | | yo=dy/(float)last_height; |
| | | ys=h/(float)last_height; |
| | | |
| | | // OGL_ENABLE(GL_TEXTURE_2D); |
| | | |
| | | OGL_DISABLE(GL_TEXTURE_2D); |
| | | glRasterPos2f(xo,yo); |
| | | ogl_filltexbuf(src->bm_data,texbuf,src->bm_w,w,h,sx,sy,w,h); |
| | | glDrawPixels(w,h,GL_RGBA,GL_UNSIGNED_BYTE,texbuf); |
| | | glRasterPos2f(0,0); |
| | | |
| | | return 0; |
| | | } |
| | | #endif |
| | | bool ogl_ubitblt(int w,int h,int dx,int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest) |
| | | { |
| | | // r_ubitbltc++; |
| | | // return 0; |
| | | //#if 0 |
| | | GLfloat xo,yo,xs,ys; |
| | | GLfloat u1,v1,u2,v2; |
| | | int gltexture=0; |
| | | // unsigned char *oldpal; |
| | | r_ubitbltc++; |
| | | |
| | | /* if (w==src->bm_w && sx==0){ |
| | | u1=0;u2=src->glu; |
| | | }else{ |
| | | u1=sx/(float)src->bm_w*src->glu; |
| | | u2=w/(float)src->bm_w*src->glu+u1; |
| | | } |
| | | if (h==src->bm_h && sy==0){ |
| | | v1=0;v2=src->glv; |
| | | }else{ |
| | | v1=sy/(float)src->bm_h*src->glv; |
| | | v2=h/(float)src->bm_h*src->glv+v1; |
| | | }*/ |
| | | u1=v1=0; |
| | | |
| | | dx+=grd_curcanv->cv_bitmap.bm_x; |
| | | dy+=grd_curcanv->cv_bitmap.bm_y; |
| | | xo=dx/(float)last_width; |
| | | xs=w/(float)last_width; |
| | | yo=1.0-dy/(float)last_height; |
| | | ys=h/(float)last_height; |
| | | |
| | | OGL_ENABLE(GL_TEXTURE_2D); |
| | | |
| | | // if (src->gltexture<0) |
| | | // oldpal=ogl_pal; |
| | | ogl_pal=gr_current_pal; |
| | | ogl_loadtexture(src->bm_data,w,h,sx,sy,&gltexture,&u2,&v2,0); |
| | | // ogl_pal=oldpal; |
| | | ogl_pal=gr_palette; |
| | | // ogl_loadbmtexture(src); |
| | | // else |
| | | // alreadygl=1; |
| | | glBindTexture(GL_TEXTURE_2D, gltexture); |
| | | |
| | | OGL_TEXCLAMP(); |
| | | |
| | | glBegin(GL_QUADS); |
| | | glColor3f(1.0,1.0,1.0); |
| | | glTexCoord2f(u1, v1); glVertex2f(xo, yo); |
| | | glTexCoord2f(u2, v1); glVertex2f(xo+xs, yo); |
| | | glTexCoord2f(u2, v2); glVertex2f(xo+xs, yo-ys); |
| | | glTexCoord2f(u1, v2); glVertex2f(xo, yo-ys); |
| | | glEnd(); |
| | | // if(!alreadygl) |
| | | // ogl_freebmtexture(src); |
| | | ogl_freetexture(&gltexture); |
| | | return 0; |
| | | //#endif |
| | | } |
| | | |
| void ogl_start_frame(void){ | | void ogl_start_frame(void){ |
| r_polyc=0;r_tpolyc=0;r_bitmapc=0;r_ubitmapc=0; | | r_polyc=0;r_tpolyc=0;r_bitmapc=0;r_ubitmapc=0;r_ubitbltc=0;r_upixelc=0; |
| | | |
| OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,Canvas_width,Canvas_height); | | OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,Canvas_width,Canvas_height); |
| glClearColor(0.0, 0.0, 0.0, 0.0); | | glClearColor(0.0, 0.0, 0.0, 0.0); |
| | |
| // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | | // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| } | | } |
| void ogl_end_frame(void){ | | void ogl_end_frame(void){ |
| | | // OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,); |
| mprintf((0,"ogl_end_frame: rendered %i flat polys, %i tmapped polys, %i sprites, %i ubitmaps\n",r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc)); | | OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); |
| | | mprintf((0,"ogl_end_frame: %i polys, %i tmaps, %i sprites, %i bitmaps, %i bitblts, %i pixels\n",r_polyc,r_tpolyc,r_bitmapc,r_ubitmapc,r_ubitbltc,r_upixelc)); |
| // glViewport(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); | | // glViewport(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); |
| glMatrixMode(GL_PROJECTION); | | glMatrixMode(GL_PROJECTION); |
| glLoadIdentity();//clear matrix | | glLoadIdentity();//clear matrix |
| | |
| return i; | | return i; |
| } | | } |
| | | |
| GLubyte texbuf[512*512*4]; | | //GLubyte texbuf[512*512*4]; |
| //loads a palettized bitmap into a ogl RGBA texture. | | GLubyte texbuf[OGLTEXBUFSIZE]; |
| //Sizes and pads dimensions to multiples of 2 if necessary. | | void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight) |
| //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. | | |
| //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 width, int height, int *texid,float *u,float *v,int domipmap){ | | |
| int x,y,c,i; | | int x,y,c,i; |
| GLubyte *texp=texbuf; | | |
| int twidth=pow2ize(width),theight=pow2ize(height);//calculate smallest texture size that can accomodate us (must be multiples of 2) | | |
| | | |
| if (twidth*theight*4>sizeof(texbuf))//shouldn't happen, descent never uses textures that big. | | if (twidth*theight*4>sizeof(texbuf))//shouldn't happen, descent never uses textures that big. |
| Error("texture toobig"); | | Error("texture toobig %i %i",twidth,theight); |
| | | |
| //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; | | i=0; |
| for (y=0;y<theight;y++){ | | for (y=0;y<theight;y++){ |
| | | 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) |
| c=data[i++]; | | c=data[i++]; |
| | |
| (*(texp++))=0; | | (*(texp++))=0; |
| (*(texp++))=0;//transparent pixel | | (*(texp++))=0;//transparent pixel |
| }else{ | | }else{ |
| (*(texp++))=gr_palette[c*3]*4; | | //(*(texp++))=gr_palette[c*3]*4; |
| (*(texp++))=gr_palette[c*3+1]*4; | | //(*(texp++))=gr_palette[c*3+1]*4; |
| (*(texp++))=gr_palette[c*3+2]*4; | | //(*(texp++))=gr_palette[c*3+2]*4; |
| | | (*(texp++))=ogl_pal[c*3]*4; |
| | | (*(texp++))=ogl_pal[c*3+1]*4; |
| | | (*(texp++))=ogl_pal[c*3+2]*4; |
| (*(texp++))=255;//not transparent | | (*(texp++))=255;//not transparent |
| } | | } |
| } | | } |
| } | | } |
| | | } |
| | | //loads a palettized bitmap into a ogl RGBA texture. |
| | | //Sizes and pads dimensions to multiples of 2 if necessary. |
| | | //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. |
| | | //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 width, int height,int dxo,int dyo, int *texid,float *u,float *v,int domipmap){ |
| | | int twidth=pow2ize(width),theight=pow2ize(height);//calculate smallest texture size that can accomodate us (must be multiples of 2) |
| | | |
| | | //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)); |
| | | ogl_filltexbuf(data,texbuf,width,width,height,dxo,dyo,twidth,theight); |
| | | |
| // Generate OpenGL texture IDs. | | // Generate OpenGL texture IDs. |
| glGenTextures(1, texid); | | glGenTextures(1, texid); |
| | |
| GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. | | GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer. |
| texbuf); | | texbuf); |
| r_texcount++; | | 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)); | | mprintf((0,"ogl_loadtexture(%p,%i,%i,%ix%i,%p):%i u=%f v=%f (%i)\n",data,twidth,theight,dxo,dyo,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,&bm->glu,&bm->glv,domipmap); | | ogl_loadtexture(buf,bm->bm_w,bm->bm_h,0,0,&bm->gltexture,&bm->glu,&bm->glv,domipmap); |
| } | | } |
| void ogl_loadbmtexture(grs_bitmap *bm){ | | void ogl_loadbmtexture(grs_bitmap *bm){ |
| ogl_loadbmtexture_m(bm,1); | | ogl_loadbmtexture_m(bm,1); |
| | | } |
| | | void ogl_freetexture(int *gltexture){ |
| | | if (*gltexture>=0){ |
| | | r_texcount--; |
| | | mprintf((0,"ogl_freetexture(%p):%i (%i left)\n",gltexture,*gltexture,r_texcount)); |
| | | glDeleteTextures( 1, gltexture ); |
| | | *gltexture=-1; |
| | | } |
| } | | } |
| void ogl_freebmtexture(grs_bitmap *bm){ | | void ogl_freebmtexture(grs_bitmap *bm){ |
| if (bm->gltexture>=0){ | | if (bm->gltexture>=0){ |