version 1.13 | | version 1.14 |
---|
| | |
#include "error.h" | | #include "error.h" |
| | |
#include "inferno.h" | | #include "inferno.h" |
| | #include "screens.h" |
| | |
#include "strutil.h" | | #include "strutil.h" |
#include "mono.h" | | #include "mono.h" |
#include "args.h" | | #include "args.h" |
| | #include "key.h" |
#include "ogl_init.h" | | #include "ogl_init.h" |
| | |
int gr_installed = 0; | | int gr_installed = 0; |
| | |
void gr_palette_clear(); // Function prototype for gr_init; | | void gr_palette_clear(); // Function prototype for gr_init; |
int gl_initialized=0; | | int gl_initialized=0; |
| | |
GLuint kludgetexture; | | |
unsigned char *kludgetexturedata=NULL; | | |
| | |
| | |
void ogl_init_state(void){ | | void ogl_init_state(void){ |
/* select clearing (background) color */ | | /* select clearing (background) color */ |
| | |
gr_palette_step_up(0,0,0);//in case its left over from in game | | gr_palette_step_up(0,0,0);//in case its left over from in game |
} | | } |
| | |
| | void ogl_swap_buffers(void){ |
| | ogl_do_palfx(); |
| | ogl_swap_buffers_internal(); |
| | glClear(GL_COLOR_BUFFER_BIT); |
| | } |
| | int last_screen_mode=-1; |
| | void ogl_set_screen_mode(void){ |
| | if (last_screen_mode==Screen_mode) |
| | return; |
| | OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); |
| | // OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h); |
| | if (Screen_mode==SCREEN_GAME){ |
| | glDrawBuffer(GL_BACK); |
| | }else{ |
| | glClearColor(0.0, 0.0, 0.0, 0.0); |
| | glDrawBuffer(GL_FRONT); |
| | glClear(GL_COLOR_BUFFER_BIT); |
| | glMatrixMode(GL_PROJECTION); |
| | glLoadIdentity();//clear matrix |
| | glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); |
| | glMatrixMode(GL_MODELVIEW); |
| | glLoadIdentity();//clear matrix |
| | glEnable(GL_BLEND); |
| | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| | } |
| | last_screen_mode=Screen_mode; |
| | } |
void gr_update() | | void gr_update() |
{ | | { |
if (gl_initialized){ | | if (gl_initialized){ |
| | |
if(Function_mode != FMODE_GAME){ | | if(Screen_mode != SCREEN_GAME){ |
int i,j; | | glFlush(); |
float kx = (32.0/(float)grd_curscreen->sc_w), | | |
ky = (32.0/(float)grd_curscreen->sc_h); | | |
| | |
ogl_init_state(); | | |
OGL_ENABLE(GL_TEXTURE_2D); | | |
// glEnable( GL_TEXTURE_2D ); | | |
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); | | |
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST ); | | |
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); | | |
// if wrap is true, the texture wraps over at the edges (repeat) | | |
// ... false, the texture ends at the edges (clamp) | | |
// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP ); | | |
// glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP ); | | |
OGL_TEXCLAMP(); | | |
| | |
glColor3f(1.0,1.0,1.0); | | |
for (i=0; i<grd_curscreen->sc_w/32; i++) { | | |
for (j=0; j<grd_curscreen->sc_h/32; j++) { | | |
int y,x,c,t; | | |
| | |
unsigned char*data=kludgetexturedata; | | |
t = j*32*grd_curscreen->sc_w+i*32; | | |
for (y=0;y<32;y++){ | | |
for (x=0;x<32; x++) { | | |
c=grd_curscreen->sc_canvas.cv_bitmap.bm_data[t+x]; | | |
*data=gr_palette[c*3]*4;data++; | | |
*data=gr_palette[c*3+1]*4;data++; | | |
*data=gr_palette[c*3+2]*4;data++; | | |
} | | |
t+=grd_curscreen->sc_w; | | |
} | | |
| | |
// select our current texture | | |
glBindTexture( GL_TEXTURE_2D, kludgetexture ); | | |
| | |
glTexImage2D( GL_TEXTURE_2D, 0, 3, 32, | | |
32, 0, GL_RGB, GL_UNSIGNED_BYTE, kludgetexturedata ); | | |
| | |
| | |
glBegin( GL_QUADS ); | | |
glTexCoord2d(0.0,0.0); glVertex2f(kx*(float)i,ky*(float)j); | | |
glTexCoord2d(1.0,0.0); glVertex2f(kx*(float)(i+1),ky*(float)j); | | |
glTexCoord2d(1.0,1.0); glVertex2f(kx*(float)(i+1),ky*(float)(j+1)); | | |
glTexCoord2d(0.0,1.0); glVertex2f(kx*(float)i,ky*(float)(j+1)); | | |
glEnd(); | | |
glDeleteTextures( 1, &kludgetexture ); | | |
} | | |
} | | |
// glDisable( GL_TEXTURE_2D ); | | |
| | |
| | |
ogl_swap_buffers();//platform specific code | | |
} | | } |
// else | | |
// ogl_swap_buffers();//platform specific code | | |
} | | } |
} | | } |
| | |
| | |
grd_curscreen->sc_canvas.cv_bitmap.bm_h = h; | | grd_curscreen->sc_canvas.cv_bitmap.bm_h = h; |
//grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch; | | //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch; |
grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w; | | grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w; |
grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR; | | grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL; |
//grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels; | | //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels; |
grd_curscreen->sc_canvas.cv_bitmap.bm_data = realloc(grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h); | | grd_curscreen->sc_canvas.cv_bitmap.bm_data = realloc(grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h); |
kludgetexturedata=realloc(kludgetexturedata,w*h*3); | | |
gr_set_current_canvas(NULL); | | gr_set_current_canvas(NULL); |
//gr_enable_default_palette_loading(); | | //gr_enable_default_palette_loading(); |
| | |
| | ogl_set_screen_mode(); |
| | |
return 0; | | return 0; |
} | | } |
| | |
| | |
} | | } |
} | | } |
if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){ | | if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){ |
// t=atoi(Args[t+1]); | | |
if (t>=glt)//allow overriding of earlier args | | if (t>=glt)//allow overriding of earlier args |
GL_texmagfilt=ogl_atotexfilti(Args[t+1],0); | | GL_texmagfilt=ogl_atotexfilti(Args[t+1],0); |
} | | } |
| | |
| | |
ogl_init();//platform specific initialization | | ogl_init();//platform specific initialization |
| | |
// allocate a texture name | | |
glGenTextures( 1, &kludgetexture ); | | |
| | |
MALLOC( grd_curscreen,grs_screen,1 ); | | MALLOC( grd_curscreen,grs_screen,1 ); |
memset( grd_curscreen, 0, sizeof(grs_screen)); | | memset( grd_curscreen, 0, sizeof(grs_screen)); |
grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL; | | grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL; |
| | |
} | | } |
ogl_close();//platform specific code | | ogl_close();//platform specific code |
} | | } |
| | extern int r_upixelc; |
void gr_upixelc(int x, int y, int c){ | | void ogl_upixelc(int x, int y, int c){ |
| | r_upixelc++; |
// printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME); | | // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME); |
if(Function_mode != FMODE_GAME){ | | // if(Function_mode != FMODE_GAME){ |
grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c; | | // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c; |
}else{ | | // }else{ |
OGL_DISABLE(GL_TEXTURE_2D); | | OGL_DISABLE(GL_TEXTURE_2D); |
glPointSize(1.0); | | glPointSize(1.0); |
glBegin(GL_POINTS); | | glBegin(GL_POINTS); |
// glBegin(GL_LINES); | | // glBegin(GL_LINES); |
glColor3f(PAL2Tr(c),PAL2Tg(c),PAL2Tb(c)); | | // ogl_pal=gr_current_pal; |
glVertex2f(x/(float)last_width,1.0-y/(float)last_height); | | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |
| | // ogl_pal=gr_palette; |
| | glVertex2f((x+grd_curcanv->cv_bitmap.bm_x)/(float)last_width,1.0-(y+grd_curcanv->cv_bitmap.bm_y)/(float)last_height); |
// glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1)); | | // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1)); |
glEnd(); | | glEnd(); |
| | // } |
} | | } |
| | void ogl_urect(int left,int top,int right,int bot){ |
| | GLfloat xo,yo,xf,yf; |
| | int c=COLOR; |
| | |
| | xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width; |
| | xf=(right+grd_curcanv->cv_bitmap.bm_x)/(float)last_width; |
| | yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height; |
| | yf=1.0-(bot+grd_curcanv->cv_bitmap.bm_y)/(float)last_height; |
| | |
| | OGL_DISABLE(GL_TEXTURE_2D); |
| | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |
| | glBegin(GL_QUADS); |
| | glVertex2f(xo,yo); |
| | glVertex2f(xo,yf); |
| | glVertex2f(xf,yf); |
| | glVertex2f(xf,yo); |
| | glEnd(); |
} | | } |
| | void ogl_ulinec(int left,int top,int right,int bot,int c){ |
| | GLfloat xo,yo,xf,yf; |
| | |
| | xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width; |
| | xf=(right+grd_curcanv->cv_bitmap.bm_x)/(float)last_width; |
| | yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height; |
| | yf=1.0-(bot+grd_curcanv->cv_bitmap.bm_y)/(float)last_height; |
| | |
| | OGL_DISABLE(GL_TEXTURE_2D); |
| | glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c)); |
| | glBegin(GL_LINES); |
| | glVertex2f(xo,yo); |
| | glVertex2f(xf,yf); |
| | glEnd(); |
| | } |
| | |
GLfloat last_r=0, last_g=0, last_b=0; | | GLfloat last_r=0, last_g=0, last_b=0; |
int do_pal_step=0; | | int do_pal_step=0; |
| | |
glVertex2f(1,0); | | glVertex2f(1,0); |
glEnd(); | | glEnd(); |
| | |
glDisable(GL_BLEND); | | glEnable(GL_BLEND); |
| | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
} | | } |
| | |
void gr_palette_clear() | | void gr_palette_clear() |
| | |
| | |
void gr_palette_read(ubyte * pal) | | void gr_palette_read(ubyte * pal) |
{ | | { |
| | int i; |
| | for (i=0; i<768; i++ ) { |
| | pal[i]=gr_current_pal[i]; |
| | if (pal[i] > 63) pal[i] = 63; |
| | } |
} | | } |
| | |
//writes out a raw bitmap file. Eventually it could be made to write a "real" bmp with header, or tiff, etc. (if I ever get the screen shot func to produce any data) | | //writes out a raw bitmap file. Eventually it could be made to write a "real" bmp with header, or tiff, etc. (if I ever get the screen shot func to produce any data) |
| | |
//OGL screenshot code. Doesn't work for me, but I hear the glReadPixels is broken for mesa/glx at least with the beta tnt2 drivers. all I get is a bunch of zeros. | | //OGL screenshot code. Doesn't work for me, but I hear the glReadPixels is broken for mesa/glx at least with the beta tnt2 drivers. all I get is a bunch of zeros. |
void save_screen_shot(int automap_flag) | | void save_screen_shot(int automap_flag) |
{ | | { |
fix t1; | | // fix t1; |
char message[100]; | | char message[100]; |
// grs_canvas *screen_canv=&grd_curscreen->sc_canvas; | | // grs_canvas *screen_canv=&grd_curscreen->sc_canvas; |
grs_font *save_font; | | // grs_font *save_font; |
static int savenum=0; | | static int savenum=0; |
// grs_canvas *temp_canv,*save_canv | | // grs_canvas *temp_canv,*save_canv |
char savename[13]; | | char savename[13]; |
unsigned char *buf; | | unsigned char *buf; |
// ubyte pal[768]; | | // ubyte pal[768]; |
int w,h,aw,x,y; | | // int w,h,aw,x,y; |
| | |
// Can't do screen shots in VR modes. | | // Can't do screen shots in VR modes. |
// if ( VR_render_mode != VR_NONE ) | | // if ( VR_render_mode != VR_NONE ) |
| | |
// y = (VR_screen_pages[VR_current_page].cv_h-h)/2; | | // y = (VR_screen_pages[VR_current_page].cv_h-h)/2; |
| | |
if (automap_flag) { | | if (automap_flag) { |
save_font = grd_curcanv->cv_font; | | // save_font = grd_curcanv->cv_font; |
gr_set_curfont(GAME_FONT); | | // gr_set_curfont(GAME_FONT); |
gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1); | | // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1); |
gr_get_string_size(message,&w,&h,&aw); | | // gr_get_string_size(message,&w,&h,&aw); |
modex_print_message(32, 2, message); | | // modex_print_message(32, 2, message); |
} else { | | } else { |
// gr_setcolor(gr_find_closest_color_current(0,0,0)); | | // gr_setcolor(gr_find_closest_color_current(0,0,0)); |
// gr_rect(x-2,y-2,x+w+2,y+h+2); | | // gr_rect(x-2,y-2,x+w+2,y+h+2); |