1 /* $Id: gr.c,v 1.29 2004-05-22 21:48:33 btb Exp $ */
4 * OGL video functions. - Added 9/15/99 Matthew Mueller
20 #if defined(__APPLE__) && defined(__MACH__)
21 //#include <OpenGL/gl.h>
28 #include <sys/types.h>
53 #if defined(__APPLE__) && defined(__MACH__)
54 #include <OpenGL/glu.h>
55 #undef GL_ARB_multitexture // hack!
65 void gr_palette_clear(); // Function prototype for gr_init;
71 int gr_check_fullscreen(void){
72 return ogl_fullscreen;
75 void gr_do_fullscreen(int f){
77 ogl_fullscreen=1;//force fullscreen mode on voodoos.
81 ogl_do_fullscreen_internal();
85 int gr_toggle_fullscreen(void){
86 gr_do_fullscreen(!ogl_fullscreen);
87 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
88 return ogl_fullscreen;
91 int arch_toggle_fullscreen_menu(void){
92 unsigned char *buf=NULL;
94 if (ogl_readpixels_ok){
95 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
96 glReadBuffer(GL_FRONT);
97 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
100 gr_do_fullscreen(!ogl_fullscreen);
102 if (ogl_readpixels_ok){
103 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
105 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
108 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
110 return ogl_fullscreen;
113 void ogl_init_state(void){
114 /* select clearing (background) color */
115 glClearColor(0.0, 0.0, 0.0, 0.0);
116 glShadeModel(GL_SMOOTH);
118 /* initialize viewing values */
119 glMatrixMode(GL_PROJECTION);
121 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
122 glScalef(1.0, -1.0, 1.0);
123 glTranslatef(0.0, -1.0, 0.0);
124 gr_palette_step_up(0,0,0);//in case its left over from in game
127 int last_screen_mode=-1;
129 void ogl_set_screen_mode(void){
130 if (last_screen_mode==Screen_mode)
132 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
133 // 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);
134 if (Screen_mode==SCREEN_GAME){
135 glDrawBuffer(GL_BACK);
137 glClearColor(0.0, 0.0, 0.0, 0.0);
138 glDrawBuffer(GL_FRONT);
139 glClear(GL_COLOR_BUFFER_BIT);
140 glMatrixMode(GL_PROJECTION);
141 glLoadIdentity();//clear matrix
142 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
143 glMatrixMode(GL_MODELVIEW);
144 glLoadIdentity();//clear matrix
146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
148 last_screen_mode=Screen_mode;
155 if(Screen_mode != SCREEN_GAME){
161 const char *gl_vendor,*gl_renderer,*gl_version,*gl_extensions;
163 void ogl_get_verinfo(void)
165 int t, arb_max_textures = -1, sgi_max_textures = -1, nv_register_combiners = -1;
166 float anisotropic_max = 0;
168 gl_vendor=glGetString(GL_VENDOR);
169 gl_renderer=glGetString(GL_RENDERER);
170 gl_version=glGetString(GL_VERSION);
171 gl_extensions=glGetString(GL_EXTENSIONS);
173 con_printf(CON_VERBOSE, "gl vendor:%s renderer:%s version:%s extensions:%s\n",gl_vendor,gl_renderer,gl_version,gl_extensions);
175 ogl_intensity4_ok = 1;
176 ogl_luminance4_alpha4_ok = 1;
178 ogl_gettexlevelparam_ok = 1;
179 ogl_setgammaramp_ok = 1;
182 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
183 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
184 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
185 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
186 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
187 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
188 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
189 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
192 #ifdef GL_ARB_multitexture
193 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
194 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
196 #ifdef GL_SGIS_multitexture
197 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
198 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
200 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
201 #ifdef GL_NV_register_combiners
202 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
205 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
206 if (ogl_ext_texture_filter_anisotropic_ok)
207 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
209 #ifdef GL_EXT_paletted_texture
210 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
211 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
213 //add driver specific hacks here. whee.
214 if ((stricmp(gl_renderer,"Mesa NVIDIA RIVA 1.0\n")==0 || stricmp(gl_renderer,"Mesa NVIDIA RIVA 1.2\n")==0) && stricmp(gl_version,"1.2 Mesa 3.0")==0){
215 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
216 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
217 ogl_gettexlevelparam_ok=0;//returns random data..
219 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
220 //displays garbage. reported by
221 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
222 // orulz (Matrox G200)
226 //allow overriding of stuff.
227 #ifdef GL_ARB_multitexture
228 if ((t=FindArg("-gl_arb_multitexture_ok"))){
229 ogl_arb_multitexture_ok=atoi(Args[t+1]);
231 if (ogl_arb_multitexture_ok)
232 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
234 #ifdef GL_SGIS_multitexture
235 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
236 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
238 if (ogl_sgis_multitexture_ok)
239 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
241 #ifdef GL_NV_register_combiners
242 if ((t = FindArg("-gl_nv_register_combiners_ok")))
244 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
246 if (ogl_nv_register_combiners_ok)
247 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
249 #ifdef GL_EXT_paletted_texture
250 if ((t = FindArg("-gl_paletted_texture_ok")))
252 ogl_paletted_texture_ok = atoi(Args[t + 1]);
254 if ((t = FindArg("-gl_shared_palette_ok")))
256 ogl_shared_palette_ok = atoi(Args[t + 1]);
258 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
259 printf("gl_paletted_texture: %i gl_shared_palette: %i (using paletted textures: %i)\n", ogl_paletted_texture_ok, ogl_shared_palette_ok, ogl_shared_palette_ok);
261 if ((t=FindArg("-gl_intensity4_ok"))){
262 ogl_intensity4_ok=atoi(Args[t+1]);
264 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
265 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
267 if ((t=FindArg("-gl_rgba2_ok"))){
268 ogl_rgba2_ok=atoi(Args[t+1]);
270 if ((t=FindArg("-gl_readpixels_ok"))){
271 ogl_readpixels_ok=atoi(Args[t+1]);
273 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
274 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
276 if ((t=FindArg("-gl_setgammaramp_ok")))
278 ogl_setgammaramp_ok = atoi(Args[t + 1]);
281 con_printf(CON_VERBOSE, "gl_arb_multitexture:%i(%i units) gl_sgis_multitexture:%i(%i units) gl_nv_texture_env_combine4:%i gl_nv_register_combiners:%i(%i stages)\n", ogl_arb_multitexture_ok, arb_max_textures, ogl_sgis_multitexture_ok, sgi_max_textures, ogl_nv_texture_env_combine4_ok, 0/*ogl_nv_register_combiners_ok*/, nv_register_combiners);
282 con_printf(CON_VERBOSE, "gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i gl_gettexlevelparam:%i gl_setgammaramp_ok:%i gl_ext_texture_filter_anisotropic:%i(%f max)\n", ogl_intensity4_ok, ogl_luminance4_alpha4_ok, ogl_rgba2_ok, ogl_readpixels_ok, ogl_gettexlevelparam_ok, ogl_setgammaramp_ok, ogl_ext_texture_filter_anisotropic_ok, anisotropic_max);
286 int gr_check_mode(u_int32_t mode)
292 return ogl_check_mode(w, h); // platform specific code
296 extern int VGA_current_mode; // DPH: kludge - remove at all costs
298 int gr_set_mode(u_int32_t mode)
312 VGA_current_mode = mode;
314 //if (screen != NULL) gr_palette_clear();
318 gr_bm_data=grd_curscreen->sc_canvas.cv_bitmap.bm_data;//since we use realloc, we want to keep this pointer around.
319 memset( grd_curscreen, 0, sizeof(grs_screen));
320 grd_curscreen->sc_mode = mode;
321 grd_curscreen->sc_w = w;
322 grd_curscreen->sc_h = h;
323 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
324 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
325 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
326 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
327 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
328 //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch;
329 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
330 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL;
331 //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels;
332 // mprintf((0,"ogl/gr.c: reallocing %p to %i\n",grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h));
333 grd_curscreen->sc_canvas.cv_bitmap.bm_data = d_realloc(gr_bm_data,w*h);
334 gr_set_current_canvas(NULL);
335 //gr_enable_default_palette_loading();
337 ogl_init_window(w,h);//platform specific code
341 OGL_VIEWPORT(0,0,w,h);
343 ogl_set_screen_mode();
345 // gamefont_choose_game_font(w,h);
350 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
351 int ogl_atotexfilti(char *a,int min){
352 GLstrcmptestr(a,NEAREST);
353 GLstrcmptestr(a,LINEAR);
354 if (min){//mipmaps are valid only for the min filter
355 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
356 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
357 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
358 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
360 Error("unknown/invalid texture filter %s\n",a);
361 // return GL_NEAREST;
363 int ogl_testneedmipmaps(int i){
368 case GL_NEAREST_MIPMAP_NEAREST:
369 case GL_NEAREST_MIPMAP_LINEAR:
370 case GL_LINEAR_MIPMAP_NEAREST:
371 case GL_LINEAR_MIPMAP_LINEAR:
374 Error("unknown texture filter %x\n",i);
377 #ifdef OGL_RUNTIME_LOAD
379 char *OglLibPath="opengl32.dll";
382 char *OglLibPath="libGL.so";
386 int ogl_init_load_library(void)
391 if ((t=FindArg("-gl_library")))
392 OglLibPath=Args[t+1];
394 retcode = OpenGL_LoadLibrary(true);
397 mprintf((0,"Opengl loaded ok\n"));
401 Error("Opengl: Functions not imported\n");
404 Error("Opengl: error loading %s\n",OglLibPath);
414 int mode = SM(640,480);
415 int retcode, t, glt = 0;
417 // Only do this function once!
422 #ifdef OGL_RUNTIME_LOAD
423 ogl_init_load_library();
426 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
427 if (FindArg("-gl_voodoo")){
429 gr_toggle_fullscreen();
431 if (FindArg("-fullscreen"))
432 gr_toggle_fullscreen();
434 if ((glt=FindArg("-gl_alttexmerge")))
436 if ((t=FindArg("-gl_stdtexmerge")))
437 if (t>=glt)//allow overriding of earlier args
440 if ((glt = FindArg("-gl_16bittextures")))
442 ogl_rgba_internalformat = GL_RGB5_A1;
443 ogl_rgb_internalformat = GL_RGB5;
446 if ((glt=FindArg("-gl_mipmap"))){
447 GL_texmagfilt=GL_LINEAR;
448 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
450 if ((glt=FindArg("-gl_trilinear")))
452 GL_texmagfilt = GL_LINEAR;
453 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
455 if ((t=FindArg("-gl_simple"))){
456 if (t>=glt){//allow overriding of earlier args
458 GL_texmagfilt=GL_NEAREST;
459 GL_texminfilt=GL_NEAREST;
462 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
463 if (t>=glt)//allow overriding of earlier args
464 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
466 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
467 if (t>=glt)//allow overriding of earlier args
468 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
470 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
472 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
474 GL_texanisofilt=atof(Args[t + 1]);
477 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
480 if ((t=FindArg("-gl_vidmem"))){
481 ogl_mem_target=atoi(Args[t+1])*1024*1024;
483 if ((t=FindArg("-gl_reticle"))){
484 gl_reticle=atoi(Args[t+1]);
486 //printf("ogl_mem_target=%i\n",ogl_mem_target);
488 ogl_init();//platform specific initialization
490 ogl_init_texture_list_internal();
492 MALLOC( grd_curscreen,grs_screen,1 );
493 memset( grd_curscreen, 0, sizeof(grs_screen));
494 grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL;
497 if ((retcode=gr_set_mode(mode)))
502 grd_curscreen->sc_canvas.cv_color = 0;
503 grd_curscreen->sc_canvas.cv_drawmode = 0;
504 grd_curscreen->sc_canvas.cv_font = NULL;
505 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
506 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
507 gr_set_current_canvas( &grd_curscreen->sc_canvas );
518 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
520 ogl_close();//platform specific code
522 if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
523 d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
524 d_free(grd_curscreen);
526 #ifdef OGL_RUNTIME_LOAD
528 OpenGL_LoadLibrary(false);
531 extern int r_upixelc;
532 void ogl_upixelc(int x, int y, int c){
534 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
535 // if(Function_mode != FMODE_GAME){
536 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
538 OGL_DISABLE(TEXTURE_2D);
541 // glBegin(GL_LINES);
542 // ogl_pal=gr_current_pal;
543 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
544 // ogl_pal=gr_palette;
545 glVertex2f((x + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width, 1.0 - (y + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height);
546 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
550 void ogl_urect(int left,int top,int right,int bot){
554 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
555 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
556 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
557 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
559 OGL_DISABLE(TEXTURE_2D);
560 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
568 void ogl_ulinec(int left,int top,int right,int bot,int c){
571 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
572 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
573 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
574 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
576 OGL_DISABLE(TEXTURE_2D);
577 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
585 GLfloat last_r=0, last_g=0, last_b=0;
587 void ogl_do_palfx(void){
589 OGL_DISABLE(TEXTURE_2D);
590 if (gr_palette_faded_out){
591 /* glEnable(GL_BLEND);
592 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
597 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
599 glBlendFunc(GL_ONE,GL_ONE);
600 glColor3f(last_r,last_g,last_b);
601 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
615 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
618 void gr_palette_clear()
620 gr_palette_faded_out=1;
624 int ogl_brightness_ok = 0;
625 int ogl_setgammaramp_ok = 1;
626 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
627 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
629 void gr_palette_step_up(int r, int g, int b)
631 if (gr_palette_faded_out)
634 old_b_r = ogl_brightness_r;
635 old_b_g = ogl_brightness_g;
636 old_b_b = ogl_brightness_b;
638 ogl_brightness_r = max(r + gr_palette_gamma, 0);
639 ogl_brightness_g = max(g + gr_palette_gamma, 0);
640 ogl_brightness_b = max(b + gr_palette_gamma, 0);
642 if (ogl_setgammaramp_ok &&
643 (old_b_r != ogl_brightness_r ||
644 old_b_g != ogl_brightness_g ||
645 old_b_b != ogl_brightness_b))
646 ogl_brightness_ok = !ogl_setbrightness_internal();
648 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
650 last_r = ogl_brightness_r / 63.0;
651 last_g = ogl_brightness_g / 63.0;
652 last_b = ogl_brightness_b / 63.0;
654 do_pal_step = (r || g || b || gr_palette_gamma);
662 //added on 980913 by adb to fix palette problems
663 // need a min without side effects...
665 static inline int min(int x, int y) { return x < y ? x : y; }
668 void gr_palette_load( ubyte *pal )
672 for (i=0; i<768; i++ ) {
673 gr_current_pal[i] = pal[i];
674 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
676 //palette = screen->format->palette;
678 gr_palette_faded_out=0;
680 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
682 init_computed_colors();
684 ogl_init_shared_palette();
689 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
691 gr_palette_faded_out=1;
697 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
699 gr_palette_faded_out=0;
705 void gr_palette_read(ubyte * pal)
708 for (i=0; i<768; i++ ) {
709 pal[i]=gr_current_pal[i];
710 if (pal[i] > 63) pal[i] = 63;
714 //writes out an uncompressed RGB .tga file
715 //if we got really spiffy, we could optionally link in libpng or something, and use that.
716 void write_bmp(char *savename,int w,int h,unsigned char *buf){
719 f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IREAD|S_IWRITE);
721 f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
724 GLubyte targaMagic[12] = { 0, //no identification field
726 2,//RGB image (well, BGR, actually)
727 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
734 write (f,targaMagic,sizeof(targaMagic));
735 blah=w%256;write (f,&blah,1);//w, low
736 blah=w/256;write (f,&blah,1);//w, high
737 blah=h%256;write (f,&blah,1);//h, low
738 blah=h/256;write (f,&blah,1);//h, high
739 blah=24;write (f,&blah,1);//24 bpp
740 blah=0;write (f,&blah,1);//no attribute bits, origin is lowerleft, no interleave
743 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
756 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
763 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
766 void save_screen_shot(int automap_flag)
770 static int savenum=0;
774 if (!ogl_readpixels_ok){
776 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
782 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
783 if ( savenum == 9999 ) savenum = 0;
784 sprintf(savename,"scrn%04d.tga",savenum++);
786 while(!access(savename,0))
788 if ( savenum == 9999 ) savenum = 0;
789 sprintf(savename,"scrn%04d.tga",savenum++);
791 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
792 //end this section addition/change - Victor Rachels
795 // save_font = grd_curcanv->cv_font;
796 // gr_set_curfont(GAME_FONT);
797 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
798 // gr_get_string_size(message,&w,&h,&aw);
799 // modex_print_message(32, 2, message);
801 hud_message(MSGC_GAME_FEEDBACK,message);
804 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
805 glReadBuffer(GL_FRONT);
806 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
807 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);