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
9 #include "SDL_opengl.h"
15 #include "gropenglinternal.h"
17 #include "grinternal.h"
21 extern bool OGL_inited;
22 extern int GL_one_inited;
24 extern void opengl_set_variables();
25 extern void opengl_init_viewport();
28 static void wxgl_init_func_pointers()
30 gr_screen.gf_flip = gr_wxgl_flip;
31 gr_screen.gf_set_clip = gr_opengl1_set_clip;
32 gr_screen.gf_reset_clip = gr_opengl_reset_clip;
34 gr_screen.gf_clear = gr_opengl_clear;
36 gr_screen.gf_aabitmap = gr_opengl1_aabitmap;
37 gr_screen.gf_aabitmap_ex = gr_opengl1_aabitmap_ex;
39 gr_screen.gf_rect = gr_opengl1_rect;
40 gr_screen.gf_shade = gr_opengl1_shade;
41 gr_screen.gf_string = gr_opengl1_string;
42 gr_screen.gf_circle = gr_opengl1_circle;
44 gr_screen.gf_line = gr_opengl1_line;
45 gr_screen.gf_aaline = gr_opengl1_aaline;
46 gr_screen.gf_pixel = gr_opengl1_pixel;
47 gr_screen.gf_scaler = gr_opengl1_scaler;
48 gr_screen.gf_tmapper = gr_opengl1_tmapper;
50 gr_screen.gf_gradient = gr_opengl1_gradient;
52 gr_screen.gf_print_screen = gr_opengl_print_screen;
54 gr_screen.gf_fade_in = gr_opengl1_fade_in;
55 gr_screen.gf_fade_out = gr_opengl1_fade_out;
56 gr_screen.gf_flash = gr_opengl1_flash;
58 gr_screen.gf_zbuffer_clear = gr_opengl1_zbuffer_clear;
60 gr_screen.gf_save_screen = gr_opengl1_save_screen;
61 gr_screen.gf_restore_screen = gr_opengl1_restore_screen;
62 gr_screen.gf_free_screen = gr_opengl1_free_screen;
64 gr_screen.gf_dump_frame_start = gr_opengl1_dump_frame_start;
65 gr_screen.gf_dump_frame_stop = gr_opengl1_dump_frame_stop;
66 gr_screen.gf_dump_frame = gr_opengl1_dump_frame;
68 gr_screen.gf_set_gamma = gr_opengl1_set_gamma;
70 gr_screen.gf_lock = gr_opengl_lock;
71 gr_screen.gf_unlock = gr_opengl_unlock;
73 gr_screen.gf_fog_set = gr_opengl1_fog_set;
75 gr_screen.gf_get_region = gr_opengl1_get_region;
77 gr_screen.gf_set_cull = gr_opengl_set_cull;
79 gr_screen.gf_cross_fade = gr_opengl1_cross_fade;
81 gr_screen.gf_preload_init = gr_opengl1_preload_init;
82 gr_screen.gf_preload = gr_opengl1_preload;
84 gr_screen.gf_zbias = gr_opengl_zbias;
86 gr_screen.gf_force_windowed = gr_opengl_force_windowed;
87 gr_screen.gf_force_fullscreen = gr_opengl_force_fullscreen;
88 gr_screen.gf_toggle_fullscreen = gr_opengl_toggle_fullscreen;
90 gr_screen.gf_set_viewport = gr_wxgl_set_viewport;
92 gr_screen.gf_activate = gr_opengl_activate;
94 gr_screen.gf_release_texture = gr_opengl1_release_texture;
97 static void wxgl_init()
103 glShadeModel(GL_SMOOTH);
105 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
106 glHint(GL_FOG_HINT, GL_NICEST);
108 glEnable(GL_DEPTH_TEST);
111 glEnable(GL_TEXTURE_2D);
113 glDepthRange(0.0, 1.0);
115 glPixelStorei(GL_PACK_ALIGNMENT, 1);
116 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
120 wxgl_init_func_pointers();
121 opengl1_tcache_init();
133 void gr_wxgl_set_viewport(int width, int height)
137 GL_viewport_w = width;
138 GL_viewport_h = height;
139 GL_viewport_scale_w = 1.0f;
140 GL_viewport_scale_h = 1.0f;
142 glViewport(GL_viewport_x, GL_viewport_y, GL_viewport_w, GL_viewport_h);
144 glMatrixMode(GL_PROJECTION);
146 glOrtho(0, GL_viewport_w, GL_viewport_h, 0, 0.0, 1.0);
147 glMatrixMode(GL_MODELVIEW);
149 glScalef(GL_viewport_scale_w, GL_viewport_scale_h, 1.0f);
151 // update gr_screen, which will deal with view scaling too
152 gr_screen.max_w = width;
153 gr_screen.max_h = height;
156 void gr_wxgl_cleanup()
168 mprintf(( "Setting up OpenGL for wxWidgets...\n" ));
172 const char *gl_version = (const char*)glGetString(GL_VERSION);
173 int v_major = 0, v_minor = 0;
175 sscanf(gl_version, "%d.%d", &v_major, &v_minor);
177 GL_version = (v_major * 10) + v_minor;
179 // version check, require 1.2+ for sake of simplicity
180 if (GL_version < 12) {
181 Error(LOCATION, "Minimum OpenGL version is 1.2!");
184 mprintf((" Vendor : %s\n", glGetString(GL_VENDOR)));
185 mprintf((" Renderer : %s\n", glGetString(GL_RENDERER)));
186 mprintf((" Version : %s\n", gl_version));
188 // initial viewport setup
189 opengl_init_viewport();
191 // set up generic variables before further init() calls
192 opengl_set_variables();
200 gr_screen.bits_per_pixel = 16;
201 gr_screen.bytes_per_pixel = 2;
207 Gr_red.mask = 0x7C00;
212 Gr_green.mask = 0x3E0;
221 Gr_alpha.scale = 255;
222 Gr_alpha.mask = 0x8000;
224 // DDOI - set these so no one else does!
225 // texture values, always 1555 - 16-bit
226 Gr_t_red.mask = 0x7C00;
230 Gr_t_green.mask = 0x3E0;
231 Gr_t_green.shift = 5;
232 Gr_t_green.scale = 8;
234 Gr_t_blue.mask = 0x1F;
238 Gr_t_alpha.mask = 0x8000;
239 Gr_t_alpha.scale = 255;
240 Gr_t_alpha.shift = 15;
242 // alpha-texture values
243 Gr_ta_red.mask = 0x0f00;
245 Gr_ta_red.scale = 16;
247 Gr_ta_green.mask = 0x00f0;
248 Gr_ta_green.shift = 4;
249 Gr_ta_green.scale = 16;
251 Gr_ta_blue.mask = 0x000f;
252 Gr_ta_blue.shift = 0;
253 Gr_ta_blue.scale = 16;
255 Gr_ta_alpha.mask = 0xf000;
256 Gr_ta_alpha.shift = 12;
257 Gr_ta_alpha.scale = 16;
260 Gr_current_red = &Gr_red;
261 Gr_current_blue = &Gr_blue;
262 Gr_current_green = &Gr_green;
263 Gr_current_alpha = &Gr_alpha;