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