]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/grwxgl.cpp
disable emterpreter for now (too many issues)
[taylor/freespace2.git] / src / graphics / grwxgl.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 #ifdef LEGACY_GL
10
11 #include "SDL_opengl.h"
12
13 #include "pstypes.h"
14 #include "2d.h"
15 #include "grwxgl.h"
16 #include "gropengl.h"
17 #include "gropenglinternal.h"
18 #include "grgl1.h"
19 #include "grinternal.h"
20 #include "mouse.h"
21
22
23 extern bool OGL_inited;
24 extern int GL_one_inited;
25
26 extern void opengl_set_variables();
27 extern void opengl_init_viewport();
28
29
30 static void wxgl_init_func_pointers()
31 {
32         gr_screen.gf_flip = gr_wxgl_flip;
33         gr_screen.gf_set_clip = gr_opengl1_set_clip;
34         gr_screen.gf_reset_clip = gr_opengl_reset_clip;
35
36         gr_screen.gf_clear = gr_opengl_clear;
37
38         gr_screen.gf_aabitmap = gr_opengl1_aabitmap;
39         gr_screen.gf_aabitmap_ex = gr_opengl1_aabitmap_ex;
40
41         gr_screen.gf_rect = gr_opengl1_rect;
42         gr_screen.gf_shade = gr_opengl1_shade;
43         gr_screen.gf_string = gr_opengl1_string;
44         gr_screen.gf_circle = gr_opengl1_circle;
45
46         gr_screen.gf_line = gr_opengl1_line;
47         gr_screen.gf_aaline = gr_opengl1_aaline;
48         gr_screen.gf_pixel = gr_opengl1_pixel;
49         gr_screen.gf_scaler = gr_opengl1_scaler;
50         gr_screen.gf_tmapper = gr_opengl1_tmapper;
51
52         gr_screen.gf_gradient = gr_opengl1_gradient;
53
54         gr_screen.gf_print_screen = gr_opengl1_print_screen;
55
56         gr_screen.gf_fade_in = gr_opengl1_fade_in;
57         gr_screen.gf_fade_out = gr_opengl1_fade_out;
58         gr_screen.gf_flash = gr_opengl1_flash;
59
60         gr_screen.gf_zbuffer_clear = gr_opengl1_zbuffer_clear;
61
62         gr_screen.gf_save_screen = gr_opengl1_save_screen;
63         gr_screen.gf_restore_screen = gr_opengl1_restore_screen;
64         gr_screen.gf_free_screen = gr_opengl1_free_screen;
65
66         gr_screen.gf_dump_frame_start = gr_opengl1_dump_frame_start;
67         gr_screen.gf_dump_frame_stop = gr_opengl1_dump_frame_stop;
68         gr_screen.gf_dump_frame = gr_opengl1_dump_frame;
69
70         gr_screen.gf_stream_start = gr_opengl1_stream_start;
71         gr_screen.gf_stream_frame = gr_opengl1_stream_frame;
72         gr_screen.gf_stream_stop = gr_opengl1_stream_stop;
73
74         gr_screen.gf_set_gamma = gr_opengl1_set_gamma;
75
76         gr_screen.gf_lock = gr_opengl_lock;
77         gr_screen.gf_unlock = gr_opengl_unlock;
78
79         gr_screen.gf_fog_set = gr_opengl1_fog_set;
80
81         gr_screen.gf_get_region = gr_opengl1_get_region;
82
83         gr_screen.gf_set_cull = gr_opengl_set_cull;
84
85         gr_screen.gf_cross_fade = gr_opengl1_cross_fade;
86
87         gr_screen.gf_preload_init = gr_opengl1_preload_init;
88         gr_screen.gf_preload = gr_opengl1_preload;
89
90         gr_screen.gf_zbias = gr_opengl_zbias;
91
92         gr_screen.gf_set_viewport = gr_wxgl_set_viewport;
93
94         gr_screen.gf_activate = gr_opengl_activate;
95
96         gr_screen.gf_release_texture = gr_opengl1_release_texture;
97 }
98
99 static void wxgl_init()
100 {
101         if (GL_one_inited) {
102                 return;
103         }
104
105         glShadeModel(GL_SMOOTH);
106         glEnable(GL_DITHER);
107         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
108         glHint(GL_FOG_HINT, GL_NICEST);
109
110         glEnable(GL_DEPTH_TEST);
111         glEnable(GL_BLEND);
112
113         glEnable(GL_TEXTURE_2D);
114
115         glDepthRange(0.0, 1.0);
116
117         glPixelStorei(GL_PACK_ALIGNMENT, 1);
118         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
119
120         glFlush();
121
122         wxgl_init_func_pointers();
123         opengl1_tcache_init();
124
125         gr_opengl_clear();
126         gr_opengl_set_cull(1);
127
128         GL_one_inited = 1;
129
130 }
131
132 void gr_wxgl_flip()
133 {
134 #ifndef NDEBUG
135         GLenum error = glGetError();
136
137         if (error != GL_NO_ERROR) {
138                 mprintf(("!!DEBUG!! OpenGL Error: %d\n", error));
139         }
140 #endif
141 }
142
143 void gr_wxgl_set_viewport(int width, int height)
144 {
145         GL_viewport_x = 0;
146         GL_viewport_y = 0;
147         GL_viewport_w = width;
148         GL_viewport_h = height;
149         GL_viewport_scale_w = 1.0f;
150         GL_viewport_scale_h = 1.0f;
151
152         glViewport(GL_viewport_x, GL_viewport_y, GL_viewport_w, GL_viewport_h);
153
154         glMatrixMode(GL_PROJECTION);
155         glLoadIdentity();
156         glOrtho(0, GL_viewport_w, GL_viewport_h, 0, 0.0, 1.0);
157         glMatrixMode(GL_MODELVIEW);
158         glLoadIdentity();
159         glScalef(GL_viewport_scale_w, GL_viewport_scale_h, 1.0f);
160
161         // update gr_screen, which will deal with view scaling too
162         gr_screen.max_w = width;
163         gr_screen.max_h = height;
164 }
165
166 void gr_wxgl_cleanup()
167 {
168         opengl1_tcache_cleanup();
169
170         opengl_free_render_buffer();
171
172         OGL_inited = false;
173         GL_one_inited = 0;
174 }
175
176 void gr_wxgl_init()
177 {
178         if ( OGL_inited )       {
179                 gr_opengl_cleanup();
180                 OGL_inited = false;
181         }
182
183         mprintf(( "Setting up OpenGL for wxWidgets...\n" ));
184
185         OGL_inited = true;
186
187         const char *gl_version = (const char*)glGetString(GL_VERSION);
188         int v_major = 0, v_minor = 0;
189
190         sscanf(gl_version, "%d.%d", &v_major, &v_minor);
191
192         int GL_version = (v_major * 10) + v_minor;
193
194         // version check, require 1.2+ for sake of simplicity
195         if (GL_version < 12) {
196                 Error(LOCATION, "Minimum OpenGL version is 1.2!");
197         }
198
199         mprintf(("  Vendor   : %s\n", glGetString(GL_VENDOR)));
200         mprintf(("  Renderer : %s\n", glGetString(GL_RENDERER)));
201         mprintf(("  Version  : %s\n", gl_version));
202
203         // initial viewport setup
204         opengl_init_viewport();
205
206         // set up generic variables before further init() calls
207         opengl_set_variables();
208
209         // main GL init
210         wxgl_init();
211
212         mprintf(("\n"));
213
214
215         gr_screen.bits_per_pixel = 16;
216         gr_screen.bytes_per_pixel = 2;
217
218         // screen values
219         Gr_red.bits = 5;
220         Gr_red.shift = 11;
221         Gr_red.scale = 8;
222         Gr_red.mask = 0x7C01;
223
224         Gr_green.bits = 5;
225         Gr_green.shift = 6;
226         Gr_green.scale = 8;
227         Gr_green.mask = 0x3E1;
228
229         Gr_blue.bits = 5;
230         Gr_blue.shift = 1;
231         Gr_blue.scale = 8;
232         Gr_blue.mask = 0x20;
233
234         Gr_alpha.bits = 1;
235         Gr_alpha.shift = 0;
236         Gr_alpha.scale = 255;
237         Gr_alpha.mask = 0x1;
238
239         // DDOI - set these so no one else does!
240         // texture values, always 1555 - 16-bit
241         Gr_t_red.mask = 0x7C01;
242         Gr_t_red.shift = 11;
243         Gr_t_red.scale = 8;
244
245         Gr_t_green.mask = 0x3E1;
246         Gr_t_green.shift = 6;
247         Gr_t_green.scale = 8;
248
249         Gr_t_blue.mask = 0x20;
250         Gr_t_blue.shift = 1;
251         Gr_t_blue.scale = 8;
252
253         Gr_t_alpha.mask = 0x1;
254         Gr_t_alpha.shift = 0;
255         Gr_t_alpha.scale = 255;
256
257         // alpha-texture values
258         Gr_ta_red.mask = 0x0f00;
259         Gr_ta_red.shift = 8;
260         Gr_ta_red.scale = 16;
261
262         Gr_ta_green.mask = 0x00f0;
263         Gr_ta_green.shift = 4;
264         Gr_ta_green.scale = 16;
265
266         Gr_ta_blue.mask = 0x000f;
267         Gr_ta_blue.shift = 0;
268         Gr_ta_blue.scale = 16;
269
270         Gr_ta_alpha.mask = 0xf000;
271         Gr_ta_alpha.shift = 12;
272         Gr_ta_alpha.scale = 16;
273
274         // default to screen
275         Gr_current_red = &Gr_red;
276         Gr_current_blue = &Gr_blue;
277         Gr_current_green = &Gr_green;
278         Gr_current_alpha = &Gr_alpha;
279
280
281         Mouse_hidden++;
282         gr_reset_clip();
283         gr_clear();
284         gr_flip();
285         gr_clear();
286 }
287
288 #else
289
290 void gr_wxgl_init()
291 {
292 }
293
294 void gr_wxgl_cleanup()
295 {
296 }
297
298 void gr_wxgl_flip()
299 {
300 }
301
302 void gr_wxgl_set_viewport(int width, int height)
303 {
304 }
305
306 #endif