2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Graphics/GrOpenGL.cpp $
15 * Code that uses the OpenGL graphics library
18 * Revision 1.76 2005/10/01 21:44:43 taylor
19 * slight speedup to font rendering by not doing something that should be global for each letter
20 * little cleanup to better deal with FS2_Open related changes
21 * don't deal with the extra texmem stuff if we don't have to, saves on temporary memory usage and speed
23 * Revision 1.75 2005/08/12 20:24:31 taylor
24 * some OSX GCC4 fixin (LEgregius)
26 * Revision 1.74 2005/08/12 08:57:20 taylor
27 * don't show hardware S-RAM value on HUD in debug
28 * do show in use GL texture memory
29 * have an actual fade effect for the credits screen artwork
31 * Revision 1.73 2005/04/02 18:58:08 taylor
32 * attempt to fix garbage at end of GL extension string
34 * Revision 1.72 2005/03/30 01:20:12 taylor
35 * Screenshot function filled, will output into ~/.freespace(2)/Data
36 * Use glTexSubImage2D on reloaded texture slots, this is only used by ANIs
38 * Revision 1.71 2004/12/15 04:10:45 taylor
39 * outwnd_unix.cpp from fs2_open for logging to file in debug mode
40 * fixes for default function values
41 * always use vm_* functions for sanity sake
42 * make cfilearchiver 64-bit compatible
43 * fix crash on exit from double free()
44 * fix crash on startup from extra long GL extension string in debug
46 * Revision 1.70 2004/09/20 01:31:44 theoddone33
49 * Revision 1.69 2004/07/04 11:31:43 taylor
50 * amd64 support, compiler warning fixes, don't use software rendering
52 * Revision 1.68 2004/06/11 01:01:07 tigital
53 * added FSAA support: switched on in .ini
55 * Revision 1.67 2003/08/03 15:59:40 taylor
56 * GL_RGB5_A1 as TexImage internal format; cleaner input grab; min window title; cleanup
58 * Revision 1.66 2003/06/22 12:52:34 taylor
59 * more texture size fixin
61 * Revision 1.65 2003/06/19 11:52:47 taylor
62 * fix texture size issue with lower detail settings
64 * Revision 1.64 2003/05/28 06:02:04 taylor
65 * fix transparency in green weapon blobs
67 * Revision 1.63 2003/05/09 05:05:52 taylor
68 * improve gr_(de)activate, mouse grab, default fullscreen
70 * Revision 1.62 2003/05/04 04:56:53 taylor
71 * move SDL_Quit to os_deinit to fix fonttool segfault
73 * Revision 1.61 2003/02/02 21:13:27 relnev
74 * minor updates (made functions static, tried to improve texture sizes)
76 * Revision 1.60 2003/02/02 20:20:03 relnev
77 * add large texture support (Taylor Richards)
79 * Revision 1.59 2002/09/04 01:38:09 relnev
82 * Revision 1.57 2002/08/31 01:39:13 theoddone33
83 * Speed up the renderer a tad
85 * Revision 1.56 2002/08/01 05:03:11 relnev
88 * Revision 1.55 2002/08/01 04:55:45 relnev
89 * experimenting with texture state
91 * Revision 1.54 2002/07/30 15:00:15 relnev
92 * not use luminance alpha by default
94 * Revision 1.53 2002/06/22 17:08:16 relnev
95 * more fixes to unused alpha code
97 * Revision 1.52 2002/06/21 23:59:14 relnev
98 * moved a gr_opengl_set_state to after the gr_tcache_set
100 * Revision 1.51 2002/06/19 04:52:45 relnev
101 * MacOS X updates (Ryan)
103 * Revision 1.50 2002/06/18 23:20:44 relnev
106 * adjusted line offsets.
108 * Revision 1.49 2002/06/17 23:11:39 relnev
109 * enable sdl key repeating.
113 * Revision 1.48 2002/06/09 04:41:17 relnev
114 * added copyright header
116 * Revision 1.47 2002/06/09 03:16:04 relnev
119 * removed unneeded asm, old sdl 2d setup.
121 * fixed crash caused by opengl_get_region.
123 * Revision 1.46 2002/06/05 04:03:32 relnev
124 * finished cfilesystem.
126 * removed some old code.
128 * fixed mouse save off-by-one.
132 * Revision 1.45 2002/06/03 09:25:37 relnev
133 * implement mouse cursor and screen save/restore
135 * Revision 1.44 2002/06/02 18:46:59 relnev
138 * Revision 1.43 2002/06/02 11:34:00 relnev
141 * Revision 1.42 2002/06/02 10:28:17 relnev
142 * fix texture handle leak
144 * Revision 1.41 2002/06/01 09:00:34 relnev
145 * silly debug memmanager
147 * Revision 1.40 2002/06/01 07:12:33 relnev
148 * a few NDEBUG updates.
150 * removed a few warnings.
152 * Revision 1.39 2002/06/01 05:33:15 relnev
153 * copied more code over.
155 * added scissor clipping.
157 * Revision 1.38 2002/06/01 03:35:27 relnev
160 * Revision 1.37 2002/06/01 03:32:00 relnev
161 * fix texture loading mistake.
163 * enable some d3d stuff for opengl also
165 * Revision 1.36 2002/05/31 23:25:03 relnev
168 * Revision 1.34 2002/05/31 22:15:22 relnev
171 * Revision 1.33 2002/05/31 22:04:55 relnev
172 * use d3d rect_internal
174 * Revision 1.32 2002/05/31 06:28:23 relnev
177 * Revision 1.31 2002/05/31 06:04:39 relnev
180 * Revision 1.30 2002/05/31 03:56:11 theoddone33
181 * Change tmapper polygon winding and enable culling
183 * Revision 1.29 2002/05/31 03:34:02 theoddone33
187 * Revision 1.28 2002/05/31 00:06:59 relnev
190 * Revision 1.27 2002/05/30 23:46:29 theoddone33
191 * some minor key changes (not necessarily fixes)
193 * Revision 1.26 2002/05/30 23:33:12 relnev
194 * implemented a few more functions.
196 * Revision 1.25 2002/05/30 23:01:16 relnev
197 * implement gr_opengl_set_state.
199 * Revision 1.24 2002/05/30 22:12:57 relnev
200 * finish default texture case
202 * Revision 1.23 2002/05/30 22:02:30 theoddone33
205 * Revision 1.22 2002/05/30 21:44:48 relnev
206 * implemented some missing texture stuff.
208 * enable bitmap polys for opengl.
210 * work around greenness in bitmaps.
212 * Revision 1.21 2002/05/30 17:29:30 theoddone33
213 * Fix some more stubs, change at least one polygon winding since culling is now
216 * Revision 1.20 2002/05/30 16:50:24 theoddone33
217 * Keyboard partially fixed
219 * Revision 1.19 2002/05/30 08:13:14 relnev
222 * Revision 1.18 2002/05/29 23:37:36 relnev
225 * Revision 1.17 2002/05/29 23:17:49 theoddone33
226 * Non working text code and fixed keys
228 * Revision 1.16 2002/05/29 19:45:13 theoddone33
229 * More changes on texture loading
231 * Revision 1.15 2002/05/29 19:06:48 theoddone33
232 * Enable string printing. Enable texture mapping
234 * Revision 1.14 2002/05/29 08:54:40 relnev
235 * "fixed" bitmap drawing.
237 * copied more d3d code over.
239 * Revision 1.13 2002/05/29 06:25:13 theoddone33
240 * Keyboard input, mouse tracking now work
242 * Revision 1.12 2002/05/29 04:52:45 relnev
245 * Revision 1.11 2002/05/29 04:29:56 relnev
246 * removed some unncessary stubbing, implemented opengl rect
248 * Revision 1.10 2002/05/29 04:13:27 theoddone33
251 * Revision 1.9 2002/05/29 03:35:51 relnev
254 * Revision 1.8 2002/05/29 03:30:05 relnev
255 * update opengl stubs
257 * Revision 1.7 2002/05/29 02:52:32 theoddone33
258 * Enable OpenGL renderer
260 * Revision 1.6 2002/05/28 04:56:51 theoddone33
261 * runs a little bit now
263 * Revision 1.5 2002/05/28 04:07:28 theoddone33
264 * New graphics stubbing arrangement
266 * Revision 1.4 2002/05/27 23:39:34 relnev
269 * Revision 1.3 2002/05/27 22:35:01 theoddone33
272 * Revision 1.2 2002/05/27 22:32:02 theoddone33
273 * throw all d3d stuff at opengl
275 * Revision 1.1.1.1 2002/05/03 03:28:09 root
279 * 10 7/14/99 9:42a Dave
280 * Put in clear_color debug function. Put in base for 3dnow stuff / P3
283 * 9 7/09/99 9:51a Dave
284 * Added thick polyline code.
286 * 8 6/29/99 10:35a Dave
287 * Interface polygon bitmaps! Whee!
289 * 7 2/03/99 11:44a Dave
290 * Fixed d3d transparent textures.
292 * 6 1/24/99 11:37p Dave
293 * First full rev of beam weapons. Very customizable. Removed some bogus
294 * Int3()'s in low level net code.
296 * 5 12/18/98 1:13a Dave
297 * Rough 1024x768 support for Direct3D. Proper detection and usage through
300 * 4 12/06/98 2:36p Dave
301 * Drastically improved nebula fogging.
303 * 3 11/11/98 5:37p Dave
304 * Checkin for multiplayer testing.
306 * 2 10/07/98 10:53a Dave
309 * 1 10/07/98 10:49a Dave
311 * 14 5/20/98 9:46p John
312 * added code so the places in code that change half the palette don't
313 * have to clear the screen.
315 * 13 5/06/98 5:30p John
316 * Removed unused cfilearchiver. Removed/replaced some unused/little used
317 * graphics functions, namely gradient_h and _v and pixel_sp. Put in new
318 * DirectX header files and libs that fixed the Direct3D alpha blending
321 * 12 4/14/98 12:15p John
322 * Made 16-bpp movies work.
324 * 11 3/12/98 5:36p John
325 * Took out any unused shaders. Made shader code take rgbc instead of
326 * matrix and vector since noone used it like a matrix and it would have
327 * been impossible to do in hardware. Made Glide implement a basic
328 * shader for online help.
330 * 10 3/10/98 4:18p John
331 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
332 * & Glide have popups and print screen. Took out all >8bpp software
333 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
334 * support Fred. Made zbuffering key off of functions rather than one
337 * 9 12/02/97 4:00p John
338 * Added first rev of thruster glow, along with variable levels of
339 * translucency, which retquired some restructing of palman.
341 * 8 10/03/97 9:10a John
342 * added better antialiased line drawer
344 * 7 9/23/97 10:45a John
345 * made so you can tell bitblt code to rle a bitmap by passing flag to
348 * 6 9/09/97 11:01a Sandeep
349 * fixed warning level 4 bugs
351 * 5 7/10/97 2:06p John
352 * added code to specify alphablending type for bitmaps.
354 * 4 6/17/97 7:04p John
355 * added d3d support for gradients.
356 * fixed some color bugs by adding screen signatures instead of watching
357 * flags and palette changes.
359 * 3 6/12/97 2:50a Lawrance
360 * bm_unlock() now passed bitmap number, not pointer
362 * 2 6/11/97 1:12p John
363 * Started fixing all the text colors in the game.
365 * 1 5/12/97 12:14p John
372 #include <windowsx.h>
380 #include "floating.h"
382 #include "systemvars.h"
383 #include "grinternal.h"
384 #include "gropengl.h"
388 #include "osregistry.h"
392 static int Inited = 0;
394 typedef enum gr_texture_source {
396 TEXTURE_SOURCE_DECAL,
397 TEXTURE_SOURCE_NO_FILTERING,
400 typedef enum gr_alpha_blend {
401 ALPHA_BLEND_NONE, // 1*SrcPixel + 0*DestPixel
402 ALPHA_BLEND_ADDITIVE, // 1*SrcPixel + 1*DestPixel
403 ALPHA_BLEND_ALPHA_ADDITIVE, // Alpha*SrcPixel + 1*DestPixel
404 ALPHA_BLEND_ALPHA_BLEND_ALPHA, // Alpha*SrcPixel + (1-Alpha)*DestPixel
405 ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR, // Alpha*SrcPixel + (1-SrcPixel)*DestPixel
408 typedef enum gr_zbuffer_type {
415 #define NEBULA_COLORS 20
417 volatile int GL_activate = 0;
418 volatile int GL_deactivate = 0;
421 static ubyte GL_xlat[256] = { 0 };
423 static GLuint Gr_saved_screen_tex = 0;
425 static int Gr_opengl_mouse_saved = 0;
426 static int Gr_opengl_mouse_saved_x = 0;
427 static int Gr_opengl_mouse_saved_y = 0;
428 static int Gr_opengl_mouse_saved_w = 0;
429 static int Gr_opengl_mouse_saved_h = 0;
430 static ubyte *Gr_opengl_mouse_saved_data = NULL;
432 #define CLAMP(x,r1,r2) do { if ( (x) < (r1) ) (x) = (r1); else if ((x) > (r2)) (x) = (r2); } while(0)
434 SDL_Window *GL_window = NULL;
435 SDL_GLContext GL_context;
437 static int GL_viewport_x = 0;
438 static int GL_viewport_y = 0;
439 static int GL_viewport_w = 640;
440 static int GL_viewport_h = 480;
441 static float GL_viewport_scale_w = 1.0f;
442 static float GL_viewport_scale_h = 1.0f;
444 PFNGLSECONDARYCOLOR3FEXTPROC glSecondaryColor3fEXT = NULL;
447 // Throw in some dummy functions - DDOI
449 int D3D_32bit = 0; // grd3d.cpp
450 int D3D_fog_mode = -1; // grd3d.cpp
451 int D3D_inited = 0; // grd3d.cpp
452 int D3D_zbias = 1; // grd3d.cpp
453 int D3d_rendition_uvs = 0; // grd3d.cpp
460 void d3d_zbias (int a)
466 static void gr_opengl_set_texture_state(gr_texture_source ts);
468 static gr_alpha_blend GL_current_alpha_blend = (gr_alpha_blend) -1;
469 static gr_zbuffer_type GL_current_zbuffer_type = (gr_zbuffer_type) -1;
471 static void gr_opengl_set_state(gr_texture_source ts, gr_alpha_blend ab, gr_zbuffer_type zt)
473 gr_opengl_set_texture_state(ts);
475 if (ab != GL_current_alpha_blend) {
477 case ALPHA_BLEND_NONE: // 1*SrcPixel + 0*DestPixel
478 glBlendFunc(GL_ONE, GL_ZERO);
480 case ALPHA_BLEND_ADDITIVE: // 1*SrcPixel + 1*DestPixel
481 glBlendFunc(GL_ONE, GL_ONE);
483 case ALPHA_BLEND_ALPHA_ADDITIVE: // Alpha*SrcPixel + 1*DestPixel
484 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
486 case ALPHA_BLEND_ALPHA_BLEND_ALPHA: // Alpha*SrcPixel + (1-Alpha)*DestPixel
487 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
489 case ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR: // Alpha*SrcPixel + (1-SrcPixel)*DestPixel
490 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);
496 GL_current_alpha_blend = ab;
499 if (zt != GL_current_zbuffer_type) {
501 case ZBUFFER_TYPE_NONE:
502 glDepthFunc(GL_ALWAYS);
503 glDepthMask(GL_FALSE);
505 case ZBUFFER_TYPE_READ:
506 glDepthFunc(GL_LESS);
507 glDepthMask(GL_FALSE);
509 case ZBUFFER_TYPE_WRITE:
510 glDepthFunc(GL_ALWAYS);
511 glDepthMask(GL_TRUE);
513 case ZBUFFER_TYPE_FULL:
514 glDepthFunc(GL_LESS);
515 glDepthMask(GL_TRUE);
521 GL_current_zbuffer_type = zt;
525 void gr_opengl_activate(int active)
530 // don't grab key/mouse if cmdline says so or if we're fullscreen
531 // if(!Cmdline_no_grab && !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN)) {
532 // SDL_WM_GrabInput(SDL_GRAB_ON);
537 // let go of mouse/keyboard
538 // SDL_WM_GrabInput(SDL_GRAB_OFF);
543 static void opengl_tcache_flush ();
545 void gr_opengl_preload_init()
547 if (gr_screen.mode != GR_OPENGL) {
551 opengl_tcache_flush ();
554 int GL_should_preload = 0;
555 int gr_opengl_preload(int bitmap_num, int is_aabitmap)
557 if ( gr_screen.mode != GR_OPENGL) {
561 if ( !GL_should_preload ) {
565 float u_scale, v_scale;
569 retval = gr_tcache_set(bitmap_num, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 1, -1, -1, 0 );
571 retval = gr_tcache_set(bitmap_num, TCACHE_TYPE_NORMAL, &u_scale, &v_scale, 1, -1, -1, 0 );
575 mprintf(("Texture upload failed!\n" ));
581 void gr_opengl_pixel(int x, int y)
586 void gr_opengl_clear()
588 glClearColor(gr_screen.current_clear_color.red / 255.0,
589 gr_screen.current_clear_color.green / 255.0,
590 gr_screen.current_clear_color.blue / 255.0, 1.0);
592 glClear ( GL_COLOR_BUFFER_BIT );
595 void gr_opengl_save_mouse_area(int x, int y, int w, int h);
596 static void opengl_tcache_frame ();
598 void gr_opengl_flip()
606 Gr_opengl_mouse_saved = 0;
608 if ( mouse_is_visible() ) {
612 mouse_get_pos( &mx, &my );
614 gr_opengl_save_mouse_area(mx,my,32,32);
616 if ( Gr_cursor == -1 ) {
619 gr_set_bitmap(Gr_cursor, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
625 GLenum error = glGetError();
628 error = glGetError();
630 if (error != GL_NO_ERROR) {
631 nprintf(("Warning", "!!DEBUG!! OpenGL Error: %d (%d this frame)\n", error, ic));
634 } while (error != GL_NO_ERROR);
637 SDL_GL_SwapWindow(GL_window);
639 opengl_tcache_frame ();
641 int cnt = GL_activate;
644 opengl_tcache_flush();
645 // gr_opengl_clip_cursor(1); /* mouse grab, see opengl_activate */
651 // gr_opengl_clip_cursor(0); /* mouse grab, see opengl_activate */
655 void gr_opengl_flip_window(uint _hdc, int x, int y, int w, int h )
660 void gr_opengl_set_clip(int x,int y,int w,int h)
662 // check for sanity of parameters
668 if (x >= gr_screen.max_w)
669 x = gr_screen.max_w - 1;
670 if (y >= gr_screen.max_h)
671 y = gr_screen.max_h - 1;
673 if (x + w > gr_screen.max_w)
674 w = gr_screen.max_w - x;
675 if (y + h > gr_screen.max_h)
676 h = gr_screen.max_h - y;
678 if (w > gr_screen.max_w)
680 if (h > gr_screen.max_h)
683 gr_screen.offset_x = x;
684 gr_screen.offset_y = y;
685 gr_screen.clip_left = 0;
686 gr_screen.clip_right = w-1;
687 gr_screen.clip_top = 0;
688 gr_screen.clip_bottom = h-1;
689 gr_screen.clip_width = w;
690 gr_screen.clip_height = h;
692 x = fl2i((x * GL_viewport_scale_w) + 0.5f) + GL_viewport_x;
693 y = fl2i((y * GL_viewport_scale_h) + 0.5f) + GL_viewport_y;
694 w = fl2i((w * GL_viewport_scale_w) + 0.5f);
695 h = fl2i((h * GL_viewport_scale_h) + 0.5f);
697 glEnable(GL_SCISSOR_TEST);
698 glScissor(x, GL_viewport_h-y-h, w, h);
701 void gr_opengl_reset_clip()
703 gr_screen.offset_x = 0;
704 gr_screen.offset_y = 0;
705 gr_screen.clip_left = 0;
706 gr_screen.clip_top = 0;
707 gr_screen.clip_right = gr_screen.max_w - 1;
708 gr_screen.clip_bottom = gr_screen.max_h - 1;
709 gr_screen.clip_width = gr_screen.max_w;
710 gr_screen.clip_height = gr_screen.max_h;
712 glDisable(GL_SCISSOR_TEST);
713 // glScissor(0, 0, gr_screen.max_w, gr_screen.max_h);
716 void gr_opengl_set_bitmap( int bitmap_num, int alphablend_mode = GR_ALPHABLEND_NONE, int bitblt_mode = GR_BITBLT_MODE_NORMAL, float alpha = 1.0f, int sx = -1, int sy = -1 )
718 gr_screen.current_alpha = alpha;
719 gr_screen.current_alphablend_mode = alphablend_mode;
720 gr_screen.current_bitblt_mode = bitblt_mode;
721 gr_screen.current_bitmap = bitmap_num;
723 gr_screen.current_bitmap_sx = sx;
724 gr_screen.current_bitmap_sy = sy;
727 void gr_opengl_create_shader(shader * shade, float r, float g, float b, float c )
729 shade->screen_sig = gr_screen.signature;
736 void gr_opengl_set_shader( shader * shade )
739 if (shade->screen_sig != gr_screen.signature) {
740 gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c );
742 gr_screen.current_shader = *shade;
744 gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f );
749 void gr_opengl_bitmap_ex(int x,int y,int w,int h,int sx,int sy)
751 STUB_FUNCTION; /* who called me? */
754 void gr_opengl_bitmap(int x, int y)
756 STUB_FUNCTION; /* who called me? */
759 static void gr_opengl_rect_internal(int x, int y, int w, int h, int r, int g, int b, int a)
763 vertex *verts[4] = {&v[0], &v[1], &v[2], &v[3]};
765 saved_zbuf = gr_zbuffer_get();
767 // start the frame, no zbuffering, no culling
769 gr_zbuffer_set(GR_ZBUFF_NONE);
778 v[0].flags = PF_PROJECTED;
785 v[1].sx = i2fl(x + w);
790 v[1].flags = PF_PROJECTED;
797 v[2].sx = i2fl(x + w);
798 v[2].sy = i2fl(y + h);
802 v[2].flags = PF_PROJECTED;
810 v[3].sy = i2fl(y + h);
814 v[3].flags = PF_PROJECTED;
822 g3_draw_poly_constant_sw(4, verts, TMAP_FLAG_GOURAUD | TMAP_FLAG_RGB | TMAP_FLAG_ALPHA, 0.1f);
826 // restore zbuffer and culling
827 gr_zbuffer_set(saved_zbuf);
831 void gr_opengl_rect(int x,int y,int w,int h)
833 gr_opengl_rect_internal(x, y, w, h, gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
836 void gr_opengl_shade(int x,int y,int w,int h)
843 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
844 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
845 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
846 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
847 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
848 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
849 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
850 if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255;
852 gr_opengl_rect_internal(x, y, w, h, r, g, b, a);
855 static void gr_opengl_aabitmap_ex_internal(int x,int y,int w,int h,int sx,int sy)
860 if ( !gr_screen.current_color.is_alphacolor ) return;
862 float u_scale, v_scale;
864 if ( !gr_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
865 // Couldn't set texture
866 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
870 gr_opengl_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
872 float u0, u1, v0, v1;
873 float x1, x2, y1, y2;
876 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
878 u0 = u_scale*i2fl(sx)/i2fl(bw);
879 v0 = v_scale*i2fl(sy)/i2fl(bh);
881 u1 = u_scale*i2fl(sx+w)/i2fl(bw);
882 v1 = v_scale*i2fl(sy+h)/i2fl(bh);
884 x1 = i2fl(x+gr_screen.offset_x);
885 y1 = i2fl(y+gr_screen.offset_y);
886 x2 = i2fl(x+w+gr_screen.offset_x);
887 y2 = i2fl(y+h+gr_screen.offset_y);
889 if ( gr_screen.current_color.is_alphacolor ) {
890 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue,gr_screen.current_color.alpha);
892 glColor3ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue);
896 glTexCoord2f (u0, v1);
897 glVertex3f (x1, y2, -0.99);
899 glTexCoord2f (u1, v1);
900 glVertex3f (x2, y2, -0.99);
902 glTexCoord2f (u1, v0);
903 glVertex3f (x2, y1, -0.99);
905 glTexCoord2f (u0, v0);
906 glVertex3f (x1, y1, -0.99);
910 void gr_opengl_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
917 int dx1=x, dx2=x+w-1;
918 int dy1=y, dy2=y+h-1;
921 bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL );
926 if ( count > 1 ) Int3();
930 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
931 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
932 if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
933 if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
934 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
935 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
962 if ( w < 1 ) return; // clipped away!
963 if ( h < 1 ) return; // clipped away!
967 // Make sure clipping algorithm works
971 SDL_assert( w == (dx2-dx1+1) );
972 SDL_assert( h == (dy2-dy1+1) );
973 SDL_assert( sx >= 0 );
974 SDL_assert( sy >= 0 );
975 SDL_assert( sx+w <= bw );
976 SDL_assert( sy+h <= bh );
977 SDL_assert( dx2 >= dx1 );
978 SDL_assert( dy2 >= dy1 );
979 SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) );
980 SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) );
981 SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) );
982 SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) );
985 // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
986 gr_opengl_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
989 void gr_opengl_aabitmap(int x, int y)
993 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
994 int dx1=x, dx2=x+w-1;
995 int dy1=y, dy2=y+h-1;
998 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
999 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
1000 if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
1001 if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
1002 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
1003 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
1005 if ( sx < 0 ) return;
1006 if ( sy < 0 ) return;
1007 if ( sx >= w ) return;
1008 if ( sy >= h ) return;
1010 // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
1011 gr_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
1014 void gr_opengl_string( int sx, int sy, const char *s )
1016 int width, spacing, letter;
1019 if ( !Current_font ) {
1023 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1028 if (sx==0x8000) { //centered
1029 x = get_centered_x(s);
1039 while (*s== '\n' ) {
1041 y += Current_font->h;
1042 if (sx==0x8000) { //centered
1043 x = get_centered_x(s);
1048 if (*s == 0 ) break;
1050 letter = get_char_width(s[0],s[1],&width,&spacing);
1053 //not in font, draw as space
1061 // Check if this character is totally clipped
1062 if ( x + width < gr_screen.clip_left ) continue;
1063 if ( y + Current_font->h < gr_screen.clip_top ) continue;
1064 if ( x > gr_screen.clip_right ) continue;
1065 if ( y > gr_screen.clip_bottom ) continue;
1068 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
1069 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
1073 wc = width - xd; hc = Current_font->h - yd;
1074 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
1075 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
1077 if ( wc < 1 ) continue;
1078 if ( hc < 1 ) continue;
1080 int u = Current_font->bm_u[letter];
1081 int v = Current_font->bm_v[letter];
1083 gr_opengl_aabitmap_ex_internal( xc, yc, wc, hc, u+xd, v+yd );
1087 void gr_opengl_line(int x1,int y1,int x2,int y2)
1089 int clipped = 0, swapped=0;
1091 gr_opengl_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
1093 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1);
1098 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5;
1099 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5;
1100 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5;
1101 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5;
1103 if ( x1 == x2 && y1 == y2 ) {
1104 glBegin (GL_POINTS);
1105 glColor4ub (gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
1106 glVertex3f (sx1, sy1, -0.99f);
1118 } else if ( y1 == y2 ) {
1127 glColor4ub (gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
1128 glVertex3f (sx2, sy2, -0.99f);
1129 glVertex3f (sx1, sy1, -0.99f);
1133 void gr_opengl_aaline(vertex *v1, vertex *v2)
1135 gr_opengl_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
1138 void gr_opengl_gradient(int x1,int y1,int x2,int y2)
1140 int clipped = 0, swapped=0;
1142 if ( !gr_screen.current_color.is_alphacolor ) {
1143 gr_line( x1, y1, x2, y2 );
1147 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1);
1149 gr_opengl_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
1151 int aa = swapped ? 0 : gr_screen.current_color.alpha;
1152 int ba = swapped ? gr_screen.current_color.alpha : 0;
1157 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5;
1158 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5;
1159 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5;
1160 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5;
1168 } else if ( y1 == y2 ) {
1177 glColor4ub (gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, ba);
1178 glVertex3f (sx2, sy2, -0.99f);
1179 glColor4ub (gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, aa);
1180 glVertex3f (sx1, sy1, -0.99f);
1184 void gr_opengl_circle( int xc, int yc, int d )
1194 if ( (xc+r) < gr_screen.clip_left ) return;
1195 if ( (xc-r) > gr_screen.clip_right ) return;
1196 if ( (yc+r) < gr_screen.clip_top ) return;
1197 if ( (yc-r) > gr_screen.clip_bottom ) return;
1200 // Draw the first octant
1201 gr_opengl_line( xc-y, yc-x, xc+y, yc-x );
1202 gr_opengl_line( xc-y, yc+x, xc+y, yc+x );
1207 // Draw the second octant
1208 gr_opengl_line( xc-x, yc-y, xc+x, yc-y );
1209 gr_opengl_line( xc-x, yc+y, xc+x, yc+y );
1217 gr_opengl_line( xc-x, yc-y, xc+x, yc-y );
1218 gr_opengl_line( xc-x, yc+y, xc+x, yc+y );
1223 static void gr_opengl_stuff_fog_value(float z, float *f_val)
1231 f_float = 1.0f - ((gr_screen.fog_far - z) / (gr_screen.fog_far - gr_screen.fog_near));
1233 if (f_float < 0.0f) {
1235 } else if (f_float > 1.0f) {
1242 static void gr_opengl_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
1245 float u_scale = 1.0f, v_scale = 1.0f;
1247 // Make nebula use the texture mapper... this blends the colors better.
1248 if ( flags & TMAP_FLAG_NEBULA ){
1252 gr_texture_source texture_source = (gr_texture_source)-1;
1253 gr_alpha_blend alpha_blend = (gr_alpha_blend)-1;
1254 gr_zbuffer_type zbuffer_type = (gr_zbuffer_type)-1;
1256 if ( gr_zbuffering ) {
1257 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
1258 zbuffer_type = ZBUFFER_TYPE_READ;
1260 zbuffer_type = ZBUFFER_TYPE_FULL;
1263 zbuffer_type = ZBUFFER_TYPE_NONE;
1268 int tmap_type = TCACHE_TYPE_NORMAL;
1272 if ( flags & TMAP_FLAG_TEXTURED ) {
1275 r = gr_screen.current_color.red;
1276 g = gr_screen.current_color.green;
1277 b = gr_screen.current_color.blue;
1280 if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER )
1283 tmap_type = TCACHE_TYPE_NORMAL;
1284 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
1286 // Blend with screen pixel using src*alpha+dst
1287 float factor = gr_screen.current_alpha;
1291 if ( factor <= 1.0f ) {
1292 int tmp_alpha = fl2i(gr_screen.current_alpha*255.0f);
1293 r = (r*tmp_alpha)/255;
1294 g = (g*tmp_alpha)/255;
1295 b = (b*tmp_alpha)/255;
1298 tmap_type = TCACHE_TYPE_XPARENT;
1300 alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
1302 // Blend with screen pixel using src*alpha+dst
1303 float factor = gr_screen.current_alpha;
1305 if ( factor > 1.0f ) {
1308 alpha = fl2i(gr_screen.current_alpha*255.0f);
1312 if(Bm_pixel_format == BM_PIXEL_FORMAT_ARGB) {
1313 alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
1315 alpha_blend = ALPHA_BLEND_NONE;
1320 if(flags & TMAP_FLAG_BITMAP_SECTION){
1321 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
1324 texture_source = TEXTURE_SOURCE_NONE;
1326 if ( flags & TMAP_FLAG_TEXTURED ) {
1327 if ( !gr_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0 ))
1329 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
1333 // use nonfiltered textures for bitmap sections
1334 if(flags & TMAP_FLAG_BITMAP_SECTION){
1335 texture_source = TEXTURE_SOURCE_NO_FILTERING;
1337 texture_source = TEXTURE_SOURCE_DECAL;
1342 gr_opengl_set_state( texture_source, alpha_blend, zbuffer_type );
1344 if ( flags & TMAP_FLAG_TEXTURED )
1350 float fr = 1.0f, fg = 1.0f, fb = 1.0f;
1352 if (flags & TMAP_FLAG_PIXEL_FOG) {
1358 for (i=nv-1;i>=0;i--) // DDOI - change polygon winding
1360 vertex * va = verts[i];
1364 x = fl2i(va->sx*16.0f);
1365 y = fl2i(va->sy*16.0f);
1367 x += gr_screen.offset_x*16;
1368 y += gr_screen.offset_y*16;
1370 sx = i2fl(x) / 16.0f;
1371 sy = i2fl(y) / 16.0f;
1373 neb2_get_pixel((int)sx, (int)sy, &r, &g, &b);
1384 gr_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
1391 glBegin(GL_TRIANGLE_FAN);
1392 for (i = nv-1; i >= 0; i--) {
1393 vertex * va = verts[i];
1399 if ( gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) {
1400 sz = 1.0 - 1.0 / (1.0 + va->z / (32768.0 / 256.0));
1409 if ( flags & TMAP_FLAG_CORRECT ) {
1415 if (flags & TMAP_FLAG_ALPHA) {
1421 if (flags & TMAP_FLAG_NEBULA ) {
1422 int pal = (verts[i]->b*(NEBULA_COLORS-1))/255;
1423 r = gr_palette[pal*3+0];
1424 g = gr_palette[pal*3+1];
1425 b = gr_palette[pal*3+2];
1426 } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) {
1427 r = Gr_gamma_lookup[verts[i]->b];
1428 g = Gr_gamma_lookup[verts[i]->b];
1429 b = Gr_gamma_lookup[verts[i]->b];
1430 } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
1431 // Make 0.75 be 256.0f
1432 r = Gr_gamma_lookup[verts[i]->r];
1433 g = Gr_gamma_lookup[verts[i]->g];
1434 b = Gr_gamma_lookup[verts[i]->b];
1436 // use constant RGB values...
1438 glColor4ub (r,g,b,a);
1440 if((gr_screen.current_fog_mode != GR_FOGMODE_NONE) && (D3D_fog_mode == 1)){
1443 gr_opengl_stuff_fog_value(va->z, &f_val);
1445 glSecondaryColor3fEXT(fr * f_val, fg * f_val, fb * f_val);
1449 x = fl2i(va->sx*16.0f);
1450 y = fl2i(va->sy*16.0f);
1452 x += gr_screen.offset_x*16;
1453 y += gr_screen.offset_y*16;
1455 sx = i2fl(x) / 16.0f;
1456 sy = i2fl(y) / 16.0f;
1458 if ( flags & TMAP_FLAG_TEXTURED ) {
1461 glTexCoord2f(tu, tv);
1464 glVertex4f(sx/rhw, sy/rhw, -sz/rhw, 1.0/rhw);
1469 void gr_opengl_tmapper( int nverts, vertex **verts, uint flags )
1471 gr_opengl_tmapper_internal( nverts, verts, flags, 0 );
1474 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
1476 void gr_opengl_scaler(vertex *va, vertex *vb )
1478 float x0, y0, x1, y1;
1479 float u0, v0, u1, v1;
1480 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
1481 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
1482 float xmin, xmax, ymin, ymax;
1483 int dx0, dy0, dx1, dy1;
1485 //============= CLIP IT =====================
1487 x0 = va->sx; y0 = va->sy;
1488 x1 = vb->sx; y1 = vb->sy;
1490 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
1491 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
1493 u0 = va->u; v0 = va->v;
1494 u1 = vb->u; v1 = vb->v;
1496 // Check for obviously offscreen bitmaps...
1497 if ( (y1<=y0) || (x1<=x0) ) return;
1498 if ( (x1<xmin ) || (x0>xmax) ) return;
1499 if ( (y1<ymin ) || (y0>ymax) ) return;
1501 clipped_u0 = u0; clipped_v0 = v0;
1502 clipped_u1 = u1; clipped_v1 = v1;
1504 clipped_x0 = x0; clipped_y0 = y0;
1505 clipped_x1 = x1; clipped_y1 = y1;
1507 // Clip the left, moving u0 right as necessary
1509 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
1513 // Clip the right, moving u1 left as necessary
1515 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
1519 // Clip the top, moving v0 down as necessary
1521 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
1525 // Clip the bottom, moving v1 up as necessary
1527 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
1531 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
1532 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
1534 if (dx1<=dx0) return;
1535 if (dy1<=dy0) return;
1537 //============= DRAW IT =====================
1543 v[0].sx = clipped_x0;
1544 v[0].sy = clipped_y0;
1547 v[0].u = clipped_u0;
1548 v[0].v = clipped_v0;
1551 v[1].sx = clipped_x1;
1552 v[1].sy = clipped_y0;
1555 v[1].u = clipped_u1;
1556 v[1].v = clipped_v0;
1559 v[2].sx = clipped_x1;
1560 v[2].sy = clipped_y1;
1563 v[2].u = clipped_u1;
1564 v[2].v = clipped_v1;
1567 v[3].sx = clipped_x0;
1568 v[3].sy = clipped_y1;
1571 v[3].u = clipped_u0;
1572 v[3].v = clipped_v1;
1574 gr_opengl_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );
1577 void gr_opengl_set_palette(ubyte *new_palette, int is_alphacolor)
1581 void gr_opengl_get_color( int * r, int * g, int * b )
1583 if (r) *r = gr_screen.current_color.red;
1584 if (g) *g = gr_screen.current_color.green;
1585 if (b) *b = gr_screen.current_color.blue;
1588 void gr_opengl_init_color(color *c, int r, int g, int b)
1590 c->screen_sig = gr_screen.signature;
1591 c->red = (unsigned char)r;
1592 c->green = (unsigned char)g;
1593 c->blue = (unsigned char)b;
1595 c->ac_type = AC_TYPE_NONE;
1597 c->is_alphacolor = 0;
1601 void gr_opengl_init_alphacolor( color *clr, int r, int g, int b, int alpha, int type )
1603 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
1604 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
1605 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
1606 if ( alpha < 0 ) alpha = 0; else if ( alpha > 255 ) alpha = 255;
1608 gr_opengl_init_color( clr, r, g, b );
1610 clr->alpha = (unsigned char)alpha;
1611 clr->ac_type = (ubyte)type;
1612 clr->alphacolor = -1;
1613 clr->is_alphacolor = 1;
1616 void gr_opengl_set_color( int r, int g, int b )
1618 SDL_assert((r >= 0) && (r < 256));
1619 SDL_assert((g >= 0) && (g < 256));
1620 SDL_assert((b >= 0) && (b < 256));
1622 gr_opengl_init_color( &gr_screen.current_color, r, g, b );
1625 void gr_opengl_set_color_fast(color *dst)
1627 if ( dst->screen_sig != gr_screen.signature ) {
1628 if ( dst->is_alphacolor ) {
1629 gr_opengl_init_alphacolor( dst, dst->red, dst->green, dst->blue, dst->alpha, dst->ac_type );
1631 gr_opengl_init_color( dst, dst->red, dst->green, dst->blue );
1634 gr_screen.current_color = *dst;
1637 void gr_opengl_print_screen(const char *filename)
1639 char tmp[MAX_FILENAME_LEN];
1642 strcpy( tmp, filename );
1643 strcat( tmp, NOX(".tga"));
1645 buf = (ubyte*)malloc(GL_viewport_w * GL_viewport_h * 3);
1651 CFILE *f = cfopen(tmp, "wb", CFILE_NORMAL, CF_TYPE_ROOT);
1658 // Write the TGA header
1659 cfwrite_ubyte( 0, f ); // IDLength;
1660 cfwrite_ubyte( 0, f ); // ColorMapType;
1661 cfwrite_ubyte( 2, f ); // ImageType; // 2 = 24bpp, uncompressed, 10=24bpp rle compressed
1662 cfwrite_ushort( 0, f ); // CMapStart;
1663 cfwrite_ushort( 0, f ); // CMapLength;
1664 cfwrite_ubyte( 0, f ); // CMapDepth;
1665 cfwrite_ushort( 0, f ); // XOffset;
1666 cfwrite_ushort( 0, f ); // YOffset;
1667 cfwrite_ushort( (ushort)GL_viewport_w, f ); // Width;
1668 cfwrite_ushort( (ushort)GL_viewport_h, f ); // Height;
1669 cfwrite_ubyte( 24, f ); //PixelDepth;
1670 cfwrite_ubyte( 0, f ); //ImageDesc;
1672 memset(buf, 0, GL_viewport_w * GL_viewport_h * 3);
1674 glReadPixels(GL_viewport_x, GL_viewport_y, GL_viewport_w, GL_viewport_h, GL_BGR, GL_UNSIGNED_BYTE, buf);
1676 cfwrite(buf, GL_viewport_w * GL_viewport_h * 3, 1, f);
1683 int gr_opengl_supports_res_ingame(int res)
1688 int gr_opengl_supports_res_interface(int res)
1693 static void opengl_tcache_cleanup ();
1695 void gr_opengl_cleanup()
1697 if ( !Inited ) return;
1704 opengl_tcache_cleanup ();
1706 SDL_GL_DeleteContext(GL_context);
1711 void gr_opengl_fog_set(int fog_mode, int r, int g, int b, float fog_near, float fog_far)
1713 SDL_assert((r >= 0) && (r < 256));
1714 SDL_assert((g >= 0) && (g < 256));
1715 SDL_assert((b >= 0) && (b < 256));
1717 if (fog_mode == GR_FOGMODE_NONE) {
1718 if (gr_screen.current_fog_mode != fog_mode) {
1721 if (D3D_fog_mode == 1) {
1722 glDisable(GL_COLOR_SUM);
1726 gr_screen.current_fog_mode = fog_mode;
1731 if (gr_screen.current_fog_mode != fog_mode) {
1734 if (D3D_fog_mode == 1) {
1735 glEnable(GL_COLOR_SUM);
1736 } else if (D3D_fog_mode == 2) {
1737 glFogi(GL_FOG_MODE, GL_LINEAR);
1740 gr_screen.current_fog_mode = fog_mode;
1743 if ( (gr_screen.current_fog_color.red != r) ||
1744 (gr_screen.current_fog_color.green != g) ||
1745 (gr_screen.current_fog_color.blue != b) ) {
1748 gr_opengl_init_color( &gr_screen.current_fog_color, r, g, b );
1750 fc[0] = (float)r/255.0;
1751 fc[1] = (float)g/255.0;
1752 fc[2] = (float)b/255.0;
1755 glFogfv(GL_FOG_COLOR, fc);
1758 if( (fog_near >= 0.0f) && (fog_far >= 0.0f) &&
1759 ((fog_near != gr_screen.fog_near) ||
1760 (fog_far != gr_screen.fog_far)) ) {
1761 gr_screen.fog_near = fog_near;
1762 gr_screen.fog_far = fog_far;
1764 if (D3D_fog_mode == 2) {
1765 glFogf(GL_FOG_START, fog_near);
1766 glFogf(GL_FOG_END, fog_far);
1771 void gr_opengl_get_pixel(int x, int y, int *r, int *g, int *b)
1776 void gr_opengl_set_cull(int cull)
1779 glEnable (GL_CULL_FACE);
1780 glFrontFace (GL_CCW);
1782 glDisable (GL_CULL_FACE);
1786 void gr_opengl_filter_set(int filter)
1791 void gr_opengl_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
1793 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
1796 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
1801 typedef struct tcache_slot_opengl {
1802 GLuint texture_handle;
1803 float u_scale, v_scale;
1806 int used_this_frame;
1811 tcache_slot_opengl *data_sections[MAX_BMAP_SECTIONS_X][MAX_BMAP_SECTIONS_Y];
1812 tcache_slot_opengl *parent;
1814 gr_texture_source texture_mode;
1815 } tcache_slot_opengl;
1817 static void *Texture_sections = NULL;
1818 static tcache_slot_opengl *Textures = NULL;
1820 static tcache_slot_opengl *GL_bound_texture;
1822 int GL_texture_sections = 0;
1823 int GL_texture_ram = 0;
1824 int GL_frame_count = 0;
1825 int GL_min_texture_width = 0;
1826 int GL_max_texture_width = 0;
1827 int GL_min_texture_height = 0;
1828 int GL_max_texture_height = 0;
1829 int GL_square_textures = 0;
1830 int GL_textures_in = 0;
1831 int GL_textures_in_frame = 0;
1832 int GL_last_bitmap_id = -1;
1833 int GL_last_detail = -1;
1834 int GL_last_bitmap_type = -1;
1835 int GL_last_section_x = -1;
1836 int GL_last_section_y = -1;
1840 static gr_texture_source GL_current_texture_source = (gr_texture_source) -1;
1842 static void gr_opengl_set_texture_state(gr_texture_source ts)
1844 if (ts == TEXTURE_SOURCE_NONE) {
1845 GL_bound_texture = NULL;
1847 glBindTexture(GL_TEXTURE_2D, 0);
1848 gr_tcache_set(-1, -1, NULL, NULL, 0, -1, -1, 0 );
1849 } else if (GL_bound_texture &&
1850 GL_bound_texture->texture_mode != ts) {
1852 case TEXTURE_SOURCE_DECAL:
1853 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1854 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1856 case TEXTURE_SOURCE_NO_FILTERING:
1857 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1858 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1864 GL_bound_texture->texture_mode = ts;
1867 GL_current_texture_source = ts;
1870 static int opengl_max_tex_size_get()
1872 GLint max_texture_size = 0;
1874 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &max_texture_size );
1875 return max_texture_size;
1878 static void opengl_tcache_init (int use_sections)
1882 // DDOI - FIXME skipped a lot of stuff here
1883 GL_should_preload = 0;
1885 //uint tmp_pl = os_config_read_uint( NULL, NOX("D3DPreloadTextures"), 255 );
1888 if ( tmp_pl == 0 ) {
1889 GL_should_preload = 0;
1890 } else if ( tmp_pl == 1 ) {
1891 GL_should_preload = 1;
1893 GL_should_preload = 1;
1898 GL_min_texture_width = 16;
1899 GL_min_texture_height = 16;
1901 GL_max_texture_width = opengl_max_tex_size_get();
1902 GL_max_texture_height = opengl_max_tex_size_get();
1904 Textures = (tcache_slot_opengl *)malloc(MAX_BITMAPS*sizeof(tcache_slot_opengl));
1910 Texture_sections = (tcache_slot_opengl*)malloc(MAX_BITMAPS * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y * sizeof(tcache_slot_opengl));
1911 if(!Texture_sections){
1914 memset(Texture_sections, 0, MAX_BITMAPS * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y * sizeof(tcache_slot_opengl));
1917 // Init the texture structures
1918 int section_count = 0;
1919 for( i=0; i<MAX_BITMAPS; i++ ) {
1921 Textures[i].vram_texture = NULL;
1922 Textures[i].vram_texture_surface = NULL;
1924 Textures[i].texture_handle = 0;
1926 Textures[i].bitmap_id = -1;
1927 Textures[i].size = 0;
1928 Textures[i].used_this_frame = 0;
1930 Textures[i].parent = NULL;
1932 // allocate sections
1934 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
1935 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
1936 Textures[i].data_sections[idx][s_idx] = &((tcache_slot_opengl*)Texture_sections)[section_count++];
1937 Textures[i].data_sections[idx][s_idx]->parent = &Textures[i];
1939 Textures[i].data_sections[idx][s_idx]->vram_texture = NULL;
1940 Textures[i].data_sections[idx][s_idx]->vram_texture_surface = NULL;
1942 Textures[i].data_sections[idx][s_idx]->texture_handle = 0;
1943 Textures[i].data_sections[idx][s_idx]->bitmap_id = -1;
1944 Textures[i].data_sections[idx][s_idx]->size = 0;
1945 Textures[i].data_sections[idx][s_idx]->used_this_frame = 0;
1949 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
1950 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
1951 Textures[i].data_sections[idx][s_idx] = NULL;
1957 GL_texture_sections = use_sections;
1959 GL_last_detail = Detail.hardware_textures;
1960 GL_last_bitmap_id = -1;
1961 GL_last_bitmap_type = -1;
1963 GL_last_section_x = -1;
1964 GL_last_section_y = -1;
1967 GL_textures_in_frame = 0;
1970 static int opengl_free_texture (tcache_slot_opengl *t);
1972 void opengl_free_texture_with_handle(int handle)
1974 for(int i=0; i<MAX_BITMAPS; i++ ) {
1975 if (Textures[i].bitmap_id == handle) {
1976 Textures[i].used_this_frame = 0; // this bmp doesn't even exist any longer...
1977 opengl_free_texture ( &Textures[i] );
1982 static void opengl_tcache_flush ()
1986 for( i=0; i<MAX_BITMAPS; i++ ) {
1987 opengl_free_texture ( &Textures[i] );
1989 if (GL_textures_in != 0) {
1990 mprintf(( "WARNING: VRAM is at %d instead of zero after flushing!\n", GL_textures_in ));
1994 GL_last_bitmap_id = -1;
1995 GL_last_section_x = -1;
1996 GL_last_section_y = -1;
1999 static void opengl_tcache_cleanup ()
2001 opengl_tcache_flush ();
2004 GL_textures_in_frame = 0;
2011 if( Texture_sections != NULL ){
2012 free(Texture_sections);
2013 Texture_sections = NULL;
2017 static void opengl_tcache_frame ()
2019 GL_last_bitmap_id = -1;
2020 GL_textures_in_frame = 0;
2027 for( i=0; i<MAX_BITMAPS; i++ ) {
2028 Textures[i].used_this_frame = 0;
2031 if(Textures[i].data_sections[0][0] != NULL){
2032 SDL_assert(GL_texture_sections);
2033 if(GL_texture_sections){
2034 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
2035 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
2036 if(Textures[i].data_sections[idx][s_idx] != NULL){
2037 Textures[i].data_sections[idx][s_idx]->used_this_frame = 0;
2047 opengl_tcache_flush();
2052 static int opengl_free_texture ( tcache_slot_opengl *t )
2058 if ( t->bitmap_id > -1 ) {
2059 // if I, or any of my children have been used this frame, bail
2060 if(t->used_this_frame == GL_frame_count){
2063 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
2064 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
2065 if((t->data_sections[idx][s_idx] != NULL) && (t->data_sections[idx][s_idx]->used_this_frame == GL_frame_count)){
2071 // ok, now we know its legal to free everything safely
2072 t->texture_mode = (gr_texture_source) -1;
2073 glDeleteTextures (1, &t->texture_handle);
2074 t->texture_handle = 0;
2076 if ( GL_last_bitmap_id == t->bitmap_id ) {
2077 GL_last_bitmap_id = -1;
2080 // if this guy has children, free them too, since the children
2081 // actually make up his size
2082 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
2083 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
2084 if(t->data_sections[idx][s_idx] != NULL){
2085 opengl_free_texture(t->data_sections[idx][s_idx]);
2091 t->used_this_frame = 0;
2092 GL_textures_in -= t->size;
2099 static void opengl_tcache_get_adjusted_texture_size(int w_in, int h_in, int *w_out, int *h_out)
2105 if((w_out == NULL) || (h_out == NULL)){
2113 // set height and width to a power of 2
2114 for (i=0; i<16; i++ ) {
2115 if ( (tex_w > (1<<i)) && (tex_w <= (1<<(i+1))) ) {
2121 for (i=0; i<16; i++ ) {
2122 if ( (tex_h > (1<<i)) && (tex_h <= (1<<(i+1))) ) {
2128 // try to keep an 8:1 size ratio
2129 if (tex_w/tex_h > 8)
2131 if (tex_h/tex_w > 8)
2134 if ( tex_w < GL_min_texture_width ) {
2135 tex_w = GL_min_texture_width;
2136 } else if ( tex_w > GL_max_texture_width ) {
2137 tex_w = GL_max_texture_width;
2140 if ( tex_h < GL_min_texture_height ) {
2141 tex_h = GL_min_texture_height;
2142 } else if ( tex_h > GL_max_texture_height ) {
2143 tex_h = GL_max_texture_height;
2146 if ( GL_square_textures) {
2148 // Make the both be equal to larger of the two
2149 new_size = max(tex_w, tex_h);
2154 // store the outgoing size
2159 // data == start of bitmap data
2160 // sx == x offset into bitmap
2161 // sy == y offset into bitmap
2162 // src_w == absolute width of section on source bitmap
2163 // src_h == absolute height of section on source bitmap
2164 // bmap_w == width of source bitmap
2165 // bmap_h == height of source bitmap
2166 // tex_w == width of final texture
2167 // tex_h == height of final texture
2168 static int opengl_create_texture_sub(int bitmap_type, int texture_handle, ushort *data, int sx, int sy, int src_w, int src_h, int bmap_w, int bmap_h, int tex_w, int tex_h, tcache_slot_opengl *t, int reload, int resize, int fail_on_full)
2173 ubyte *bmp_data = ((ubyte*)data);
2174 ubyte *texmem = NULL, *texmemp;
2177 if((t == NULL) || (bmp_data == NULL)){
2181 if ( t->used_this_frame == GL_frame_count ) {
2182 mprintf(( "ARGHH!!! Texture already used this frame! Cannot free it!\n" ));
2187 if(!opengl_free_texture(t)){
2192 if ( bitmap_type == TCACHE_TYPE_AABITMAP ) {
2193 t->u_scale = (float)bmap_w / (float)tex_w;
2194 t->v_scale = (float)bmap_h / (float)tex_h;
2195 } else if(bitmap_type == TCACHE_TYPE_BITMAP_SECTION){
2196 t->u_scale = (float)src_w / (float)tex_w;
2197 t->v_scale = (float)src_h / (float)tex_h;
2204 glGenTextures (1, &t->texture_handle);
2207 if (t->texture_handle == 0) {
2208 nprintf(("Error", "!!DEBUG!! t->texture_handle == 0"));
2212 GL_bound_texture = t;
2214 GL_bound_texture->texture_mode = (gr_texture_source) -1;
2216 glBindTexture (GL_TEXTURE_2D, t->texture_handle);
2218 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2219 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2220 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2222 /* this should be set next anyway */
2223 // if (GL_current_texture_source != TEXTURE_SOURCE_NONE) {
2224 // gr_opengl_set_texture_state(GL_current_texture_source);
2229 switch (bitmap_type) {
2231 case TCACHE_TYPE_AABITMAP:
2233 texmem = (ubyte *) malloc (tex_w*tex_h);
2236 for (i=0;i<tex_h;i++)
2238 for (j=0;j<tex_w;j++)
2240 if (i < bmap_h && j < bmap_w) {
2241 *texmemp++ = GL_xlat[bmp_data[i*bmap_w+j]];
2251 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, tex_w, tex_h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texmem);
2253 glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, tex_w, tex_h, GL_ALPHA, GL_UNSIGNED_BYTE, texmem);
2261 case TCACHE_TYPE_BITMAP_SECTION:
2263 // if we aren't resizing in any way then we can just use bmp_data directly
2265 texmem = (ubyte *) malloc (tex_w*tex_h*2);
2268 for (i=0;i<tex_h;i++) {
2269 for (j=0;j<tex_w;j++) {
2270 if (i < src_h && j < src_w) {
2271 *texmemp++ = bmp_data[((i+sy)*bmap_w+(j+sx))*2+0];
2272 *texmemp++ = bmp_data[((i+sy)*bmap_w+(j+sx))*2+1];
2281 size = tex_w*tex_h*2;
2284 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB5_A1, tex_w, tex_h, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, (resize) ? texmem : bmp_data);
2286 glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, tex_w, tex_h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, (resize) ? texmem : bmp_data);
2297 // if we aren't resizing then we can just use bmp_data directly
2299 texmem = (ubyte *) malloc (tex_w*tex_h*2);
2302 SDL_assert( texmem != NULL );
2304 fix u, utmp, v, du, dv;
2308 du = ( (bmap_w-1)*F1_0 ) / tex_w;
2309 dv = ( (bmap_h-1)*F1_0 ) / tex_h;
2311 for (j=0;j<tex_h;j++) {
2313 for (i=0;i<tex_w;i++) {
2314 *texmemp++ = bmp_data[(f2i(v)*bmap_w+f2i(utmp))*2+0];
2315 *texmemp++ = bmp_data[(f2i(v)*bmap_w+f2i(utmp))*2+1];
2322 size = tex_w*tex_h*2;
2325 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB5_A1, tex_w, tex_h, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, (resize) ? texmem : bmp_data);
2327 glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, tex_w, tex_h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, (resize) ? texmem : bmp_data);
2339 t->bitmap_id = texture_handle;
2340 t->time_created = GL_frame_count;
2341 t->used_this_frame = 0;
2343 t->w = (ushort)tex_w;
2344 t->h = (ushort)tex_h;
2346 GL_textures_in_frame += t->size;
2348 GL_textures_in += t->size;
2354 static int opengl_create_texture (int bitmap_handle, int bitmap_type, tcache_slot_opengl *tslot, int fail_on_full)
2358 int final_w, final_h;
2363 // setup texture/bitmap flags
2365 switch(bitmap_type){
2366 case TCACHE_TYPE_AABITMAP:
2367 flags |= BMP_AABITMAP;
2370 case TCACHE_TYPE_NORMAL:
2371 flags |= BMP_TEX_OTHER;
2372 case TCACHE_TYPE_XPARENT:
2373 flags |= BMP_TEX_XPARENT;
2375 case TCACHE_TYPE_NONDARKENING:
2377 flags |= BMP_TEX_NONDARK;
2381 // lock the bitmap into the proper format
2382 bmp = bm_lock(bitmap_handle, bpp, flags);
2383 if ( bmp == NULL ) {
2384 mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle ));
2393 if ( bitmap_type != TCACHE_TYPE_AABITMAP ) {
2394 // max_w /= D3D_texture_divider;
2395 // max_h /= D3D_texture_divider;
2397 // if we are going to cull the size then we need to force a resize
2398 if (Detail.hardware_textures < 4) {
2402 // Detail.debris_culling goes from 0 to 4.
2403 max_w /= (16 >> Detail.hardware_textures);
2404 max_h /= (16 >> Detail.hardware_textures);
2408 // get final texture size as it will be allocated as a DD surface
2409 opengl_tcache_get_adjusted_texture_size(max_w, max_h, &final_w, &final_h);
2411 if ( (final_w < 1) || (final_h < 1) ) {
2412 mprintf(("Bitmap is too small at %dx%d.\n", final_w, final_h));
2416 // if we don't have to resize the image (to get power of 2, etc.) then skip that extra work
2417 if ( (max_w != final_w) || (max_h != final_h) ) {
2421 // if this tcache slot has no bitmap
2422 if ( tslot->bitmap_id < 0) {
2425 // different bitmap altogether - determine if the new one can use the old one's slot
2426 else if (tslot->bitmap_id != bitmap_handle) {
2427 if((final_w == tslot->w) && (final_h == tslot->h)){
2429 //ml_printf("Reloading texture %d\n", bitmap_handle);
2436 int ret_val = opengl_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, 0, 0, bmp->w, bmp->h, bmp->w, bmp->h, final_w, final_h, tslot, reload, resize, fail_on_full);
2438 // unlock the bitmap
2439 bm_unlock(bitmap_handle);
2444 static int opengl_create_texture_sectioned(int bitmap_handle, int bitmap_type, tcache_slot_opengl *tslot, int sx, int sy, int fail_on_full)
2448 int final_w, final_h;
2449 int section_x, section_y;
2453 // setup texture/bitmap flags
2454 SDL_assert(bitmap_type == TCACHE_TYPE_BITMAP_SECTION);
2455 if(bitmap_type != TCACHE_TYPE_BITMAP_SECTION){
2456 bitmap_type = TCACHE_TYPE_BITMAP_SECTION;
2458 flags = BMP_TEX_XPARENT;
2460 // lock the bitmap in the proper format
2461 bmp = bm_lock(bitmap_handle, 16, flags);
2462 if ( bmp == NULL ) {
2463 mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle ));
2466 // determine the width and height of this section
2467 bm_get_section_size(bitmap_handle, sx, sy, §ion_x, §ion_y);
2469 // get final texture size as it will be allocated as an opengl texture
2470 opengl_tcache_get_adjusted_texture_size(section_x, section_y, &final_w, &final_h);
2472 if ( (final_w < 1) || (final_h < 1) ) {
2473 mprintf(("Bitmap is too small at %dx%d.\n", final_w, final_h));
2477 // if we don't have to resize the image (to get power of 2, etc.) then skip that extra work
2478 if ( (bmp->sections.num_x == 1) && (bmp->sections.num_y == 1) && (section_x == final_w) && (section_y == final_h) ) {
2482 // if this tcache slot has no bitmap
2483 if ( tslot->bitmap_id < 0) {
2486 // different bitmap altogether - determine if the new one can use the old one's slot
2487 else if (tslot->bitmap_id != bitmap_handle) {
2488 if((final_w == tslot->w) && (final_h == tslot->h)){
2496 int ret_val = opengl_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, bmp->sections.sx[sx], bmp->sections.sy[sy], section_x, section_y, bmp->w, bmp->h, final_w, final_h, tslot, reload, resize, fail_on_full);
2498 // unlock the bitmap
2499 bm_unlock(bitmap_handle);
2505 extern int bm_get_cache_slot( int bitmap_id, int separate_ani_frames );
2506 static int gr_opengl_tcache_set(int bitmap_id, int bitmap_type, float *u_scale, float *v_scale, int fail_on_full = 0, int sx = -1, int sy = -1, int force = 0)
2515 GL_last_bitmap_id = -1;
2519 if ( GL_last_detail != Detail.hardware_textures ) {
2520 GL_last_detail = Detail.hardware_textures;
2521 opengl_tcache_flush();
2528 int n = bm_get_cache_slot (bitmap_id, 1);
2529 tcache_slot_opengl *t = &Textures[n];
2531 if ( (GL_last_bitmap_id == bitmap_id) && (GL_last_bitmap_type==bitmap_type) && (t->bitmap_id == bitmap_id) && (GL_last_section_x == sx) && (GL_last_section_y == sy)) {
2532 t->used_this_frame = GL_frame_count;
2534 // mark all children as used
2535 if(GL_texture_sections){
2536 for(idx=0; idx<MAX_BMAP_SECTIONS_X; idx++){
2537 for(s_idx=0; s_idx<MAX_BMAP_SECTIONS_Y; s_idx++){
2538 if(t->data_sections[idx][s_idx] != NULL){
2539 t->data_sections[idx][s_idx]->used_this_frame = GL_frame_count;
2545 *u_scale = t->u_scale;
2546 *v_scale = t->v_scale;
2550 if (bitmap_type == TCACHE_TYPE_BITMAP_SECTION){
2551 SDL_assert((sx >= 0) && (sy >= 0) && (sx < MAX_BMAP_SECTIONS_X) && (sy < MAX_BMAP_SECTIONS_Y));
2552 if(!((sx >= 0) && (sy >= 0) && (sx < MAX_BMAP_SECTIONS_X) && (sy < MAX_BMAP_SECTIONS_Y))){
2558 // if the texture sections haven't been created yet
2559 if((t->bitmap_id < 0) || (t->bitmap_id != bitmap_id)){
2561 // lock the bitmap in the proper format
2562 bmp = bm_lock(bitmap_id, 16, BMP_TEX_XPARENT);
2563 bm_unlock(bitmap_id);
2565 // now lets do something for each texture
2567 for(idx=0; idx<bmp->sections.num_x; idx++){
2568 for(s_idx=0; s_idx<bmp->sections.num_y; s_idx++){
2569 // hmm. i'd rather we didn't have to do it this way...
2570 if(!opengl_create_texture_sectioned(bitmap_id, bitmap_type, t->data_sections[idx][s_idx], idx, s_idx, fail_on_full)){
2574 // not used this frame
2575 t->data_sections[idx][s_idx]->used_this_frame = 0;
2579 // zero out pretty much everything in the parent struct since he's just the root
2580 t->bitmap_id = bitmap_id;
2581 t->texture_handle = 0;
2582 t->time_created = t->data_sections[sx][sy]->time_created;
2583 t->used_this_frame = 0;
2585 t->vram_texture = NULL;
2586 t->vram_texture_surface = NULL
2590 // argh. we failed to upload. free anything we can
2592 opengl_free_texture(t);
2594 // swap in the texture we want
2596 t = t->data_sections[sx][sy];
2599 // all other "normal" textures
2600 else if((bitmap_id < 0) || (bitmap_id != t->bitmap_id)){
2601 ret_val = opengl_create_texture( bitmap_id, bitmap_type, t, fail_on_full );
2604 // everything went ok
2605 if(ret_val && (t->texture_handle) && !vram_full){
2606 *u_scale = t->u_scale;
2607 *v_scale = t->v_scale;
2609 GL_bound_texture = t;
2611 glBindTexture (GL_TEXTURE_2D, t->texture_handle );
2613 /* this should be set next anyway */
2614 // if (GL_current_texture_source != TEXTURE_SOURCE_NONE) {
2615 // gr_opengl_set_texture_state(GL_current_texture_source);
2618 GL_last_bitmap_id = t->bitmap_id;
2619 GL_last_bitmap_type = bitmap_type;
2620 GL_last_section_x = sx;
2621 GL_last_section_y = sy;
2623 t->used_this_frame = GL_frame_count;
2627 GL_last_bitmap_id = -1;
2628 GL_last_bitmap_type = -1;
2630 GL_last_section_x = -1;
2631 GL_last_section_y = -1;
2633 GL_bound_texture = NULL;
2635 glBindTexture (GL_TEXTURE_2D, 0); // test - DDOI
2642 void gr_opengl_set_clear_color(int r, int g, int b)
2644 gr_init_color (&gr_screen.current_clear_color, r, g, b);
2647 void gr_opengl_flash(int r, int g, int b)
2653 if ( r || g || b ) {
2654 gr_opengl_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
2656 float x1, x2, y1, y2;
2657 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
2658 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
2659 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
2660 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
2662 glColor4ub(r, g, b, 255);
2664 glVertex3f (x1, y2, -0.99);
2666 glVertex3f (x2, y2, -0.99);
2668 glVertex3f (x2, y1, -0.99);
2670 glVertex3f (x1, y1, -0.99);
2675 int gr_opengl_zbuffer_get()
2677 if ( !gr_global_zbuffering ) {
2678 return GR_ZBUFF_NONE;
2680 return gr_zbuffering_mode;
2683 int gr_opengl_zbuffer_set(int mode)
2685 int tmp = gr_zbuffering_mode;
2687 gr_zbuffering_mode = mode;
2689 if (gr_zbuffering_mode == GR_ZBUFF_NONE ) {
2697 void gr_opengl_zbuffer_clear(int mode)
2701 gr_zbuffering_mode = GR_ZBUFF_FULL;
2702 gr_global_zbuffering = 1;
2704 gr_opengl_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_FULL );
2705 glClear ( GL_DEPTH_BUFFER_BIT );
2708 gr_zbuffering_mode = GR_ZBUFF_NONE;
2709 gr_global_zbuffering = 0;
2713 void gr_opengl_set_gamma(float gamma)
2716 Gr_gamma_int = int (Gr_gamma*10);
2718 // Create the Gamma lookup table
2720 for (i=0;i<256; i++) {
2721 int v = fl2i(pow(i2fl(i)/255.0f, 1.0f/Gr_gamma)*255.0f);
2724 } else if ( v < 0 ) {
2727 Gr_gamma_lookup[i] = v;
2730 // set the alpha gamma settings (for fonts)
2731 for (i=0; i<16; i++) {
2732 GL_xlat[i] = (ubyte)Gr_gamma_lookup[(i*255)/15];
2735 GL_xlat[15] = GL_xlat[1];
2737 for (; i<256; i++) {
2738 GL_xlat[i] = GL_xlat[0];
2741 // Flush any existing textures
2742 opengl_tcache_flush();
2745 void gr_opengl_fade_in(int instantaneous)
2750 void gr_opengl_fade_out(int instantaneous)
2755 void gr_opengl_get_region(int front, int w, int h, ubyte *data)
2758 glReadBuffer(GL_FRONT);
2760 glReadBuffer(GL_BACK);
2763 gr_opengl_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
2765 glPixelStorei(GL_UNPACK_ROW_LENGTH, GL_viewport_w);
2767 int x = GL_viewport_x;
2768 int y = (GL_viewport_y+GL_viewport_h)-h-1;
2770 if (gr_screen.bits_per_pixel == 15) {
2771 glReadPixels(x, y, w, h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, data);
2772 } else if (gr_screen.bits_per_pixel == 32) {
2773 glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
2776 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
2779 void gr_opengl_save_mouse_area(int x, int y, int w, int h)
2783 w = fl2i((w * GL_viewport_scale_w) + 0.5f);
2784 h = fl2i((h * GL_viewport_scale_h) + 0.5f);
2791 CLAMP(x1, 0, GL_viewport_w);
2792 CLAMP(x2, 0, GL_viewport_w);
2793 CLAMP(y1, 0, GL_viewport_h);
2794 CLAMP(y2, 0, GL_viewport_h);
2796 Gr_opengl_mouse_saved_x = x1;
2797 Gr_opengl_mouse_saved_y = y1;
2798 Gr_opengl_mouse_saved_w = x2 - x1 + 1;
2799 Gr_opengl_mouse_saved_h = y2 - y1 + 1;
2801 if ( (Gr_opengl_mouse_saved_w < 1) || (Gr_opengl_mouse_saved_h < 1) ) {
2805 if (Gr_opengl_mouse_saved_data == NULL) {
2806 Gr_opengl_mouse_saved_data = (ubyte*)malloc(w * h * gr_screen.bytes_per_pixel);
2808 if ( !Gr_opengl_mouse_saved_data ) {
2813 gr_opengl_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
2815 x1 = GL_viewport_x+Gr_opengl_mouse_saved_x;
2816 y1 = (GL_viewport_y+GL_viewport_h)-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
2818 glReadBuffer(GL_BACK);
2819 glReadPixels(x1, y1, Gr_opengl_mouse_saved_w, Gr_opengl_mouse_saved_h,
2820 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, Gr_opengl_mouse_saved_data);
2822 Gr_opengl_mouse_saved = 1;
2825 int gr_opengl_save_screen()
2829 if (Gr_saved_screen_tex) {
2830 mprintf(( "Screen already saved!\n" ));
2834 glGenTextures(1, &Gr_saved_screen_tex);
2836 if ( !Gr_saved_screen_tex ) {
2837 mprintf(( "Couldn't create texture for saved screen!\n" ));
2841 gr_opengl_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
2843 glBindTexture(GL_TEXTURE_2D, Gr_saved_screen_tex);
2845 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2846 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2847 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2848 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2849 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2851 glReadBuffer(GL_FRONT);
2852 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, GL_viewport_x, GL_viewport_y,
2853 GL_viewport_w, GL_viewport_h, 0);
2855 if (Gr_opengl_mouse_saved) {
2856 int x = Gr_opengl_mouse_saved_x;
2857 int y = GL_viewport_h-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
2859 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, Gr_opengl_mouse_saved_w,
2860 Gr_opengl_mouse_saved_h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
2861 Gr_opengl_mouse_saved_data);
2864 glBindTexture(GL_TEXTURE_2D, 0);
2869 void gr_opengl_restore_screen(int id)
2873 if ( !Gr_saved_screen_tex ) {
2878 glBindTexture(GL_TEXTURE_2D, Gr_saved_screen_tex);
2880 if (Gr_opengl_mouse_saved) {
2881 int x = Gr_opengl_mouse_saved_x;
2882 int y = GL_viewport_h-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
2884 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, Gr_opengl_mouse_saved_w,
2885 Gr_opengl_mouse_saved_h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
2886 Gr_opengl_mouse_saved_data);
2889 glMatrixMode(GL_MODELVIEW);
2892 glScalef(1.0f, -1.0f, 1.0f);
2896 glVertex2i(GL_viewport_x, GL_viewport_y);
2899 glVertex2i(GL_viewport_x, GL_viewport_h);
2902 glVertex2f(GL_viewport_w, GL_viewport_h);
2905 glVertex2i(GL_viewport_w, GL_viewport_y);
2910 glBindTexture(GL_TEXTURE_2D, 0);
2913 void gr_opengl_free_screen(int id)
2915 if (Gr_saved_screen_tex) {
2916 glDeleteTextures(1, &Gr_saved_screen_tex);
2917 Gr_saved_screen_tex = 0;
2921 void gr_opengl_dump_frame_start(int first_frame, int frames_between_dumps)
2926 void gr_opengl_dump_frame_stop()
2931 void gr_opengl_dump_frame()
2936 uint gr_opengl_lock()
2943 void gr_opengl_unlock()
2948 void gr_opengl_set_viewport(int width, int height)
2952 float ratio = gr_screen.max_w / i2fl(gr_screen.max_h);
2955 h = i2fl((width / ratio) + 0.5f);
2959 w = i2fl((height * ratio) + 0.5f);
2962 x = (width - w) / 2;
2963 y = (height - h) / 2;
2969 GL_viewport_scale_w = w / i2fl(gr_screen.max_w);
2970 GL_viewport_scale_h = h / i2fl(gr_screen.max_h);
2972 glViewport(GL_viewport_x, GL_viewport_y, GL_viewport_w, GL_viewport_h);
2974 glMatrixMode(GL_PROJECTION);
2976 glOrtho(0, GL_viewport_w, GL_viewport_h, 0, 0.0, 1.0);
2977 glMatrixMode(GL_MODELVIEW);
2979 glScalef(GL_viewport_scale_w, GL_viewport_scale_h, 1.0f);
2982 void gr_opengl_force_windowed()
2984 SDL_SetWindowFullscreen(GL_window, 0);
2987 void gr_opengl_force_fullscreen()
2989 int fullscreen = os_config_read_uint(NULL, "Fullscreen", 1);
2990 int flag = SDL_WINDOW_FULLSCREEN_DESKTOP;
2992 if (fullscreen == 2) {
2993 flag = SDL_WINDOW_FULLSCREEN;
2996 SDL_SetWindowFullscreen(GL_window, flag);
2999 void opengl_zbias(int bias)
3002 glEnable(GL_POLYGON_OFFSET_FILL);
3003 glPolygonOffset(0.0, -bias);
3005 glDisable(GL_POLYGON_OFFSET_FILL);
3009 extern const char *Osreg_title;
3010 void gr_opengl_init()
3013 gr_opengl_cleanup();
3017 mprintf(( "Initializing OpenGL graphics device...\n" ));
3020 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
3021 fprintf (stderr, "Couldn't init SDL: %s", SDL_GetError());
3025 int r = 5, g = 5, b = 5, bpp = 16, db = 1;
3027 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, r);
3028 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, g);
3029 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, b);
3030 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, bpp);
3031 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, db);
3033 FSAA = os_config_read_uint(NULL, "FSAA", 2);
3036 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
3037 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, FSAA);
3040 GL_window = SDL_CreateWindow(Osreg_title, SDL_WINDOWPOS_CENTERED,
3041 SDL_WINDOWPOS_CENTERED,
3042 gr_screen.max_w, gr_screen.max_h, SDL_WINDOW_OPENGL);
3045 fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
3049 GL_context = SDL_GL_CreateContext(GL_window);
3051 mprintf((" Vendor : %s\n", glGetString(GL_VENDOR)));
3052 mprintf((" Renderer : %s\n", glGetString(GL_RENDERER)));
3053 mprintf((" Version : %s\n", glGetString(GL_VERSION)));
3055 mprintf((" Attributes requested: RGB %d%d%d, BPP %d, DB %d, AA %d\n", r, g, b, bpp, db, FSAA));
3057 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r);
3058 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g);
3059 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b);
3060 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &bpp);
3061 SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &db);
3062 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &FSAA);
3064 mprintf((" Attributes received: RGB %d%d%d, BPP %d, DB %d, AA %d\n", r, g, b, bpp, db, FSAA));
3067 D3D_32bit = 1; // grd3d.cpp
3068 extern int D3D_enabled;
3072 1 = use secondary color ext
3073 2 = use opengl linear fog
3075 D3D_fog_mode = 2; // grd3d.cpp
3077 if ( SDL_GL_ExtensionSupported("GL_EXT_secondary_color") ) {
3078 glSecondaryColor3fEXT = (PFNGLSECONDARYCOLOR3FEXTPROC)SDL_GL_GetProcAddress("glSecondaryColor3fEXT");
3079 SDL_assert( glSecondaryColor3fEXT != NULL );
3081 mprintf((" Using extension: GL_EXT_secondary_color\n"));
3088 // initial setup viewport
3089 gr_opengl_set_viewport(gr_screen.max_w, gr_screen.max_h);
3091 // maybe go fullscreen - should be done *after* initial viewport setup
3092 int fullscreen = os_config_read_uint(NULL, "Fullscreen", 1);
3093 if ( !Cmdline_window && (fullscreen || Cmdline_fullscreen) ) {
3094 int flag = SDL_WINDOW_FULLSCREEN_DESKTOP;
3096 if (fullscreen == 2) {
3097 flag = SDL_WINDOW_FULLSCREEN;
3100 SDL_SetWindowFullscreen(GL_window, flag);
3103 glShadeModel(GL_SMOOTH);
3104 glEnable(GL_DITHER);
3105 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
3106 glHint(GL_FOG_HINT, GL_NICEST);
3108 glEnable(GL_DEPTH_TEST);
3111 glEnable(GL_TEXTURE_2D);
3113 glDepthRange(0.0, 1.0);
3115 glPixelStorei(GL_PACK_ALIGNMENT, 1);
3116 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3121 Bm_pixel_format = BM_PIXEL_FORMAT_ARGB;
3127 gr_screen.bits_per_pixel = 15;
3128 gr_screen.bytes_per_pixel = 2;
3133 Gr_red.mask = 0x7C00;
3138 Gr_green.mask = 0x3E0;
3143 Gr_blue.mask = 0x1F;
3148 gr_screen.bits_per_pixel = 16;
3149 gr_screen.bytes_per_pixel = 2;
3154 Gr_red.mask = 0xF800;
3159 Gr_green.mask = 0x7E0;
3164 Gr_blue.mask = 0x1F;
3169 gr_screen.bits_per_pixel = 32;
3170 gr_screen.bytes_per_pixel = 4;
3175 Gr_red.mask = 0xff0000;
3180 Gr_green.mask = 0xff00;
3185 Gr_blue.mask = 0xff;
3190 Int3(); // Illegal bpp
3193 // DDOI - set these so no one else does!
3194 Gr_t_red.mask = Gr_red.mask;
3195 Gr_t_red.shift = Gr_red.shift;
3196 Gr_t_red.scale = Gr_red.scale;
3198 Gr_t_green.mask = Gr_green.mask;
3199 Gr_t_green.shift = Gr_green.shift;
3200 Gr_t_green.scale = Gr_green.scale;
3202 Gr_t_blue.mask = Gr_blue.mask;
3203 Gr_t_blue.shift = Gr_blue.shift;
3204 Gr_t_blue.scale = Gr_blue.scale;
3206 Gr_t_alpha.mask = 0x8000;
3207 Gr_t_alpha.scale = 255;
3208 Gr_t_alpha.shift = 15;
3210 Gr_ta_red.mask = 0x0f00;
3211 Gr_ta_red.shift = 8;
3212 Gr_ta_red.scale = 16;
3214 Gr_ta_green.mask = 0x00f0;
3215 Gr_ta_green.shift = 4;
3216 Gr_ta_green.scale = 16;
3218 Gr_ta_blue.mask = 0x000f;
3219 Gr_ta_blue.shift = 0;
3220 Gr_ta_blue.scale = 16;
3222 Gr_ta_alpha.mask = 0xf000;
3223 Gr_ta_alpha.shift = 12;
3224 Gr_ta_alpha.scale = 16;
3227 opengl_tcache_init (1);
3230 Gr_current_red = &Gr_red;
3231 Gr_current_blue = &Gr_blue;
3232 Gr_current_green = &Gr_green;
3233 Gr_current_alpha = &Gr_alpha;
3235 gr_screen.gf_flip = gr_opengl_flip;
3236 gr_screen.gf_flip_window = gr_opengl_flip_window;
3237 gr_screen.gf_set_clip = gr_opengl_set_clip;
3238 gr_screen.gf_reset_clip = gr_opengl_reset_clip;
3239 gr_screen.gf_set_font = grx_set_font;
3241 gr_screen.gf_set_color = gr_opengl_set_color;
3242 gr_screen.gf_set_bitmap = gr_opengl_set_bitmap;
3243 gr_screen.gf_create_shader = gr_opengl_create_shader;
3244 gr_screen.gf_set_shader = gr_opengl_set_shader;
3245 gr_screen.gf_clear = gr_opengl_clear;
3246 // gr_screen.gf_bitmap = gr_opengl_bitmap;
3247 // gr_screen.gf_bitmap_ex = gr_opengl_bitmap_ex;
3248 gr_screen.gf_aabitmap = gr_opengl_aabitmap;
3249 gr_screen.gf_aabitmap_ex = gr_opengl_aabitmap_ex;
3251 gr_screen.gf_rect = gr_opengl_rect;
3252 gr_screen.gf_shade = gr_opengl_shade;
3253 gr_screen.gf_string = gr_opengl_string;
3254 gr_screen.gf_circle = gr_opengl_circle;
3256 gr_screen.gf_line = gr_opengl_line;
3257 gr_screen.gf_aaline = gr_opengl_aaline;
3258 gr_screen.gf_pixel = gr_opengl_pixel;
3259 gr_screen.gf_scaler = gr_opengl_scaler;
3260 gr_screen.gf_tmapper = gr_opengl_tmapper;
3262 gr_screen.gf_gradient = gr_opengl_gradient;
3264 gr_screen.gf_set_palette = gr_opengl_set_palette;
3265 gr_screen.gf_get_color = gr_opengl_get_color;
3266 gr_screen.gf_init_color = gr_opengl_init_color;
3267 gr_screen.gf_init_alphacolor = gr_opengl_init_alphacolor;
3268 gr_screen.gf_set_color_fast = gr_opengl_set_color_fast;
3269 gr_screen.gf_print_screen = gr_opengl_print_screen;
3271 gr_screen.gf_fade_in = gr_opengl_fade_in;
3272 gr_screen.gf_fade_out = gr_opengl_fade_out;
3273 gr_screen.gf_flash = gr_opengl_flash;
3275 gr_screen.gf_zbuffer_get = gr_opengl_zbuffer_get;
3276 gr_screen.gf_zbuffer_set = gr_opengl_zbuffer_set;
3277 gr_screen.gf_zbuffer_clear = gr_opengl_zbuffer_clear;
3279 gr_screen.gf_save_screen = gr_opengl_save_screen;
3280 gr_screen.gf_restore_screen = gr_opengl_restore_screen;
3281 gr_screen.gf_free_screen = gr_opengl_free_screen;
3283 gr_screen.gf_dump_frame_start = gr_opengl_dump_frame_start;
3284 gr_screen.gf_dump_frame_stop = gr_opengl_dump_frame_stop;
3285 gr_screen.gf_dump_frame = gr_opengl_dump_frame;
3287 gr_screen.gf_set_gamma = gr_opengl_set_gamma;
3289 gr_screen.gf_lock = gr_opengl_lock;
3290 gr_screen.gf_unlock = gr_opengl_unlock;
3292 gr_screen.gf_fog_set = gr_opengl_fog_set;
3294 gr_screen.gf_get_region = gr_opengl_get_region;
3296 gr_screen.gf_get_pixel = gr_opengl_get_pixel;
3298 gr_screen.gf_set_cull = gr_opengl_set_cull;
3300 gr_screen.gf_cross_fade = gr_opengl_cross_fade;
3302 gr_screen.gf_filter_set = gr_opengl_filter_set;
3304 gr_screen.gf_tcache_set = gr_opengl_tcache_set;
3306 gr_screen.gf_set_clear_color = gr_opengl_set_clear_color;