]> git.xonotic.org Git - xonotic/darkplaces.git/blob - vid_sdl.c
added support for SDL_Window API but it is disabled by default until SDL
[xonotic/darkplaces.git] / vid_sdl.c
1 /*
2 Copyright (C) 2003  T. Joseph Carter
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19 #undef WIN32_LEAN_AND_MEAN  //hush a warning, SDL.h redefines this
20 #include <SDL.h>
21 #include <SDL_syswm.h>
22 #include <stdio.h>
23
24 #include "quakedef.h"
25 #include "image.h"
26 #include "dpsoftrast.h"
27
28 #ifndef __IPHONEOS__
29 #ifdef MACOSX
30 #include <Carbon/Carbon.h>
31 #include <IOKit/hidsystem/IOHIDLib.h>
32 #include <IOKit/hidsystem/IOHIDParameter.h>
33 #include <IOKit/hidsystem/event_status_driver.h>
34 static cvar_t apple_mouse_noaccel = {CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"};
35 static qboolean vid_usingnoaccel;
36 static double originalMouseSpeed = -1.0;
37 io_connect_t IN_GetIOHandle(void)
38 {
39         io_connect_t iohandle = MACH_PORT_NULL;
40         kern_return_t status;
41         io_service_t iohidsystem = MACH_PORT_NULL;
42         mach_port_t masterport;
43
44         status = IOMasterPort(MACH_PORT_NULL, &masterport);
45         if(status != KERN_SUCCESS)
46                 return 0;
47
48         iohidsystem = IORegistryEntryFromPath(masterport, kIOServicePlane ":/IOResources/IOHIDSystem");
49         if(!iohidsystem)
50                 return 0;
51
52         status = IOServiceOpen(iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle);
53         IOObjectRelease(iohidsystem);
54
55         return iohandle;
56 }
57 #endif
58 #endif
59
60 #ifdef WIN32
61 #define SDL_R_RESTART
62 #endif
63
64 // Tell startup code that we have a client
65 int cl_available = true;
66
67 qboolean vid_supportrefreshrate = false;
68
69 cvar_t vid_soft = {CVAR_SAVE, "vid_soft", "0", "enables use of the DarkPlaces Software Rasterizer rather than OpenGL or Direct3D"};
70 cvar_t vid_soft_threads = {CVAR_SAVE, "vid_soft_threads", "2", "the number of threads the DarkPlaces Software Rasterizer should use"}; 
71 cvar_t vid_soft_interlace = {CVAR_SAVE, "vid_soft_interlace", "1", "whether the DarkPlaces Software Rasterizer shoud interlace the screen bands occupied by each thread"};
72 cvar_t joy_detected = {CVAR_READONLY, "joy_detected", "0", "number of joysticks detected by engine"};
73 cvar_t joy_enable = {CVAR_SAVE, "joy_enable", "0", "enables joystick support"};
74 cvar_t joy_index = {0, "joy_index", "0", "selects which joystick to use if you have multiple"};
75 cvar_t joy_axisforward = {0, "joy_axisforward", "1", "which joystick axis to query for forward/backward movement"};
76 cvar_t joy_axisside = {0, "joy_axisside", "0", "which joystick axis to query for right/left movement"};
77 cvar_t joy_axisup = {0, "joy_axisup", "-1", "which joystick axis to query for up/down movement"};
78 cvar_t joy_axispitch = {0, "joy_axispitch", "3", "which joystick axis to query for looking up/down"};
79 cvar_t joy_axisyaw = {0, "joy_axisyaw", "2", "which joystick axis to query for looking right/left"};
80 cvar_t joy_axisroll = {0, "joy_axisroll", "-1", "which joystick axis to query for tilting head right/left"};
81 cvar_t joy_deadzoneforward = {0, "joy_deadzoneforward", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
82 cvar_t joy_deadzoneside = {0, "joy_deadzoneside", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
83 cvar_t joy_deadzoneup = {0, "joy_deadzoneup", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
84 cvar_t joy_deadzonepitch = {0, "joy_deadzonepitch", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
85 cvar_t joy_deadzoneyaw = {0, "joy_deadzoneyaw", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
86 cvar_t joy_deadzoneroll = {0, "joy_deadzoneroll", "0", "deadzone tolerance, suggested values are in the range 0 to 0.01"};
87 cvar_t joy_sensitivityforward = {0, "joy_sensitivityforward", "-1", "movement multiplier"};
88 cvar_t joy_sensitivityside = {0, "joy_sensitivityside", "1", "movement multiplier"};
89 cvar_t joy_sensitivityup = {0, "joy_sensitivityup", "1", "movement multiplier"};
90 cvar_t joy_sensitivitypitch = {0, "joy_sensitivitypitch", "1", "movement multiplier"};
91 cvar_t joy_sensitivityyaw = {0, "joy_sensitivityyaw", "-1", "movement multiplier"};
92 cvar_t joy_sensitivityroll = {0, "joy_sensitivityroll", "1", "movement multiplier"};
93 cvar_t joy_axiskeyevents = {CVAR_SAVE, "joy_axiskeyevents", "0", "generate uparrow/leftarrow etc. keyevents for joystick axes, use if your joystick driver is not generating them"};
94
95 #ifdef __IPHONEOS__
96 # define SETVIDEOMODE 0
97 #else
98 # if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
99 #  define SETVIDEOMODE 1
100 # else
101 // LordHavoc: SDL 1.3's SDL_CreateWindow API is not finished enough to use yet, but you can set this to 0 if you want to try it...
102 #  ifndef SETVIDEOMODE
103 #   define SETVIDEOMODE 1
104 #  endif
105 # endif
106 #endif
107
108 static qboolean vid_usingmouse = false;
109 static qboolean vid_usinghidecursor = false;
110 static qboolean vid_hasfocus = false;
111 static qboolean vid_isfullscreen;
112 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
113 #else
114 static qboolean vid_usingvsync = false;
115 #endif
116 static int vid_numjoysticks = 0;
117 #define MAX_JOYSTICKS 8
118 static SDL_Joystick *vid_joysticks[MAX_JOYSTICKS];
119
120 static int win_half_width = 50;
121 static int win_half_height = 50;
122 static int video_bpp;
123
124 #if SETVIDEOMODE
125 static SDL_Surface *screen;
126 static int video_flags;
127 #else
128 static SDL_GLContext *context;
129 static SDL_Window *window;
130 static int window_flags;
131 #endif
132 static SDL_Surface *vid_softsurface;
133
134 // joystick axes state
135 #define MAX_JOYSTICK_AXES       16
136 typedef struct
137 {
138         float oldmove;
139         float move;
140         double keytime;
141 }joy_axiscache_t;
142 static joy_axiscache_t joy_axescache[MAX_JOYSTICK_AXES];
143
144 /////////////////////////
145 // Input handling
146 ////
147 //TODO: Add joystick support
148 //TODO: Add error checking
149
150 #ifndef SDLK_PERCENT
151 #define SDLK_PERCENT '%'
152 #define SDLK_PRINTSCREEN SDLK_PRINT
153 #define SDLK_SCROLLLOCK SDLK_SCROLLOCK
154 #define SDLK_NUMLOCKCLEAR SDLK_NUMLOCK
155 #define SDLK_KP_1 SDLK_KP1
156 #define SDLK_KP_2 SDLK_KP2
157 #define SDLK_KP_3 SDLK_KP3
158 #define SDLK_KP_4 SDLK_KP4
159 #define SDLK_KP_5 SDLK_KP5
160 #define SDLK_KP_6 SDLK_KP6
161 #define SDLK_KP_7 SDLK_KP7
162 #define SDLK_KP_8 SDLK_KP8
163 #define SDLK_KP_9 SDLK_KP9
164 #define SDLK_KP_0 SDLK_KP0
165 #endif
166
167 static int MapKey( unsigned int sdlkey )
168 {
169         switch(sdlkey)
170         {
171         default: return 0;
172 //      case SDLK_UNKNOWN:            return K_UNKNOWN;
173         case SDLK_RETURN:             return K_ENTER;
174         case SDLK_ESCAPE:             return K_ESCAPE;
175         case SDLK_BACKSPACE:          return K_BACKSPACE;
176         case SDLK_TAB:                return K_TAB;
177         case SDLK_SPACE:              return K_SPACE;
178         case SDLK_EXCLAIM:            return '!';
179         case SDLK_QUOTEDBL:           return '"';
180         case SDLK_HASH:               return '#';
181         case SDLK_PERCENT:            return '%';
182         case SDLK_DOLLAR:             return '$';
183         case SDLK_AMPERSAND:          return '&';
184         case SDLK_QUOTE:              return '\'';
185         case SDLK_LEFTPAREN:          return '(';
186         case SDLK_RIGHTPAREN:         return ')';
187         case SDLK_ASTERISK:           return '*';
188         case SDLK_PLUS:               return '+';
189         case SDLK_COMMA:              return ',';
190         case SDLK_MINUS:              return '-';
191         case SDLK_PERIOD:             return '.';
192         case SDLK_SLASH:              return '/';
193         case SDLK_0:                  return '0';
194         case SDLK_1:                  return '1';
195         case SDLK_2:                  return '2';
196         case SDLK_3:                  return '3';
197         case SDLK_4:                  return '4';
198         case SDLK_5:                  return '5';
199         case SDLK_6:                  return '6';
200         case SDLK_7:                  return '7';
201         case SDLK_8:                  return '8';
202         case SDLK_9:                  return '9';
203         case SDLK_COLON:              return ':';
204         case SDLK_SEMICOLON:          return ';';
205         case SDLK_LESS:               return '<';
206         case SDLK_EQUALS:             return '=';
207         case SDLK_GREATER:            return '>';
208         case SDLK_QUESTION:           return '?';
209         case SDLK_AT:                 return '@';
210         case SDLK_LEFTBRACKET:        return '[';
211         case SDLK_BACKSLASH:          return '\\';
212         case SDLK_RIGHTBRACKET:       return ']';
213         case SDLK_CARET:              return '^';
214         case SDLK_UNDERSCORE:         return '_';
215         case SDLK_BACKQUOTE:          return '`';
216         case SDLK_a:                  return 'a';
217         case SDLK_b:                  return 'b';
218         case SDLK_c:                  return 'c';
219         case SDLK_d:                  return 'd';
220         case SDLK_e:                  return 'e';
221         case SDLK_f:                  return 'f';
222         case SDLK_g:                  return 'g';
223         case SDLK_h:                  return 'h';
224         case SDLK_i:                  return 'i';
225         case SDLK_j:                  return 'j';
226         case SDLK_k:                  return 'k';
227         case SDLK_l:                  return 'l';
228         case SDLK_m:                  return 'm';
229         case SDLK_n:                  return 'n';
230         case SDLK_o:                  return 'o';
231         case SDLK_p:                  return 'p';
232         case SDLK_q:                  return 'q';
233         case SDLK_r:                  return 'r';
234         case SDLK_s:                  return 's';
235         case SDLK_t:                  return 't';
236         case SDLK_u:                  return 'u';
237         case SDLK_v:                  return 'v';
238         case SDLK_w:                  return 'w';
239         case SDLK_x:                  return 'x';
240         case SDLK_y:                  return 'y';
241         case SDLK_z:                  return 'z';
242         case SDLK_CAPSLOCK:           return K_CAPSLOCK;
243         case SDLK_F1:                 return K_F1;
244         case SDLK_F2:                 return K_F2;
245         case SDLK_F3:                 return K_F3;
246         case SDLK_F4:                 return K_F4;
247         case SDLK_F5:                 return K_F5;
248         case SDLK_F6:                 return K_F6;
249         case SDLK_F7:                 return K_F7;
250         case SDLK_F8:                 return K_F8;
251         case SDLK_F9:                 return K_F9;
252         case SDLK_F10:                return K_F10;
253         case SDLK_F11:                return K_F11;
254         case SDLK_F12:                return K_F12;
255         case SDLK_PRINTSCREEN:        return K_PRINTSCREEN;
256         case SDLK_SCROLLLOCK:         return K_SCROLLOCK;
257         case SDLK_PAUSE:              return K_PAUSE;
258         case SDLK_INSERT:             return K_INS;
259         case SDLK_HOME:               return K_HOME;
260         case SDLK_PAGEUP:             return K_PGUP;
261         case SDLK_DELETE:             return K_DEL;
262         case SDLK_END:                return K_END;
263         case SDLK_PAGEDOWN:           return K_PGDN;
264         case SDLK_RIGHT:              return K_RIGHTARROW;
265         case SDLK_LEFT:               return K_LEFTARROW;
266         case SDLK_DOWN:               return K_DOWNARROW;
267         case SDLK_UP:                 return K_UPARROW;
268         case SDLK_NUMLOCKCLEAR:       return K_NUMLOCK;
269         case SDLK_KP_DIVIDE:          return K_KP_DIVIDE;
270         case SDLK_KP_MULTIPLY:        return K_KP_MULTIPLY;
271         case SDLK_KP_MINUS:           return K_KP_MINUS;
272         case SDLK_KP_PLUS:            return K_KP_PLUS;
273         case SDLK_KP_ENTER:           return K_KP_ENTER;
274         case SDLK_KP_1:               return K_KP_1;
275         case SDLK_KP_2:               return K_KP_2;
276         case SDLK_KP_3:               return K_KP_3;
277         case SDLK_KP_4:               return K_KP_4;
278         case SDLK_KP_5:               return K_KP_5;
279         case SDLK_KP_6:               return K_KP_6;
280         case SDLK_KP_7:               return K_KP_7;
281         case SDLK_KP_8:               return K_KP_8;
282         case SDLK_KP_9:               return K_KP_9;
283         case SDLK_KP_0:               return K_KP_0;
284         case SDLK_KP_PERIOD:          return K_KP_PERIOD;
285 //      case SDLK_APPLICATION:        return K_APPLICATION;
286 //      case SDLK_POWER:              return K_POWER;
287         case SDLK_KP_EQUALS:          return K_KP_EQUALS;
288 //      case SDLK_F13:                return K_F13;
289 //      case SDLK_F14:                return K_F14;
290 //      case SDLK_F15:                return K_F15;
291 //      case SDLK_F16:                return K_F16;
292 //      case SDLK_F17:                return K_F17;
293 //      case SDLK_F18:                return K_F18;
294 //      case SDLK_F19:                return K_F19;
295 //      case SDLK_F20:                return K_F20;
296 //      case SDLK_F21:                return K_F21;
297 //      case SDLK_F22:                return K_F22;
298 //      case SDLK_F23:                return K_F23;
299 //      case SDLK_F24:                return K_F24;
300 //      case SDLK_EXECUTE:            return K_EXECUTE;
301 //      case SDLK_HELP:               return K_HELP;
302 //      case SDLK_MENU:               return K_MENU;
303 //      case SDLK_SELECT:             return K_SELECT;
304 //      case SDLK_STOP:               return K_STOP;
305 //      case SDLK_AGAIN:              return K_AGAIN;
306 //      case SDLK_UNDO:               return K_UNDO;
307 //      case SDLK_CUT:                return K_CUT;
308 //      case SDLK_COPY:               return K_COPY;
309 //      case SDLK_PASTE:              return K_PASTE;
310 //      case SDLK_FIND:               return K_FIND;
311 //      case SDLK_MUTE:               return K_MUTE;
312 //      case SDLK_VOLUMEUP:           return K_VOLUMEUP;
313 //      case SDLK_VOLUMEDOWN:         return K_VOLUMEDOWN;
314 //      case SDLK_KP_COMMA:           return K_KP_COMMA;
315 //      case SDLK_KP_EQUALSAS400:     return K_KP_EQUALSAS400;
316 //      case SDLK_ALTERASE:           return K_ALTERASE;
317 //      case SDLK_SYSREQ:             return K_SYSREQ;
318 //      case SDLK_CANCEL:             return K_CANCEL;
319 //      case SDLK_CLEAR:              return K_CLEAR;
320 //      case SDLK_PRIOR:              return K_PRIOR;
321 //      case SDLK_RETURN2:            return K_RETURN2;
322 //      case SDLK_SEPARATOR:          return K_SEPARATOR;
323 //      case SDLK_OUT:                return K_OUT;
324 //      case SDLK_OPER:               return K_OPER;
325 //      case SDLK_CLEARAGAIN:         return K_CLEARAGAIN;
326 //      case SDLK_CRSEL:              return K_CRSEL;
327 //      case SDLK_EXSEL:              return K_EXSEL;
328 //      case SDLK_KP_00:              return K_KP_00;
329 //      case SDLK_KP_000:             return K_KP_000;
330 //      case SDLK_THOUSANDSSEPARATOR: return K_THOUSANDSSEPARATOR;
331 //      case SDLK_DECIMALSEPARATOR:   return K_DECIMALSEPARATOR;
332 //      case SDLK_CURRENCYUNIT:       return K_CURRENCYUNIT;
333 //      case SDLK_CURRENCYSUBUNIT:    return K_CURRENCYSUBUNIT;
334 //      case SDLK_KP_LEFTPAREN:       return K_KP_LEFTPAREN;
335 //      case SDLK_KP_RIGHTPAREN:      return K_KP_RIGHTPAREN;
336 //      case SDLK_KP_LEFTBRACE:       return K_KP_LEFTBRACE;
337 //      case SDLK_KP_RIGHTBRACE:      return K_KP_RIGHTBRACE;
338 //      case SDLK_KP_TAB:             return K_KP_TAB;
339 //      case SDLK_KP_BACKSPACE:       return K_KP_BACKSPACE;
340 //      case SDLK_KP_A:               return K_KP_A;
341 //      case SDLK_KP_B:               return K_KP_B;
342 //      case SDLK_KP_C:               return K_KP_C;
343 //      case SDLK_KP_D:               return K_KP_D;
344 //      case SDLK_KP_E:               return K_KP_E;
345 //      case SDLK_KP_F:               return K_KP_F;
346 //      case SDLK_KP_XOR:             return K_KP_XOR;
347 //      case SDLK_KP_POWER:           return K_KP_POWER;
348 //      case SDLK_KP_PERCENT:         return K_KP_PERCENT;
349 //      case SDLK_KP_LESS:            return K_KP_LESS;
350 //      case SDLK_KP_GREATER:         return K_KP_GREATER;
351 //      case SDLK_KP_AMPERSAND:       return K_KP_AMPERSAND;
352 //      case SDLK_KP_DBLAMPERSAND:    return K_KP_DBLAMPERSAND;
353 //      case SDLK_KP_VERTICALBAR:     return K_KP_VERTICALBAR;
354 //      case SDLK_KP_DBLVERTICALBAR:  return K_KP_DBLVERTICALBAR;
355 //      case SDLK_KP_COLON:           return K_KP_COLON;
356 //      case SDLK_KP_HASH:            return K_KP_HASH;
357 //      case SDLK_KP_SPACE:           return K_KP_SPACE;
358 //      case SDLK_KP_AT:              return K_KP_AT;
359 //      case SDLK_KP_EXCLAM:          return K_KP_EXCLAM;
360 //      case SDLK_KP_MEMSTORE:        return K_KP_MEMSTORE;
361 //      case SDLK_KP_MEMRECALL:       return K_KP_MEMRECALL;
362 //      case SDLK_KP_MEMCLEAR:        return K_KP_MEMCLEAR;
363 //      case SDLK_KP_MEMADD:          return K_KP_MEMADD;
364 //      case SDLK_KP_MEMSUBTRACT:     return K_KP_MEMSUBTRACT;
365 //      case SDLK_KP_MEMMULTIPLY:     return K_KP_MEMMULTIPLY;
366 //      case SDLK_KP_MEMDIVIDE:       return K_KP_MEMDIVIDE;
367 //      case SDLK_KP_PLUSMINUS:       return K_KP_PLUSMINUS;
368 //      case SDLK_KP_CLEAR:           return K_KP_CLEAR;
369 //      case SDLK_KP_CLEARENTRY:      return K_KP_CLEARENTRY;
370 //      case SDLK_KP_BINARY:          return K_KP_BINARY;
371 //      case SDLK_KP_OCTAL:           return K_KP_OCTAL;
372 //      case SDLK_KP_DECIMAL:         return K_KP_DECIMAL;
373 //      case SDLK_KP_HEXADECIMAL:     return K_KP_HEXADECIMAL;
374         case SDLK_LCTRL:              return K_CTRL;
375         case SDLK_LSHIFT:             return K_SHIFT;
376         case SDLK_LALT:               return K_ALT;
377 //      case SDLK_LGUI:               return K_LGUI;
378         case SDLK_RCTRL:              return K_CTRL;
379         case SDLK_RSHIFT:             return K_SHIFT;
380         case SDLK_RALT:               return K_ALT;
381 //      case SDLK_RGUI:               return K_RGUI;
382 //      case SDLK_MODE:               return K_MODE;
383 //      case SDLK_AUDIONEXT:          return K_AUDIONEXT;
384 //      case SDLK_AUDIOPREV:          return K_AUDIOPREV;
385 //      case SDLK_AUDIOSTOP:          return K_AUDIOSTOP;
386 //      case SDLK_AUDIOPLAY:          return K_AUDIOPLAY;
387 //      case SDLK_AUDIOMUTE:          return K_AUDIOMUTE;
388 //      case SDLK_MEDIASELECT:        return K_MEDIASELECT;
389 //      case SDLK_WWW:                return K_WWW;
390 //      case SDLK_MAIL:               return K_MAIL;
391 //      case SDLK_CALCULATOR:         return K_CALCULATOR;
392 //      case SDLK_COMPUTER:           return K_COMPUTER;
393 //      case SDLK_AC_SEARCH:          return K_AC_SEARCH;
394 //      case SDLK_AC_HOME:            return K_AC_HOME;
395 //      case SDLK_AC_BACK:            return K_AC_BACK;
396 //      case SDLK_AC_FORWARD:         return K_AC_FORWARD;
397 //      case SDLK_AC_STOP:            return K_AC_STOP;
398 //      case SDLK_AC_REFRESH:         return K_AC_REFRESH;
399 //      case SDLK_AC_BOOKMARKS:       return K_AC_BOOKMARKS;
400 //      case SDLK_BRIGHTNESSDOWN:     return K_BRIGHTNESSDOWN;
401 //      case SDLK_BRIGHTNESSUP:       return K_BRIGHTNESSUP;
402 //      case SDLK_DISPLAYSWITCH:      return K_DISPLAYSWITCH;
403 //      case SDLK_KBDILLUMTOGGLE:     return K_KBDILLUMTOGGLE;
404 //      case SDLK_KBDILLUMDOWN:       return K_KBDILLUMDOWN;
405 //      case SDLK_KBDILLUMUP:         return K_KBDILLUMUP;
406 //      case SDLK_EJECT:              return K_EJECT;
407 //      case SDLK_SLEEP:              return K_SLEEP;
408         }
409 }
410
411 void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
412 {
413 #ifdef __IPHONEOS__
414         if (key_consoleactive || key_dest != key_game)
415         {
416                 if (!SDL_iPhoneKeyboardIsShown(window))
417                         SDL_iPhoneKeyboardShow(window);
418         }
419         else
420         {
421                 if (SDL_iPhoneKeyboardIsShown(window))
422                         SDL_iPhoneKeyboardHide(window);
423         }
424 #else
425 #ifdef MACOSX
426         if(relative)
427                 if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer))
428                         VID_SetMouse(false, false, false); // ungrab first!
429 #endif
430         if (vid_usingmouse != relative)
431         {
432                 vid_usingmouse = relative;
433                 cl_ignoremousemoves = 2;
434 #if SETVIDEOMODE
435                 SDL_WM_GrabInput( relative ? SDL_GRAB_ON : SDL_GRAB_OFF );
436 #else
437                 SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
438 #endif
439 #ifdef MACOSX
440                 if(relative)
441                 {
442                         // Save the status of mouse acceleration
443                         originalMouseSpeed = -1.0; // in case of error
444                         if(apple_mouse_noaccel.integer)
445                         {
446                                 io_connect_t mouseDev = IN_GetIOHandle();
447                                 if(mouseDev != 0)
448                                 {
449                                         if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
450                                         {
451                                                 Con_DPrintf("previous mouse acceleration: %f\n", originalMouseSpeed);
452                                                 if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
453                                                 {
454                                                         Con_Print("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
455                                                         Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
456                                                 }
457                                         }
458                                         else
459                                         {
460                                                 Con_Print("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n");
461                                                 Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
462                                         }
463                                         IOServiceClose(mouseDev);
464                                 }
465                                 else
466                                 {
467                                         Con_Print("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n");
468                                         Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
469                                 }
470                         }
471
472                         vid_usingnoaccel = !!apple_mouse_noaccel.integer;
473                 }
474                 else
475                 {
476                         if(originalMouseSpeed != -1.0)
477                         {
478                                 io_connect_t mouseDev = IN_GetIOHandle();
479                                 if(mouseDev != 0)
480                                 {
481                                         Con_DPrintf("restoring mouse acceleration to: %f\n", originalMouseSpeed);
482                                         if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
483                                                 Con_Print("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
484                                         IOServiceClose(mouseDev);
485                                 }
486                                 else
487                                         Con_Print("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
488                         }
489                 }
490 #endif
491         }
492         if (vid_usinghidecursor != hidecursor)
493         {
494                 vid_usinghidecursor = hidecursor;
495                 SDL_ShowCursor( hidecursor ? SDL_DISABLE : SDL_ENABLE);
496         }
497 #endif
498 }
499
500 static double IN_JoystickGetAxis(SDL_Joystick *joy, int axis, double sensitivity, double deadzone)
501 {
502         double value;
503         if (axis < 0 || axis >= SDL_JoystickNumAxes(joy))
504                 return 0; // no such axis on this joystick
505         value = SDL_JoystickGetAxis(joy, axis) * (1.0 / 32767.0);
506         value = bound(-1, value, 1);
507         if (fabs(value) < deadzone)
508                 return 0; // within deadzone around center
509         return value * sensitivity;
510 }
511
512 /////////////////////
513 // Joystick axis keyevents
514 // a sort of hack emulating Arrow keys for joystick axises
515 // as some drives dont send such keyevents for them
516 // additionally we should block drivers that do send arrow keyevents to prevent double events
517 ////
518
519 static void IN_JoystickKeyeventForAxis(SDL_Joystick *joy, int axis, int key_pos, int key_neg)
520 {
521         double joytime;
522
523         if (axis < 0 || axis >= SDL_JoystickNumAxes(joy))
524                 return; // no such axis on this joystick
525
526         joytime = Sys_DoubleTime();
527         // no key event, continuous keydown event
528         if (joy_axescache[axis].move == joy_axescache[axis].oldmove)
529         {
530                 if (joy_axescache[axis].move != 0 && joytime > joy_axescache[axis].keytime)
531                 {
532                         //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time);
533                         Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1);
534                         joy_axescache[axis].keytime = joytime + 0.5 / 20;
535                 }
536                 return;
537         }
538         // generate key up event
539         if (joy_axescache[axis].oldmove)
540         {
541                 //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg), 1, cl.time);
542                 Key_Event((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg, 0, 0);
543         }
544         // generate key down event
545         if (joy_axescache[axis].move)
546         {
547                 //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time);
548                 Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1);
549                 joy_axescache[axis].keytime = joytime + 0.5;
550         }
551 }
552
553 static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode)
554 {
555         if (!joy_axiskeyevents.integer)
556                 return false;
557
558         // block keyevent if it's going to be provided by joystick keyevent system
559         if (vid_numjoysticks && joy_enable.integer && joy_index.integer >= 0 && joy_index.integer < vid_numjoysticks)
560         {
561                 SDL_Joystick *joy = vid_joysticks[joy_index.integer];
562
563                 if (keycode == K_UPARROW || keycode == K_DOWNARROW)
564                         if (IN_JoystickGetAxis(joy, joy_axisforward.integer, 1, 0.01) || joy_axescache[joy_axisforward.integer].move || joy_axescache[joy_axisforward.integer].oldmove)
565                                 return true;
566                 if (keycode == K_RIGHTARROW || keycode == K_LEFTARROW)
567                         if (IN_JoystickGetAxis(joy, joy_axisside.integer, 1, 0.01) || joy_axescache[joy_axisside.integer].move || joy_axescache[joy_axisside.integer].oldmove)
568                                 return true;
569         }
570
571         return false;
572 }
573
574 /////////////////////
575 // Movement handling
576 ////
577
578 void IN_Move( void )
579 {
580         int j;
581         static int old_x = 0, old_y = 0;
582         static int stuck = 0;
583         int x, y, numaxes, numballs;
584
585         if (vid_usingmouse)
586         {
587                 if (vid_touchscreen.integer)
588                 {
589                         // touchscreen controls...
590                         if (SDL_GetRelativeMouseState(&x,&y))
591                         {
592                                 in_mouse_x = x;
593                                 in_mouse_y = y;
594                         }
595                         else
596                         {
597                                 in_mouse_x = 0;
598                                 in_mouse_y = 0;
599                         }
600                 }
601                 else if (vid_stick_mouse.integer)
602                 {
603                         // have the mouse stuck in the middle, example use: prevent expose effect of beryl during the game when not using
604                         // window grabbing. --blub
605
606                         // we need 2 frames to initialize the center position
607                         if(!stuck)
608                         {
609 #if SETVIDEOMODE
610                                 SDL_WarpMouse(win_half_width, win_half_height);
611 #else
612                                 SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
613 #endif
614                                 SDL_GetMouseState(&x, &y);
615                                 SDL_GetRelativeMouseState(&x, &y);
616                                 ++stuck;
617                         } else {
618                                 SDL_GetRelativeMouseState(&x, &y);
619                                 in_mouse_x = x + old_x;
620                                 in_mouse_y = y + old_y;
621                                 SDL_GetMouseState(&x, &y);
622                                 old_x = x - win_half_width;
623                                 old_y = y - win_half_height;
624 #if SETVIDEOMODE
625                                 SDL_WarpMouse(win_half_width, win_half_height);
626 #else
627                                 SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
628 #endif
629                         }
630                 } else {
631                         SDL_GetRelativeMouseState( &x, &y );
632                         in_mouse_x = x;
633                         in_mouse_y = y;
634                 }
635         }
636
637         SDL_GetMouseState(&x, &y);
638         in_windowmouse_x = x;
639         in_windowmouse_y = y;
640
641         if (vid_numjoysticks && joy_enable.integer && joy_index.integer >= 0 && joy_index.integer < vid_numjoysticks)
642         {
643                 SDL_Joystick *joy = vid_joysticks[joy_index.integer];
644
645                 // balls convert to mousemove
646                 numballs = SDL_JoystickNumBalls(joy);
647                 for (j = 0;j < numballs;j++)
648                 {
649                         SDL_JoystickGetBall(joy, j, &x, &y);
650                         in_mouse_x += x;
651                         in_mouse_y += y;
652                 }
653
654                 // axes
655                 cl.cmd.forwardmove += IN_JoystickGetAxis(joy, joy_axisforward.integer, joy_sensitivityforward.value, joy_deadzoneforward.value) * cl_forwardspeed.value;
656                 cl.cmd.sidemove    += IN_JoystickGetAxis(joy, joy_axisside.integer, joy_sensitivityside.value, joy_deadzoneside.value) * cl_sidespeed.value;
657                 cl.cmd.upmove      += IN_JoystickGetAxis(joy, joy_axisup.integer, joy_sensitivityup.value, joy_deadzoneup.value) * cl_upspeed.value;
658                 cl.viewangles[0]   += IN_JoystickGetAxis(joy, joy_axispitch.integer, joy_sensitivitypitch.value, joy_deadzonepitch.value) * cl.realframetime * cl_pitchspeed.value;
659                 cl.viewangles[1]   += IN_JoystickGetAxis(joy, joy_axisyaw.integer, joy_sensitivityyaw.value, joy_deadzoneyaw.value) * cl.realframetime * cl_yawspeed.value;
660                 //cl.viewangles[2]   += IN_JoystickGetAxis(joy, joy_axisroll.integer, joy_sensitivityroll.value, joy_deadzoneroll.value) * cl.realframetime * cl_rollspeed.value;
661         
662                 // cache state of axes to emulate button events for them
663                 numaxes = min(MAX_JOYSTICK_AXES, SDL_JoystickNumAxes(joy));
664                 for (j = 0; j < numaxes; j++)
665                 {
666                         joy_axescache[j].oldmove = joy_axescache[j].move;
667                         joy_axescache[j].move = IN_JoystickGetAxis(joy, j, 1, 0.01);
668                 }
669
670                 // run keyevents
671                 if (joy_axiskeyevents.integer)
672                 {
673                         IN_JoystickKeyeventForAxis(joy, joy_axisforward.integer, K_DOWNARROW, K_UPARROW);
674                         IN_JoystickKeyeventForAxis(joy, joy_axisside.integer, K_RIGHTARROW, K_LEFTARROW);
675                 }
676         }
677 }
678
679 /////////////////////
680 // Message Handling
681 ////
682
683 #ifdef SDL_R_RESTART
684 static qboolean sdl_needs_restart;
685 static void sdl_start(void)
686 {
687 }
688 static void sdl_shutdown(void)
689 {
690         sdl_needs_restart = false;
691 }
692 static void sdl_newmap(void)
693 {
694 }
695 #endif
696
697 static keynum_t buttonremap[18] =
698 {
699         K_MOUSE1,
700         K_MOUSE3,
701         K_MOUSE2,
702         K_MWHEELUP,
703         K_MWHEELDOWN,
704         K_MOUSE4,
705         K_MOUSE5,
706         K_MOUSE6,
707         K_MOUSE7,
708         K_MOUSE8,
709         K_MOUSE9,
710         K_MOUSE10,
711         K_MOUSE11,
712         K_MOUSE12,
713         K_MOUSE13,
714         K_MOUSE14,
715         K_MOUSE15,
716         K_MOUSE16,
717 };
718
719 #if SETVIDEOMODE
720 // SDL 1.2
721 void Sys_SendKeyEvents( void )
722 {
723         static qboolean sound_active = true;
724         int keycode;
725         SDL_Event event;
726
727         while( SDL_PollEvent( &event ) )
728                 switch( event.type ) {
729                         case SDL_QUIT:
730                                 Sys_Quit(0);
731                                 break;
732                         case SDL_KEYDOWN:
733                         case SDL_KEYUP:
734                                 keycode = MapKey(event.key.keysym.sym);
735                                 if (!IN_JoystickBlockDoubledKeyEvents(keycode))
736                                         Key_Event(keycode, event.key.keysym.unicode, (event.key.state == SDL_PRESSED));
737                                 break;
738                         case SDL_ACTIVEEVENT:
739                                 if( event.active.state & SDL_APPACTIVE )
740                                 {
741                                         if( event.active.gain )
742                                                 vid_hidden = false;
743                                         else
744                                                 vid_hidden = true;
745                                 }
746                                 break;
747                         case SDL_MOUSEBUTTONDOWN:
748                         case SDL_MOUSEBUTTONUP:
749                                 if (event.button.button <= 18)
750                                         Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
751                                 break;
752                         case SDL_JOYBUTTONDOWN:
753                                 if (!joy_enable.integer)
754                                         break; // ignore down events if joystick has been disabled
755                         case SDL_JOYBUTTONUP:
756                                 if (event.jbutton.button < 48)
757                                         Key_Event( event.jbutton.button + (event.jbutton.button < 16 ? K_JOY1 : K_AUX1 - 16), 0, (event.jbutton.state == SDL_PRESSED) );
758                                 break;
759                         case SDL_VIDEORESIZE:
760                                 if(vid_resizable.integer < 2)
761                                 {
762                                         vid.width = event.resize.w;
763                                         vid.height = event.resize.h;
764                                         screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
765                                         if (vid_softsurface)
766                                         {
767                                                 SDL_FreeSurface(vid_softsurface);
768                                                 vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
769                                                 vid.softpixels = (unsigned int *)vid_softsurface->pixels;
770                                                 SDL_SetAlpha(vid_softsurface, 0, 255);
771                                                 if (vid.softdepthpixels)
772                                                         free(vid.softdepthpixels);
773                                                 vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
774                                         }
775 #ifdef SDL_R_RESTART
776                                         // better not call R_Modules_Restart from here directly, as this may wreak havoc...
777                                         // so, let's better queue it for next frame
778                                         if(!sdl_needs_restart)
779                                         {
780                                                 Cbuf_AddText("\nr_restart\n");
781                                                 sdl_needs_restart = true;
782                                         }
783 #endif
784                                 }
785                                 break;
786                         case SDL_TEXTEDITING:
787                                 // unused when SETVIDEOMODE API is used
788                                 break;
789                         case SDL_TEXTINPUT:
790                                 // this occurs with SETVIDEOMODE but we are not using it
791                                 break;
792                         case SDL_MOUSEMOTION:
793                                 break;
794                         default:
795                                 Con_DPrintf("Received unrecognized SDL_Event type 0x%x\n", event.type);
796                                 break;
797                 }
798
799         // enable/disable sound on focus gain/loss
800         if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
801         {
802                 if (!sound_active)
803                 {
804                         S_UnblockSound ();
805                         sound_active = true;
806                 }
807         }
808         else
809         {
810                 if (sound_active)
811                 {
812                         S_BlockSound ();
813                         sound_active = false;
814                 }
815         }
816 }
817
818 #else
819
820 // SDL 1.3
821 void Sys_SendKeyEvents( void )
822 {
823         static qboolean sound_active = true;
824         int keycode;
825         SDL_Event event;
826
827         while( SDL_PollEvent( &event ) )
828                 switch( event.type ) {
829                         case SDL_QUIT:
830                                 Sys_Quit(0);
831                                 break;
832                         case SDL_KEYDOWN:
833                         case SDL_KEYUP:
834                                 keycode = MapKey(event.key.keysym.sym);
835                                 if (!IN_JoystickBlockDoubledKeyEvents(keycode))
836                                         Key_Event(keycode, 0, (event.key.state == SDL_PRESSED));
837                                 break;
838                         case SDL_MOUSEBUTTONDOWN:
839                         case SDL_MOUSEBUTTONUP:
840                                 if (event.button.button <= 18)
841                                         Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
842                                 break;
843                         case SDL_JOYBUTTONDOWN:
844                                 if (!joy_enable.integer)
845                                         break; // ignore down events if joystick has been disabled
846                         case SDL_JOYBUTTONUP:
847                                 if (event.jbutton.button < 48)
848                                         Key_Event( event.jbutton.button + (event.jbutton.button < 16 ? K_JOY1 : K_AUX1 - 16), 0, (event.jbutton.state == SDL_PRESSED) );
849                                 break;
850                         case SDL_WINDOWEVENT:
851                                 //if (event.window.windowID == window) // how to compare?
852                                 {
853                                         switch(event.window.event)
854                                         {
855                                         case SDL_WINDOWEVENT_SHOWN:
856                                                 vid_hidden = false;
857                                                 break;
858                                         case  SDL_WINDOWEVENT_HIDDEN:
859                                                 vid_hidden = true;
860                                                 break;
861                                         case SDL_WINDOWEVENT_EXPOSED:
862                                                 break;
863                                         case SDL_WINDOWEVENT_MOVED:
864                                                 break;
865                                         case SDL_WINDOWEVENT_RESIZED:
866                                                 if(vid_resizable.integer < 2)
867                                                 {
868                                                         vid.width = event.window.data1;
869                                                         vid.height = event.window.data2;
870                                                         if (vid_softsurface)
871                                                         {
872                                                                 SDL_FreeSurface(vid_softsurface);
873                                                                 vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
874                                                                 vid.softpixels = (unsigned int *)vid_softsurface->pixels;
875                                                                 SDL_SetAlpha(vid_softsurface, 0, 255);
876                                                                 if (vid.softdepthpixels)
877                                                                         free(vid.softdepthpixels);
878                                                                 vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
879                                                         }
880 #ifdef SDL_R_RESTART
881                                                         // better not call R_Modules_Restart from here directly, as this may wreak havoc...
882                                                         // so, let's better queue it for next frame
883                                                         if(!sdl_needs_restart)
884                                                         {
885                                                                 Cbuf_AddText("\nr_restart\n");
886                                                                 sdl_needs_restart = true;
887                                                         }
888 #endif
889                                                 }
890                                                 break;
891                                         case SDL_WINDOWEVENT_MINIMIZED:
892                                                 break;
893                                         case SDL_WINDOWEVENT_MAXIMIZED:
894                                                 break;
895                                         case SDL_WINDOWEVENT_RESTORED:
896                                                 break;
897                                         case SDL_WINDOWEVENT_ENTER:
898                                                 break;
899                                         case SDL_WINDOWEVENT_LEAVE:
900                                                 break;
901                                         case SDL_WINDOWEVENT_FOCUS_GAINED:
902                                                 vid_hasfocus = true;
903                                                 break;
904                                         case SDL_WINDOWEVENT_FOCUS_LOST:
905                                                 vid_hasfocus = false;
906                                                 break;
907                                         case SDL_WINDOWEVENT_CLOSE:
908                                                 Sys_Quit(0);
909                                                 break;
910                                         }
911                                 }
912                                 break;
913                         case SDL_TEXTEDITING:
914                                 // FIXME!  this is where composition gets supported
915                                 break;
916                         case SDL_TEXTINPUT:
917                                 // we have some characters to parse
918                                 {
919                                         int unicode;
920                                         int i;
921                                         int j;
922                                         unicode = 0;
923                                         for (i = 0;event.text.text[i];)
924                                         {
925                                                 unicode = event.text.text[i++];
926                                                 if (unicode & 0x80)
927                                                 {
928                                                         // UTF-8 character
929                                                         // strip high bits (we could count these to validate character length but we don't)
930                                                         for (j = 0x80;unicode & j;j >>= 1)
931                                                                 unicode ^= j;
932                                                         for (;(event.text.text[i] & 0xC0) == 0x80;i++)
933                                                                 unicode = (unicode << 6) | (event.text.text[i] & 0x3F);
934                                                         // low characters are invalid and could be bad, so replace them
935                                                         if (unicode < 0x80)
936                                                                 unicode = '?'; // we could use 0xFFFD instead, the unicode substitute character
937                                                 }
938                                                 //Con_DPrintf("SDL_TEXTINPUT: K_TEXT %i \n", unicode);
939                                                 Key_Event(K_TEXT, unicode, true);
940                                                 Key_Event(K_TEXT, unicode, false);
941                                         }
942                                 }
943                                 break;
944                         case SDL_MOUSEMOTION:
945                                 break;
946                         default:
947                                 Con_DPrintf("Received unrecognized SDL_Event type 0x%x\n", event.type);
948                                 break;
949                 }
950
951         // enable/disable sound on focus gain/loss
952         if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
953         {
954                 if (!sound_active)
955                 {
956                         S_UnblockSound ();
957                         sound_active = true;
958                 }
959         }
960         else
961         {
962                 if (sound_active)
963                 {
964                         S_BlockSound ();
965                         sound_active = false;
966                 }
967         }
968 }
969 #endif
970
971 /////////////////
972 // Video system
973 ////
974
975 #ifdef __IPHONEOS__
976 //#include <SDL_opengles.h>
977 #include <OpenGLES/ES2/gl.h>
978
979 GLboolean wrapglIsBuffer(GLuint buffer) {return glIsBuffer(buffer);}
980 GLboolean wrapglIsEnabled(GLenum cap) {return glIsEnabled(cap);}
981 GLboolean wrapglIsFramebuffer(GLuint framebuffer) {return glIsFramebuffer(framebuffer);}
982 //GLboolean wrapglIsQuery(GLuint qid) {return glIsQuery(qid);}
983 GLboolean wrapglIsRenderbuffer(GLuint renderbuffer) {return glIsRenderbuffer(renderbuffer);}
984 //GLboolean wrapglUnmapBuffer(GLenum target) {return glUnmapBuffer(target);}
985 GLenum wrapglCheckFramebufferStatus(GLenum target) {return glCheckFramebufferStatus(target);}
986 GLenum wrapglGetError(void) {return glGetError();}
987 GLuint wrapglCreateProgram(void) {return glCreateProgram();}
988 GLuint wrapglCreateShader(GLenum shaderType) {return glCreateShader(shaderType);}
989 //GLuint wrapglGetHandle(GLenum pname) {return glGetHandle(pname);}
990 GLint wrapglGetAttribLocation(GLuint programObj, const GLchar *name) {return glGetAttribLocation(programObj, name);}
991 GLint wrapglGetUniformLocation(GLuint programObj, const GLchar *name) {return glGetUniformLocation(programObj, name);}
992 //GLvoid* wrapglMapBuffer(GLenum target, GLenum access) {return glMapBuffer(target, access);}
993 const GLubyte* wrapglGetString(GLenum name) {return glGetString(name);}
994 void wrapglActiveStencilFace(GLenum e) {Con_Printf("glActiveStencilFace(e)\n");}
995 void wrapglActiveTexture(GLenum e) {glActiveTexture(e);}
996 void wrapglAlphaFunc(GLenum func, GLclampf ref) {Con_Printf("glAlphaFunc(func, ref)\n");}
997 void wrapglArrayElement(GLint i) {Con_Printf("glArrayElement(i)\n");}
998 void wrapglAttachShader(GLuint containerObj, GLuint obj) {glAttachShader(containerObj, obj);}
999 void wrapglBegin(GLenum mode) {Con_Printf("glBegin(mode)\n");}
1000 //void wrapglBeginQuery(GLenum target, GLuint qid) {glBeginQuery(target, qid);}
1001 void wrapglBindAttribLocation(GLuint programObj, GLuint index, const GLchar *name) {glBindAttribLocation(programObj, index, name);}
1002 void wrapglBindBuffer(GLenum target, GLuint buffer) {glBindBuffer(target, buffer);}
1003 void wrapglBindFramebuffer(GLenum target, GLuint framebuffer) {glBindFramebuffer(target, framebuffer);}
1004 void wrapglBindRenderbuffer(GLenum target, GLuint renderbuffer) {glBindRenderbuffer(target, renderbuffer);}
1005 void wrapglBindTexture(GLenum target, GLuint texture) {glBindTexture(target, texture);}
1006 void wrapglBlendEquation(GLenum e) {glBlendEquation(e);}
1007 void wrapglBlendFunc(GLenum sfactor, GLenum dfactor) {glBlendFunc(sfactor, dfactor);}
1008 void wrapglBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) {glBufferData(target, size, data, usage);}
1009 void wrapglBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) {glBufferSubData(target, offset, size, data);}
1010 void wrapglClear(GLbitfield mask) {glClear(mask);}
1011 void wrapglClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {glClearColor(red, green, blue, alpha);}
1012 void wrapglClearDepth(GLclampd depth) {glClearDepthf((float)depth);}
1013 void wrapglClearStencil(GLint s) {glClearStencil(s);}
1014 void wrapglClientActiveTexture(GLenum target) {Con_Printf("glClientActiveTexture(target)\n");}
1015 void wrapglColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {Con_Printf("glColor4f(red, green, blue, alpha)\n");}
1016 void wrapglColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {Con_Printf("glColor4ub(red, green, blue, alpha)\n");}
1017 void wrapglColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {glColorMask(red, green, blue, alpha);}
1018 void wrapglColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) {Con_Printf("glColorPointer(size, type, stride, ptr)\n");}
1019 void wrapglCompileShader(GLuint shaderObj) {glCompileShader(shaderObj);}
1020 void wrapglCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border,  GLsizei imageSize, const void *data) {glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);}
1021 void wrapglCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data) {Con_Printf("glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data)\n");}
1022 void wrapglCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) {glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);}
1023 void wrapglCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data) {Con_Printf("glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data)\n");}
1024 void wrapglCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);}
1025 void wrapglCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);}
1026 void wrapglCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) {Con_Printf("glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height)\n");}
1027 void wrapglCullFace(GLenum mode) {glCullFace(mode);}
1028 void wrapglDeleteBuffers(GLsizei n, const GLuint *buffers) {glDeleteBuffers(n, buffers);}
1029 void wrapglDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) {glDeleteFramebuffers(n, framebuffers);}
1030 void wrapglDeleteShader(GLuint obj) {glDeleteShader(obj);}
1031 void wrapglDeleteProgram(GLuint obj) {glDeleteProgram(obj);}
1032 //void wrapglDeleteQueries(GLsizei n, const GLuint *ids) {glDeleteQueries(n, ids);}
1033 void wrapglDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) {glDeleteRenderbuffers(n, renderbuffers);}
1034 void wrapglDeleteTextures(GLsizei n, const GLuint *textures) {glDeleteTextures(n, textures);}
1035 void wrapglDepthFunc(GLenum func) {glDepthFunc(func);}
1036 void wrapglDepthMask(GLboolean flag) {glDepthMask(flag);}
1037 void wrapglDepthRange(GLclampd near_val, GLclampd far_val) {glDepthRangef((float)near_val, (float)far_val);}
1038 void wrapglDetachShader(GLuint containerObj, GLuint attachedObj) {glDetachShader(containerObj, attachedObj);}
1039 void wrapglDisable(GLenum cap) {glDisable(cap);}
1040 void wrapglDisableClientState(GLenum cap) {Con_Printf("glDisableClientState(cap)\n");}
1041 void wrapglDisableVertexAttribArray(GLuint index) {glDisableVertexAttribArray(index);}
1042 void wrapglDrawArrays(GLenum mode, GLint first, GLsizei count) {glDrawArrays(mode, first, count);}
1043 void wrapglDrawBuffer(GLenum mode) {Con_Printf("glDrawBuffer(mode)\n");}
1044 void wrapglDrawBuffers(GLsizei n, const GLenum *bufs) {Con_Printf("glDrawBuffers(n, bufs)\n");}
1045 void wrapglDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) {glDrawElements(mode, count, type, indices);}
1046 //void wrapglDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) {glDrawRangeElements(mode, start, end, count, type, indices);}
1047 //void wrapglDrawRangeElementsEXT(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) {glDrawRangeElements(mode, start, end, count, type, indices);}
1048 void wrapglEnable(GLenum cap) {glEnable(cap);}
1049 void wrapglEnableClientState(GLenum cap) {Con_Printf("glEnableClientState(cap)\n");}
1050 void wrapglEnableVertexAttribArray(GLuint index) {glEnableVertexAttribArray(index);}
1051 void wrapglEnd(void) {Con_Printf("glEnd()\n");}
1052 //void wrapglEndQuery(GLenum target) {glEndQuery(target);}
1053 void wrapglFinish(void) {glFinish();}
1054 void wrapglFlush(void) {glFlush();}
1055 void wrapglFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);}
1056 void wrapglFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {glFramebufferTexture2D(target, attachment, textarget, texture, level);}
1057 void wrapglFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) {Con_Printf("glFramebufferTexture3D()\n");}
1058 void wrapglGenBuffers(GLsizei n, GLuint *buffers) {glGenBuffers(n, buffers);}
1059 void wrapglGenFramebuffers(GLsizei n, GLuint *framebuffers) {glGenFramebuffers(n, framebuffers);}
1060 //void wrapglGenQueries(GLsizei n, GLuint *ids) {glGenQueries(n, ids);}
1061 void wrapglGenRenderbuffers(GLsizei n, GLuint *renderbuffers) {glGenRenderbuffers(n, renderbuffers);}
1062 void wrapglGenTextures(GLsizei n, GLuint *textures) {glGenTextures(n, textures);}
1063 void wrapglGenerateMipmap(GLenum target) {glGenerateMipmap(target);}
1064 void wrapglGetActiveAttrib(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {glGetActiveAttrib(programObj, index, maxLength, length, size, type, name);}
1065 void wrapglGetActiveUniform(GLuint programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {glGetActiveUniform(programObj, index, maxLength, length, size, type, name);}
1066 void wrapglGetAttachedShaders(GLuint containerObj, GLsizei maxCount, GLsizei *count, GLuint *obj) {glGetAttachedShaders(containerObj, maxCount, count, obj);}
1067 void wrapglGetBooleanv(GLenum pname, GLboolean *params) {glGetBooleanv(pname, params);}
1068 void wrapglGetCompressedTexImage(GLenum target, GLint lod, void *img) {Con_Printf("glGetCompressedTexImage(target, lod, img)\n");}
1069 void wrapglGetDoublev(GLenum pname, GLdouble *params) {Con_Printf("glGetDoublev(pname, params)\n");}
1070 void wrapglGetFloatv(GLenum pname, GLfloat *params) {glGetFloatv(pname, params);}
1071 void wrapglGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params) {glGetFramebufferAttachmentParameteriv(target, attachment, pname, params);}
1072 void wrapglGetShaderInfoLog(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog) {glGetShaderInfoLog(obj, maxLength, length, infoLog);}
1073 void wrapglGetProgramInfoLog(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *infoLog) {glGetProgramInfoLog(obj, maxLength, length, infoLog);}
1074 void wrapglGetIntegerv(GLenum pname, GLint *params) {glGetIntegerv(pname, params);}
1075 void wrapglGetShaderiv(GLuint obj, GLenum pname, GLint *params) {glGetShaderiv(obj, pname, params);}
1076 void wrapglGetProgramiv(GLuint obj, GLenum pname, GLint *params) {glGetProgramiv(obj, pname, params);}
1077 //void wrapglGetQueryObjectiv(GLuint qid, GLenum pname, GLint *params) {glGetQueryObjectiv(qid, pname, params);}
1078 //void wrapglGetQueryObjectuiv(GLuint qid, GLenum pname, GLuint *params) {glGetQueryObjectuiv(qid, pname, params);}
1079 //void wrapglGetQueryiv(GLenum target, GLenum pname, GLint *params) {glGetQueryiv(target, pname, params);}
1080 void wrapglGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) {glGetRenderbufferParameteriv(target, pname, params);}
1081 void wrapglGetShaderSource(GLuint obj, GLsizei maxLength, GLsizei *length, GLchar *source) {glGetShaderSource(obj, maxLength, length, source);}
1082 void wrapglGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels) {Con_Printf("glGetTexImage(target, level, format, type, pixels)\n");}
1083 void wrapglGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params) {Con_Printf("glGetTexLevelParameterfv(target, level, pname, params)\n");}
1084 void wrapglGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params) {Con_Printf("glGetTexLevelParameteriv(target, level, pname, params)\n");}
1085 void wrapglGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) {glGetTexParameterfv(target, pname, params);}
1086 void wrapglGetTexParameteriv(GLenum target, GLenum pname, GLint *params) {glGetTexParameteriv(target, pname, params);}
1087 void wrapglGetUniformfv(GLuint programObj, GLint location, GLfloat *params) {glGetUniformfv(programObj, location, params);}
1088 void wrapglGetUniformiv(GLuint programObj, GLint location, GLint *params) {glGetUniformiv(programObj, location, params);}
1089 void wrapglHint(GLenum target, GLenum mode) {glHint(target, mode);}
1090 void wrapglLineWidth(GLfloat width) {glLineWidth(width);}
1091 void wrapglLinkProgram(GLuint programObj) {glLinkProgram(programObj);}
1092 void wrapglLoadIdentity(void) {Con_Printf("glLoadIdentity()\n");}
1093 void wrapglLoadMatrixf(const GLfloat *m) {Con_Printf("glLoadMatrixf(m)\n");}
1094 void wrapglMatrixMode(GLenum mode) {Con_Printf("glMatrixMode(mode)\n");}
1095 void wrapglMultiTexCoord1f(GLenum target, GLfloat s) {Con_Printf("glMultiTexCoord1f(target, s)\n");}
1096 void wrapglMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t) {Con_Printf("glMultiTexCoord2f(target, s, t)\n");}
1097 void wrapglMultiTexCoord3f(GLenum target, GLfloat s, GLfloat t, GLfloat r) {Con_Printf("glMultiTexCoord3f(target, s, t, r)\n");}
1098 void wrapglMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {Con_Printf("glMultiTexCoord4f(target, s, t, r, q)\n");}
1099 void wrapglNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr) {Con_Printf("glNormalPointer(type, stride, ptr)\n");}
1100 void wrapglPixelStorei(GLenum pname, GLint param) {glPixelStorei(pname, param);}
1101 void wrapglPointSize(GLfloat size) {Con_Printf("glPointSize(size)\n");}
1102 void wrapglPolygonMode(GLenum face, GLenum mode) {Con_Printf("glPolygonMode(face, mode)\n");}
1103 void wrapglPolygonOffset(GLfloat factor, GLfloat units) {glPolygonOffset(factor, units);}
1104 void wrapglPolygonStipple(const GLubyte *mask) {Con_Printf("glPolygonStipple(mask)\n");}
1105 void wrapglReadBuffer(GLenum mode) {Con_Printf("glReadBuffer(mode)\n");}
1106 void wrapglReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {glReadPixels(x, y, width, height, format, type, pixels);}
1107 void wrapglRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {glRenderbufferStorage(target, internalformat, width, height);}
1108 void wrapglScissor(GLint x, GLint y, GLsizei width, GLsizei height) {glScissor(x, y, width, height);}
1109 void wrapglShaderSource(GLuint shaderObj, GLsizei count, const GLchar **string, const GLint *length) {glShaderSource(shaderObj, count, string, length);}
1110 void wrapglStencilFunc(GLenum func, GLint ref, GLuint mask) {glStencilFunc(func, ref, mask);}
1111 void wrapglStencilFuncSeparate(GLenum func1, GLenum func2, GLint ref, GLuint mask) {Con_Printf("glStencilFuncSeparate(func1, func2, ref, mask)\n");}
1112 void wrapglStencilMask(GLuint mask) {glStencilMask(mask);}
1113 void wrapglStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {glStencilOp(fail, zfail, zpass);}
1114 void wrapglStencilOpSeparate(GLenum e1, GLenum e2, GLenum e3, GLenum e4) {Con_Printf("glStencilOpSeparate(e1, e2, e3, e4)\n");}
1115 void wrapglTexCoord1f(GLfloat s) {Con_Printf("glTexCoord1f(s)\n");}
1116 void wrapglTexCoord2f(GLfloat s, GLfloat t) {Con_Printf("glTexCoord2f(s, t)\n");}
1117 void wrapglTexCoord3f(GLfloat s, GLfloat t, GLfloat r) {Con_Printf("glTexCoord3f(s, t, r)\n");}
1118 void wrapglTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) {Con_Printf("glTexCoord4f(s, t, r, q)\n");}
1119 void wrapglTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) {Con_Printf("glTexCoordPointer(size, type, stride, ptr)\n");}
1120 void wrapglTexEnvf(GLenum target, GLenum pname, GLfloat param) {Con_Printf("glTexEnvf(target, pname, param)\n");}
1121 void wrapglTexEnvfv(GLenum target, GLenum pname, const GLfloat *params) {Con_Printf("glTexEnvfv(target, pname, params)\n");}
1122 void wrapglTexEnvi(GLenum target, GLenum pname, GLint param) {Con_Printf("glTexEnvi(target, pname, param)\n");}
1123 void wrapglTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels);}
1124 void wrapglTexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {Con_Printf("glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels)\n");}
1125 void wrapglTexParameterf(GLenum target, GLenum pname, GLfloat param) {glTexParameterf(target, pname, param);}
1126 void wrapglTexParameterfv(GLenum target, GLenum pname, GLfloat *params) {glTexParameterfv(target, pname, params);}
1127 void wrapglTexParameteri(GLenum target, GLenum pname, GLint param) {glTexParameteri(target, pname, param);}
1128 void wrapglTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) {glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);}
1129 void wrapglTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) {Con_Printf("glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels)\n");}
1130 void wrapglUniform1f(GLint location, GLfloat v0) {glUniform1f(location, v0);}
1131 void wrapglUniform1fv(GLint location, GLsizei count, const GLfloat *value) {glUniform1fv(location, count, value);}
1132 void wrapglUniform1i(GLint location, GLint v0) {glUniform1i(location, v0);}
1133 void wrapglUniform1iv(GLint location, GLsizei count, const GLint *value) {glUniform1iv(location, count, value);}
1134 void wrapglUniform2f(GLint location, GLfloat v0, GLfloat v1) {glUniform2f(location, v0, v1);}
1135 void wrapglUniform2fv(GLint location, GLsizei count, const GLfloat *value) {glUniform2fv(location, count, value);}
1136 void wrapglUniform2i(GLint location, GLint v0, GLint v1) {glUniform2i(location, v0, v1);}
1137 void wrapglUniform2iv(GLint location, GLsizei count, const GLint *value) {glUniform2iv(location, count, value);}
1138 void wrapglUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {glUniform3f(location, v0, v1, v2);}
1139 void wrapglUniform3fv(GLint location, GLsizei count, const GLfloat *value) {glUniform3fv(location, count, value);}
1140 void wrapglUniform3i(GLint location, GLint v0, GLint v1, GLint v2) {glUniform3i(location, v0, v1, v2);}
1141 void wrapglUniform3iv(GLint location, GLsizei count, const GLint *value) {glUniform3iv(location, count, value);}
1142 void wrapglUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {glUniform4f(location, v0, v1, v2, v3);}
1143 void wrapglUniform4fv(GLint location, GLsizei count, const GLfloat *value) {glUniform4fv(location, count, value);}
1144 void wrapglUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {glUniform4i(location, v0, v1, v2, v3);}
1145 void wrapglUniform4iv(GLint location, GLsizei count, const GLint *value) {glUniform4iv(location, count, value);}
1146 void wrapglUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {glUniformMatrix2fv(location, count, transpose, value);}
1147 void wrapglUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {glUniformMatrix3fv(location, count, transpose, value);}
1148 void wrapglUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {glUniformMatrix4fv(location, count, transpose, value);}
1149 void wrapglUseProgram(GLuint programObj) {glUseProgram(programObj);}
1150 void wrapglValidateProgram(GLuint programObj) {glValidateProgram(programObj);}
1151 void wrapglVertex2f(GLfloat x, GLfloat y) {Con_Printf("glVertex2f(x, y)\n");}
1152 void wrapglVertex3f(GLfloat x, GLfloat y, GLfloat z) {Con_Printf("glVertex3f(x, y, z)\n");}
1153 void wrapglVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {Con_Printf("glVertex4f(x, y, z, w)\n");}
1154 void wrapglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer) {glVertexAttribPointer(index, size, type, normalized, stride, pointer);}
1155 void wrapglVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) {Con_Printf("glVertexPointer(size, type, stride, ptr)\n");}
1156 void wrapglViewport(GLint x, GLint y, GLsizei width, GLsizei height) {glViewport(x, y, width, height);}
1157 void wrapglVertexAttrib1f(GLuint index, GLfloat v0) {glVertexAttrib1f(index, v0);}
1158 //void wrapglVertexAttrib1s(GLuint index, GLshort v0) {glVertexAttrib1s(index, v0);}
1159 //void wrapglVertexAttrib1d(GLuint index, GLdouble v0) {glVertexAttrib1d(index, v0);}
1160 void wrapglVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) {glVertexAttrib2f(index, v0, v1);}
1161 //void wrapglVertexAttrib2s(GLuint index, GLshort v0, GLshort v1) {glVertexAttrib2s(index, v0, v1);}
1162 //void wrapglVertexAttrib2d(GLuint index, GLdouble v0, GLdouble v1) {glVertexAttrib2d(index, v0, v1);}
1163 void wrapglVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) {glVertexAttrib3f(index, v0, v1, v2);}
1164 //void wrapglVertexAttrib3s(GLuint index, GLshort v0, GLshort v1, GLshort v2) {glVertexAttrib3s(index, v0, v1, v2);}
1165 //void wrapglVertexAttrib3d(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2) {glVertexAttrib3d(index, v0, v1, v2);}
1166 void wrapglVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {glVertexAttrib4f(index, v0, v1, v2, v3);}
1167 //void wrapglVertexAttrib4s(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3) {glVertexAttrib4s(index, v0, v1, v2, v3);}
1168 //void wrapglVertexAttrib4d(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3) {glVertexAttrib4d(index, v0, v1, v2, v3);}
1169 //void wrapglVertexAttrib4Nub(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) {glVertexAttrib4Nub(index, x, y, z, w);}
1170 void wrapglVertexAttrib1fv(GLuint index, const GLfloat *v) {glVertexAttrib1fv(index, v);}
1171 //void wrapglVertexAttrib1sv(GLuint index, const GLshort *v) {glVertexAttrib1sv(index, v);}
1172 //void wrapglVertexAttrib1dv(GLuint index, const GLdouble *v) {glVertexAttrib1dv(index, v);}
1173 void wrapglVertexAttrib2fv(GLuint index, const GLfloat *v) {glVertexAttrib2fv(index, v);}
1174 //void wrapglVertexAttrib2sv(GLuint index, const GLshort *v) {glVertexAttrib2sv(index, v);}
1175 //void wrapglVertexAttrib2dv(GLuint index, const GLdouble *v) {glVertexAttrib2dv(index, v);}
1176 void wrapglVertexAttrib3fv(GLuint index, const GLfloat *v) {glVertexAttrib3fv(index, v);}
1177 //void wrapglVertexAttrib3sv(GLuint index, const GLshort *v) {glVertexAttrib3sv(index, v);}
1178 //void wrapglVertexAttrib3dv(GLuint index, const GLdouble *v) {glVertexAttrib3dv(index, v);}
1179 void wrapglVertexAttrib4fv(GLuint index, const GLfloat *v) {glVertexAttrib4fv(index, v);}
1180 //void wrapglVertexAttrib4sv(GLuint index, const GLshort *v) {glVertexAttrib4sv(index, v);}
1181 //void wrapglVertexAttrib4dv(GLuint index, const GLdouble *v) {glVertexAttrib4dv(index, v);}
1182 //void wrapglVertexAttrib4iv(GLuint index, const GLint *v) {glVertexAttrib4iv(index, v);}
1183 //void wrapglVertexAttrib4bv(GLuint index, const GLbyte *v) {glVertexAttrib4bv(index, v);}
1184 //void wrapglVertexAttrib4ubv(GLuint index, const GLubyte *v) {glVertexAttrib4ubv(index, v);}
1185 //void wrapglVertexAttrib4usv(GLuint index, const GLushort *v) {glVertexAttrib4usv(index, GLushort v);}
1186 //void wrapglVertexAttrib4uiv(GLuint index, const GLuint *v) {glVertexAttrib4uiv(index, v);}
1187 //void wrapglVertexAttrib4Nbv(GLuint index, const GLbyte *v) {glVertexAttrib4Nbv(index, v);}
1188 //void wrapglVertexAttrib4Nsv(GLuint index, const GLshort *v) {glVertexAttrib4Nsv(index, v);}
1189 //void wrapglVertexAttrib4Niv(GLuint index, const GLint *v) {glVertexAttrib4Niv(index, v);}
1190 //void wrapglVertexAttrib4Nubv(GLuint index, const GLubyte *v) {glVertexAttrib4Nubv(index, v);}
1191 //void wrapglVertexAttrib4Nusv(GLuint index, const GLushort *v) {glVertexAttrib4Nusv(index, GLushort v);}
1192 //void wrapglVertexAttrib4Nuiv(GLuint index, const GLuint *v) {glVertexAttrib4Nuiv(index, v);}
1193 //void wrapglGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) {glGetVertexAttribdv(index, pname, params);}
1194 void wrapglGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) {glGetVertexAttribfv(index, pname, params);}
1195 void wrapglGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) {glGetVertexAttribiv(index, pname, params);}
1196 void wrapglGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) {glGetVertexAttribPointerv(index, pname, pointer);}
1197
1198 void GLES_Init(void)
1199 {
1200         qglIsBufferARB = wrapglIsBuffer;
1201         qglIsEnabled = wrapglIsEnabled;
1202         qglIsFramebufferEXT = wrapglIsFramebuffer;
1203 //      qglIsQueryARB = wrapglIsQuery;
1204         qglIsRenderbufferEXT = wrapglIsRenderbuffer;
1205 //      qglUnmapBufferARB = wrapglUnmapBuffer;
1206         qglCheckFramebufferStatusEXT = wrapglCheckFramebufferStatus;
1207         qglGetError = wrapglGetError;
1208         qglCreateProgram = wrapglCreateProgram;
1209         qglCreateShader = wrapglCreateShader;
1210 //      qglGetHandleARB = wrapglGetHandle;
1211         qglGetAttribLocation = wrapglGetAttribLocation;
1212         qglGetUniformLocation = wrapglGetUniformLocation;
1213 //      qglMapBufferARB = wrapglMapBuffer;
1214         qglGetString = wrapglGetString;
1215 //      qglActiveStencilFaceEXT = wrapglActiveStencilFace;
1216         qglActiveTexture = wrapglActiveTexture;
1217         qglAlphaFunc = wrapglAlphaFunc;
1218         qglArrayElement = wrapglArrayElement;
1219         qglAttachShader = wrapglAttachShader;
1220         qglBegin = wrapglBegin;
1221 //      qglBeginQueryARB = wrapglBeginQuery;
1222         qglBindAttribLocation = wrapglBindAttribLocation;
1223         qglBindBufferARB = wrapglBindBuffer;
1224         qglBindFramebufferEXT = wrapglBindFramebuffer;
1225         qglBindRenderbufferEXT = wrapglBindRenderbuffer;
1226         qglBindTexture = wrapglBindTexture;
1227         qglBlendEquationEXT = wrapglBlendEquation;
1228         qglBlendFunc = wrapglBlendFunc;
1229         qglBufferDataARB = wrapglBufferData;
1230         qglBufferSubDataARB = wrapglBufferSubData;
1231         qglClear = wrapglClear;
1232         qglClearColor = wrapglClearColor;
1233         qglClearDepth = wrapglClearDepth;
1234         qglClearStencil = wrapglClearStencil;
1235         qglClientActiveTexture = wrapglClientActiveTexture;
1236         qglColor4f = wrapglColor4f;
1237         qglColor4ub = wrapglColor4ub;
1238         qglColorMask = wrapglColorMask;
1239         qglColorPointer = wrapglColorPointer;
1240         qglCompileShader = wrapglCompileShader;
1241         qglCompressedTexImage2DARB = wrapglCompressedTexImage2D;
1242         qglCompressedTexImage3DARB = wrapglCompressedTexImage3D;
1243         qglCompressedTexSubImage2DARB = wrapglCompressedTexSubImage2D;
1244         qglCompressedTexSubImage3DARB = wrapglCompressedTexSubImage3D;
1245         qglCopyTexImage2D = wrapglCopyTexImage2D;
1246         qglCopyTexSubImage2D = wrapglCopyTexSubImage2D;
1247         qglCopyTexSubImage3D = wrapglCopyTexSubImage3D;
1248         qglCullFace = wrapglCullFace;
1249         qglDeleteBuffersARB = wrapglDeleteBuffers;
1250         qglDeleteFramebuffersEXT = wrapglDeleteFramebuffers;
1251         qglDeleteProgram = wrapglDeleteProgram;
1252         qglDeleteShader = wrapglDeleteShader;
1253 //      qglDeleteQueriesARB = wrapglDeleteQueries;
1254         qglDeleteRenderbuffersEXT = wrapglDeleteRenderbuffers;
1255         qglDeleteTextures = wrapglDeleteTextures;
1256         qglDepthFunc = wrapglDepthFunc;
1257         qglDepthMask = wrapglDepthMask;
1258         qglDepthRange = wrapglDepthRange;
1259         qglDetachShader = wrapglDetachShader;
1260         qglDisable = wrapglDisable;
1261         qglDisableClientState = wrapglDisableClientState;
1262         qglDisableVertexAttribArray = wrapglDisableVertexAttribArray;
1263         qglDrawArrays = wrapglDrawArrays;
1264 //      qglDrawBuffer = wrapglDrawBuffer;
1265 //      qglDrawBuffersARB = wrapglDrawBuffers;
1266         qglDrawElements = wrapglDrawElements;
1267 //      qglDrawRangeElements = wrapglDrawRangeElements;
1268         qglEnable = wrapglEnable;
1269         qglEnableClientState = wrapglEnableClientState;
1270         qglEnableVertexAttribArray = wrapglEnableVertexAttribArray;
1271         qglEnd = wrapglEnd;
1272 //      qglEndQueryARB = wrapglEndQuery;
1273         qglFinish = wrapglFinish;
1274         qglFlush = wrapglFlush;
1275         qglFramebufferRenderbufferEXT = wrapglFramebufferRenderbuffer;
1276         qglFramebufferTexture2DEXT = wrapglFramebufferTexture2D;
1277         qglFramebufferTexture3DEXT = wrapglFramebufferTexture3D;
1278         qglGenBuffersARB = wrapglGenBuffers;
1279         qglGenFramebuffersEXT = wrapglGenFramebuffers;
1280 //      qglGenQueriesARB = wrapglGenQueries;
1281         qglGenRenderbuffersEXT = wrapglGenRenderbuffers;
1282         qglGenTextures = wrapglGenTextures;
1283         qglGenerateMipmapEXT = wrapglGenerateMipmap;
1284         qglGetActiveAttrib = wrapglGetActiveAttrib;
1285         qglGetActiveUniform = wrapglGetActiveUniform;
1286         qglGetAttachedShaders = wrapglGetAttachedShaders;
1287         qglGetBooleanv = wrapglGetBooleanv;
1288 //      qglGetCompressedTexImageARB = wrapglGetCompressedTexImage;
1289         qglGetDoublev = wrapglGetDoublev;
1290         qglGetFloatv = wrapglGetFloatv;
1291         qglGetFramebufferAttachmentParameterivEXT = wrapglGetFramebufferAttachmentParameteriv;
1292         qglGetProgramInfoLog = wrapglGetProgramInfoLog;
1293         qglGetShaderInfoLog = wrapglGetShaderInfoLog;
1294         qglGetIntegerv = wrapglGetIntegerv;
1295         qglGetShaderiv = wrapglGetShaderiv;
1296         qglGetProgramiv = wrapglGetProgramiv;
1297 //      qglGetQueryObjectivARB = wrapglGetQueryObjectiv;
1298 //      qglGetQueryObjectuivARB = wrapglGetQueryObjectuiv;
1299 //      qglGetQueryivARB = wrapglGetQueryiv;
1300         qglGetRenderbufferParameterivEXT = wrapglGetRenderbufferParameteriv;
1301         qglGetShaderSource = wrapglGetShaderSource;
1302         qglGetTexImage = wrapglGetTexImage;
1303         qglGetTexLevelParameterfv = wrapglGetTexLevelParameterfv;
1304         qglGetTexLevelParameteriv = wrapglGetTexLevelParameteriv;
1305         qglGetTexParameterfv = wrapglGetTexParameterfv;
1306         qglGetTexParameteriv = wrapglGetTexParameteriv;
1307         qglGetUniformfv = wrapglGetUniformfv;
1308         qglGetUniformiv = wrapglGetUniformiv;
1309         qglHint = wrapglHint;
1310         qglLineWidth = wrapglLineWidth;
1311         qglLinkProgram = wrapglLinkProgram;
1312         qglLoadIdentity = wrapglLoadIdentity;
1313         qglLoadMatrixf = wrapglLoadMatrixf;
1314         qglMatrixMode = wrapglMatrixMode;
1315         qglMultiTexCoord1f = wrapglMultiTexCoord1f;
1316         qglMultiTexCoord2f = wrapglMultiTexCoord2f;
1317         qglMultiTexCoord3f = wrapglMultiTexCoord3f;
1318         qglMultiTexCoord4f = wrapglMultiTexCoord4f;
1319         qglNormalPointer = wrapglNormalPointer;
1320         qglPixelStorei = wrapglPixelStorei;
1321         qglPointSize = wrapglPointSize;
1322         qglPolygonMode = wrapglPolygonMode;
1323         qglPolygonOffset = wrapglPolygonOffset;
1324 //      qglPolygonStipple = wrapglPolygonStipple;
1325         qglReadBuffer = wrapglReadBuffer;
1326         qglReadPixels = wrapglReadPixels;
1327         qglRenderbufferStorageEXT = wrapglRenderbufferStorage;
1328         qglScissor = wrapglScissor;
1329         qglShaderSource = wrapglShaderSource;
1330         qglStencilFunc = wrapglStencilFunc;
1331         qglStencilFuncSeparate = wrapglStencilFuncSeparate;
1332         qglStencilMask = wrapglStencilMask;
1333         qglStencilOp = wrapglStencilOp;
1334         qglStencilOpSeparate = wrapglStencilOpSeparate;
1335         qglTexCoord1f = wrapglTexCoord1f;
1336         qglTexCoord2f = wrapglTexCoord2f;
1337         qglTexCoord3f = wrapglTexCoord3f;
1338         qglTexCoord4f = wrapglTexCoord4f;
1339         qglTexCoordPointer = wrapglTexCoordPointer;
1340         qglTexEnvf = wrapglTexEnvf;
1341         qglTexEnvfv = wrapglTexEnvfv;
1342         qglTexEnvi = wrapglTexEnvi;
1343         qglTexImage2D = wrapglTexImage2D;
1344         qglTexImage3D = wrapglTexImage3D;
1345         qglTexParameterf = wrapglTexParameterf;
1346         qglTexParameterfv = wrapglTexParameterfv;
1347         qglTexParameteri = wrapglTexParameteri;
1348         qglTexSubImage2D = wrapglTexSubImage2D;
1349         qglTexSubImage3D = wrapglTexSubImage3D;
1350         qglUniform1f = wrapglUniform1f;
1351         qglUniform1fv = wrapglUniform1fv;
1352         qglUniform1i = wrapglUniform1i;
1353         qglUniform1iv = wrapglUniform1iv;
1354         qglUniform2f = wrapglUniform2f;
1355         qglUniform2fv = wrapglUniform2fv;
1356         qglUniform2i = wrapglUniform2i;
1357         qglUniform2iv = wrapglUniform2iv;
1358         qglUniform3f = wrapglUniform3f;
1359         qglUniform3fv = wrapglUniform3fv;
1360         qglUniform3i = wrapglUniform3i;
1361         qglUniform3iv = wrapglUniform3iv;
1362         qglUniform4f = wrapglUniform4f;
1363         qglUniform4fv = wrapglUniform4fv;
1364         qglUniform4i = wrapglUniform4i;
1365         qglUniform4iv = wrapglUniform4iv;
1366         qglUniformMatrix2fv = wrapglUniformMatrix2fv;
1367         qglUniformMatrix3fv = wrapglUniformMatrix3fv;
1368         qglUniformMatrix4fv = wrapglUniformMatrix4fv;
1369         qglUseProgram = wrapglUseProgram;
1370         qglValidateProgram = wrapglValidateProgram;
1371         qglVertex2f = wrapglVertex2f;
1372         qglVertex3f = wrapglVertex3f;
1373         qglVertex4f = wrapglVertex4f;
1374         qglVertexAttribPointer = wrapglVertexAttribPointer;
1375         qglVertexPointer = wrapglVertexPointer;
1376         qglViewport = wrapglViewport;
1377         qglVertexAttrib1f = wrapglVertexAttrib1f;
1378 //      qglVertexAttrib1s = wrapglVertexAttrib1s;
1379 //      qglVertexAttrib1d = wrapglVertexAttrib1d;
1380         qglVertexAttrib2f = wrapglVertexAttrib2f;
1381 //      qglVertexAttrib2s = wrapglVertexAttrib2s;
1382 //      qglVertexAttrib2d = wrapglVertexAttrib2d;
1383         qglVertexAttrib3f = wrapglVertexAttrib3f;
1384 //      qglVertexAttrib3s = wrapglVertexAttrib3s;
1385 //      qglVertexAttrib3d = wrapglVertexAttrib3d;
1386         qglVertexAttrib4f = wrapglVertexAttrib4f;
1387 //      qglVertexAttrib4s = wrapglVertexAttrib4s;
1388 //      qglVertexAttrib4d = wrapglVertexAttrib4d;
1389 //      qglVertexAttrib4Nub = wrapglVertexAttrib4Nub;
1390         qglVertexAttrib1fv = wrapglVertexAttrib1fv;
1391 //      qglVertexAttrib1sv = wrapglVertexAttrib1sv;
1392 //      qglVertexAttrib1dv = wrapglVertexAttrib1dv;
1393         qglVertexAttrib2fv = wrapglVertexAttrib2fv;
1394 //      qglVertexAttrib2sv = wrapglVertexAttrib2sv;
1395 //      qglVertexAttrib2dv = wrapglVertexAttrib2dv;
1396         qglVertexAttrib3fv = wrapglVertexAttrib3fv;
1397 //      qglVertexAttrib3sv = wrapglVertexAttrib3sv;
1398 //      qglVertexAttrib3dv = wrapglVertexAttrib3dv;
1399         qglVertexAttrib4fv = wrapglVertexAttrib4fv;
1400 //      qglVertexAttrib4sv = wrapglVertexAttrib4sv;
1401 //      qglVertexAttrib4dv = wrapglVertexAttrib4dv;
1402 //      qglVertexAttrib4iv = wrapglVertexAttrib4iv;
1403 //      qglVertexAttrib4bv = wrapglVertexAttrib4bv;
1404 //      qglVertexAttrib4ubv = wrapglVertexAttrib4ubv;
1405 //      qglVertexAttrib4usv = wrapglVertexAttrib4usv;
1406 //      qglVertexAttrib4uiv = wrapglVertexAttrib4uiv;
1407 //      qglVertexAttrib4Nbv = wrapglVertexAttrib4Nbv;
1408 //      qglVertexAttrib4Nsv = wrapglVertexAttrib4Nsv;
1409 //      qglVertexAttrib4Niv = wrapglVertexAttrib4Niv;
1410 //      qglVertexAttrib4Nubv = wrapglVertexAttrib4Nubv;
1411 //      qglVertexAttrib4Nusv = wrapglVertexAttrib4Nusv;
1412 //      qglVertexAttrib4Nuiv = wrapglVertexAttrib4Nuiv;
1413 //      qglGetVertexAttribdv = wrapglGetVertexAttribdv;
1414         qglGetVertexAttribfv = wrapglGetVertexAttribfv;
1415         qglGetVertexAttribiv = wrapglGetVertexAttribiv;
1416         qglGetVertexAttribPointerv = wrapglGetVertexAttribPointerv;
1417
1418         gl_renderer = (const char *)qglGetString(GL_RENDERER);
1419         gl_vendor = (const char *)qglGetString(GL_VENDOR);
1420         gl_version = (const char *)qglGetString(GL_VERSION);
1421         gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
1422         
1423         if (!gl_extensions)
1424                 gl_extensions = "";
1425         if (!gl_platformextensions)
1426                 gl_platformextensions = "";
1427         
1428         Con_Printf("GL_VENDOR: %s\n", gl_vendor);
1429         Con_Printf("GL_RENDERER: %s\n", gl_renderer);
1430         Con_Printf("GL_VERSION: %s\n", gl_version);
1431         Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
1432         Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
1433         
1434         // LordHavoc: report supported extensions
1435         Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
1436         
1437         vid.support.gl20shaders = true;
1438         vid.support.amd_texture_texture4 = false;
1439         vid.support.arb_depth_texture = false;
1440         vid.support.arb_draw_buffers = false;
1441         vid.support.arb_multitexture = false;
1442         vid.support.arb_occlusion_query = false;
1443         vid.support.arb_shadow = false;
1444         vid.support.arb_texture_compression = false; // different (vendor-specific) formats than on desktop OpenGL...
1445         vid.support.arb_texture_cube_map = true;
1446         vid.support.arb_texture_env_combine = false;
1447         vid.support.arb_texture_gather = false;
1448         vid.support.arb_texture_non_power_of_two = strstr(gl_extensions, "GL_OES_texture_npot") != NULL;
1449         vid.support.arb_vertex_buffer_object = true;
1450         vid.support.ati_separate_stencil = false;
1451         vid.support.ext_blend_minmax = false;
1452         vid.support.ext_blend_subtract = true;
1453         vid.support.ext_draw_range_elements = true;
1454         vid.support.ext_framebuffer_object = false;//true;
1455         vid.support.ext_stencil_two_side = false;
1456         vid.support.ext_texture_3d = false;//SDL_GL_ExtensionSupported("GL_OES_texture_3D"); // iPhoneOS does not support 3D textures, odd...
1457         vid.support.ext_texture_compression_s3tc = false;
1458         vid.support.ext_texture_edge_clamp = true;
1459         vid.support.ext_texture_filter_anisotropic = false; // probably don't want to use it...
1460
1461         qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
1462         if (vid.support.ext_texture_filter_anisotropic)
1463                 qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
1464         if (vid.support.arb_texture_cube_map)
1465                 qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&vid.maxtexturesize_cubemap);
1466         if (vid.support.ext_texture_3d)
1467                 qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
1468         Con_Printf("GL_MAX_CUBE_MAP_TEXTURE_SIZE = %i\n", vid.maxtexturesize_cubemap);
1469         Con_Printf("GL_MAX_3D_TEXTURE_SIZE = %i\n", vid.maxtexturesize_3d);
1470
1471         // verify that cubemap textures are really supported
1472         if (vid.support.arb_texture_cube_map && vid.maxtexturesize_cubemap < 256)
1473                 vid.support.arb_texture_cube_map = false;
1474         
1475         // verify that 3d textures are really supported
1476         if (vid.support.ext_texture_3d && vid.maxtexturesize_3d < 32)
1477         {
1478                 vid.support.ext_texture_3d = false;
1479                 Con_Printf("GL_OES_texture_3d reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n");
1480         }
1481
1482         vid.texunits = 4;
1483         vid.teximageunits = 8;
1484         vid.texarrayunits = 5;
1485         vid.texunits = bound(1, vid.texunits, MAX_TEXTUREUNITS);
1486         vid.teximageunits = bound(1, vid.teximageunits, MAX_TEXTUREUNITS);
1487         vid.texarrayunits = bound(1, vid.texarrayunits, MAX_TEXTUREUNITS);
1488         Con_DPrintf("Using GLES2.0 rendering path - %i texture matrix, %i texture images, %i texcoords%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.support.ext_framebuffer_object ? ", shadowmapping supported" : "");
1489         vid.renderpath = RENDERPATH_GLES2;
1490         vid.useinterleavedarrays = false;
1491
1492         // VorteX: set other info (maybe place them in VID_InitMode?)
1493         extern cvar_t gl_info_vendor;
1494         extern cvar_t gl_info_renderer;
1495         extern cvar_t gl_info_version;
1496         extern cvar_t gl_info_platform;
1497         extern cvar_t gl_info_driver;
1498         Cvar_SetQuick(&gl_info_vendor, gl_vendor);
1499         Cvar_SetQuick(&gl_info_renderer, gl_renderer);
1500         Cvar_SetQuick(&gl_info_version, gl_version);
1501         Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
1502         Cvar_SetQuick(&gl_info_driver, gl_driver);
1503 }
1504 #endif
1505
1506 void *GL_GetProcAddress(const char *name)
1507 {
1508         void *p = NULL;
1509         p = SDL_GL_GetProcAddress(name);
1510         return p;
1511 }
1512
1513 static qboolean vid_sdl_initjoysticksystem = false;
1514
1515 void VID_Init (void)
1516 {
1517 #ifndef __IPHONEOS__
1518 #ifdef MACOSX
1519         Cvar_RegisterVariable(&apple_mouse_noaccel);
1520 #endif
1521 #endif
1522         Cvar_RegisterVariable(&vid_soft);
1523         Cvar_RegisterVariable(&vid_soft_threads);
1524         Cvar_RegisterVariable(&vid_soft_interlace);
1525         Cvar_RegisterVariable(&joy_detected);
1526         Cvar_RegisterVariable(&joy_enable);
1527         Cvar_RegisterVariable(&joy_index);
1528         Cvar_RegisterVariable(&joy_axisforward);
1529         Cvar_RegisterVariable(&joy_axisside);
1530         Cvar_RegisterVariable(&joy_axisup);
1531         Cvar_RegisterVariable(&joy_axispitch);
1532         Cvar_RegisterVariable(&joy_axisyaw);
1533         //Cvar_RegisterVariable(&joy_axisroll);
1534         Cvar_RegisterVariable(&joy_deadzoneforward);
1535         Cvar_RegisterVariable(&joy_deadzoneside);
1536         Cvar_RegisterVariable(&joy_deadzoneup);
1537         Cvar_RegisterVariable(&joy_deadzonepitch);
1538         Cvar_RegisterVariable(&joy_deadzoneyaw);
1539         //Cvar_RegisterVariable(&joy_deadzoneroll);
1540         Cvar_RegisterVariable(&joy_sensitivityforward);
1541         Cvar_RegisterVariable(&joy_sensitivityside);
1542         Cvar_RegisterVariable(&joy_sensitivityup);
1543         Cvar_RegisterVariable(&joy_sensitivitypitch);
1544         Cvar_RegisterVariable(&joy_sensitivityyaw);
1545         //Cvar_RegisterVariable(&joy_sensitivityroll);
1546         Cvar_RegisterVariable(&joy_axiskeyevents);
1547 #ifdef __IPHONEOS__
1548         Cvar_SetValueQuick(&vid_touchscreen, 1);
1549 #endif
1550
1551 #ifdef SDL_R_RESTART
1552         R_RegisterModule("SDL", sdl_start, sdl_shutdown, sdl_newmap, NULL, NULL);
1553 #endif
1554
1555         if (SDL_Init(SDL_INIT_VIDEO) < 0)
1556                 Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError());
1557         vid_sdl_initjoysticksystem = SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0;
1558         if (vid_sdl_initjoysticksystem)
1559                 Con_Printf("Failed to init SDL joystick subsystem: %s\n", SDL_GetError());
1560         vid_isfullscreen = false;
1561 }
1562
1563 #if SETVIDEOMODE
1564 // set the icon (we dont use SDL here since it would be too much a PITA)
1565 #ifdef WIN32
1566 #include "resource.h"
1567 #include <SDL_syswm.h>
1568 static void VID_SetCaption(void)
1569 {
1570     SDL_SysWMinfo       info;
1571         HICON                   icon;
1572
1573         // set the caption
1574         SDL_WM_SetCaption( gamename, NULL );
1575
1576         // get the HWND handle
1577     SDL_VERSION( &info.version );
1578         if( !SDL_GetWMInfo( &info ) )
1579                 return;
1580
1581         icon = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDI_ICON1 ) );
1582 #ifndef _W64 //If Windows 64bit data types don't exist
1583 #ifndef SetClassLongPtr
1584 #define SetClassLongPtr SetClassLong
1585 #endif
1586 #ifndef GCLP_HICON
1587 #define GCLP_HICON GCL_HICON
1588 #endif
1589 #ifndef LONG_PTR
1590 #define LONG_PTR LONG
1591 #endif
1592 #endif
1593         SetClassLongPtr( info.window, GCLP_HICON, (LONG_PTR)icon );
1594 }
1595 static void VID_SetIcon_Pre(void)
1596 {
1597 }
1598 static void VID_SetIcon_Post(void)
1599 {
1600 }
1601 #else
1602 // Adding the OS independent XPM version --blub
1603 #include "darkplaces.xpm"
1604 #include "nexuiz.xpm"
1605 static SDL_Surface *icon = NULL;
1606 static void VID_SetIcon_Pre(void)
1607 {
1608         /*
1609          * Somewhat restricted XPM reader. Only supports XPMs saved by GIMP 2.4 at
1610          * default settings with less than 91 colors and transparency.
1611          */
1612
1613         int width, height, colors, isize, i, j;
1614         int thenone = -1;
1615         static SDL_Color palette[256];
1616         unsigned short palenc[256]; // store color id by char
1617         char *xpm;
1618         char **idata, *data;
1619         const SDL_version *version;
1620
1621         version = SDL_Linked_Version();
1622         // only use non-XPM icon support in SDL v1.3 and higher
1623         // SDL v1.2 does not support "smooth" transparency, and thus is better
1624         // off the xpm way
1625         if(version->major >= 2 || (version->major == 1 && version->minor >= 3))
1626         {
1627                 data = (char *) loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL);
1628                 if(data)
1629                 {
1630                         unsigned int red = 0x00FF0000;
1631                         unsigned int green = 0x0000FF00;
1632                         unsigned int blue = 0x000000FF;
1633                         unsigned int alpha = 0xFF000000;
1634                         width = image_width;
1635                         height = image_height;
1636
1637                         // reallocate with malloc, as this is in tempmempool (do not want)
1638                         xpm = data;
1639                         data = malloc(width * height * 4);
1640                         memcpy(data, xpm, width * height * 4);
1641                         Mem_Free(xpm);
1642                         xpm = NULL;
1643
1644                         icon = SDL_CreateRGBSurface(SDL_SRCALPHA, width, height, 32, LittleLong(red), LittleLong(green), LittleLong(blue), LittleLong(alpha));
1645
1646                         if(icon == NULL) {
1647                                 Con_Printf(     "Failed to create surface for the window Icon!\n"
1648                                                 "%s\n", SDL_GetError());
1649                                 free(data);
1650                                 return;
1651                         }
1652
1653                         icon->pixels = data;
1654                 }
1655         }
1656
1657         // we only get here if non-XPM icon was missing, or SDL version is not
1658         // sufficient for transparent non-XPM icons
1659         if(!icon)
1660         {
1661                 xpm = (char *) FS_LoadFile("darkplaces-icon.xpm", tempmempool, false, NULL);
1662                 idata = NULL;
1663                 if(xpm)
1664                         idata = XPM_DecodeString(xpm);
1665                 if(!idata)
1666                         idata = ENGINE_ICON;
1667                 if(xpm)
1668                         Mem_Free(xpm);
1669
1670                 data = idata[0];
1671
1672                 if(sscanf(data, "%i %i %i %i", &width, &height, &colors, &isize) != 4)
1673                 {
1674                         // NOTE: Only 1-char colornames are supported
1675                         Con_Printf("Sorry, but this does not even look similar to an XPM.\n");
1676                         return;
1677                 }
1678
1679                 if(isize != 1)
1680                 {
1681                         // NOTE: Only 1-char colornames are supported
1682                         Con_Printf("This XPM's palette is either huge or idiotically unoptimized. It's key size is %i\n", isize);
1683                         return;
1684                 }
1685
1686                 for(i = 0; i < colors; ++i)
1687                 {
1688                         unsigned int r, g, b;
1689                         char idx;
1690
1691                         if(sscanf(idata[i+1], "%c c #%02x%02x%02x", &idx, &r, &g, &b) != 4)
1692                         {
1693                                 char foo[2];
1694                                 if(sscanf(idata[i+1], "%c c Non%1[e]", &idx, foo) != 2) // I take the DailyWTF credit for this. --div0
1695                                 {
1696                                         Con_Printf("This XPM's palette looks odd. Can't continue.\n");
1697                                         return;
1698                                 }
1699                                 else
1700                                 {
1701                                         palette[i].r = 255; // color key
1702                                         palette[i].g = 0;
1703                                         palette[i].b = 255;
1704                                         thenone = i; // weeeee
1705                                 }
1706                         }
1707                         else
1708                         {
1709                                 palette[i].r = r - (r == 255 && g == 0 && b == 255); // change 255/0/255 pink to 254/0/255 for color key
1710                                 palette[i].g = g;
1711                                 palette[i].b = b;
1712                         }
1713
1714                         palenc[(unsigned char) idx] = i;
1715                 }
1716
1717                 // allocate the image data
1718                 data = (char*) malloc(width*height);
1719
1720                 for(j = 0; j < height; ++j)
1721                 {
1722                         for(i = 0; i < width; ++i)
1723                         {
1724                                 // casting to the safest possible datatypes ^^
1725                                 data[j * width + i] = palenc[((unsigned char*)idata[colors+j+1])[i]];
1726                         }
1727                 }
1728
1729                 if(icon != NULL)
1730                 {
1731                         // SDL_FreeSurface should free the data too
1732                         // but for completeness' sake...
1733                         if(icon->flags & SDL_PREALLOC)
1734                         {
1735                                 free(icon->pixels);
1736                                 icon->pixels = NULL; // safety
1737                         }
1738                         SDL_FreeSurface(icon);
1739                 }
1740
1741                 icon = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, width, height, 8, 0,0,0,0);// rmask, gmask, bmask, amask); no mask needed
1742                 // 8 bit surfaces get an empty palette allocated according to the docs
1743                 // so it's a palette image for sure :) no endian check necessary for the mask
1744
1745                 if(icon == NULL) {
1746                         Con_Printf(     "Failed to create surface for the window Icon!\n"
1747                                         "%s\n", SDL_GetError());
1748                         free(data);
1749                         return;
1750                 }
1751
1752                 icon->pixels = data;
1753                 SDL_SetPalette(icon, SDL_PHYSPAL|SDL_LOGPAL, palette, 0, colors);
1754                 SDL_SetColorKey(icon, SDL_SRCCOLORKEY, thenone);
1755         }
1756
1757         SDL_WM_SetIcon(icon, NULL);
1758 }
1759 static void VID_SetIcon_Post(void)
1760 {
1761 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
1762 // LordHavoc: info.info.x11.lock_func and accompanying code do not seem to compile with SDL 1.3
1763 #if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
1764         int j;
1765         char *data;
1766         const SDL_version *version;
1767
1768         version = SDL_Linked_Version();
1769         // only use non-XPM icon support in SDL v1.3 and higher
1770         // SDL v1.2 does not support "smooth" transparency, and thus is better
1771         // off the xpm way
1772         if(!(version->major >= 2 || (version->major == 1 && version->minor >= 3)))
1773         {
1774                 // in this case, we did not set the good icon yet
1775                 SDL_SysWMinfo info;
1776                 SDL_VERSION(&info.version);
1777                 if(SDL_GetWMInfo(&info) == 1 && info.subsystem == SDL_SYSWM_X11)
1778                 {
1779                         data = (char *) loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL);
1780                         if(data)
1781                         {
1782                                 // use _NET_WM_ICON too
1783                                 static long netwm_icon[MAX_NETWM_ICON];
1784                                 int pos = 0;
1785                                 int i = 1;
1786
1787                                 while(data)
1788                                 {
1789                                         if(pos + 2 * image_width * image_height < MAX_NETWM_ICON)
1790                                         {
1791                                                 netwm_icon[pos++] = image_width;
1792                                                 netwm_icon[pos++] = image_height;
1793                                                 for(i = 0; i < image_height; ++i)
1794                                                         for(j = 0; j < image_width; ++j)
1795                                                                 netwm_icon[pos++] = BuffLittleLong((unsigned char *) &data[(i*image_width+j)*4]);
1796                                         }
1797                                         else
1798                                         {
1799                                                 Con_Printf("Skipping NETWM icon #%d because there is no space left\n", i);
1800                                         }
1801                                         ++i;
1802                                         Mem_Free(data);
1803                                         data = (char *) loadimagepixelsbgra(va("darkplaces-icon%d", i), false, false, false, NULL);
1804                                 }
1805
1806                                 info.info.x11.lock_func();
1807                                 {
1808                                         Atom net_wm_icon = XInternAtom(info.info.x11.display, "_NET_WM_ICON", false);
1809                                         XChangeProperty(info.info.x11.display, info.info.x11.wmwindow, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (const unsigned char *) netwm_icon, pos);
1810                                 }
1811                                 info.info.x11.unlock_func();
1812                         }
1813                 }
1814         }
1815 #endif
1816 #endif
1817 }
1818
1819
1820 static void VID_SetCaption(void)
1821 {
1822         SDL_WM_SetCaption( gamename, NULL );
1823 }
1824 #endif
1825 #endif
1826
1827 static void VID_OutputVersion(void)
1828 {
1829         const SDL_version *version;
1830         version = SDL_Linked_Version();
1831         Con_Printf(     "Linked against SDL version %d.%d.%d\n"
1832                                         "Using SDL library version %d.%d.%d\n",
1833                                         SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
1834                                         version->major, version->minor, version->patch );
1835 }
1836
1837 qboolean VID_InitModeGL(viddef_mode_t *mode)
1838 {
1839         int i;
1840 #if SETVIDEOMODE
1841         static int notfirstvideomode = false;
1842         int flags = SDL_OPENGL;
1843 #else
1844         int windowflags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
1845 #endif
1846         const char *drivername;
1847
1848         win_half_width = mode->width>>1;
1849         win_half_height = mode->height>>1;
1850
1851         if(vid_resizable.integer)
1852 #if SETVIDEOMODE
1853                 flags |= SDL_RESIZABLE;
1854 #else
1855                 windowflags |= SDL_WINDOW_RESIZABLE;
1856 #endif
1857
1858         VID_OutputVersion();
1859
1860 #if SETVIDEOMODE
1861         /*
1862         SDL 1.2 Hack
1863                 We cant switch from one OpenGL video mode to another.
1864                 Thus we first switch to some stupid 2D mode and then back to OpenGL.
1865         */
1866         if (notfirstvideomode)
1867                 SDL_SetVideoMode( 0, 0, 0, 0 );
1868         notfirstvideomode = true;
1869 #endif
1870
1871         // SDL usually knows best
1872         drivername = NULL;
1873
1874 // COMMANDLINEOPTION: SDL GL: -gl_driver <drivername> selects a GL driver library, default is whatever SDL recommends, useful only for 3dfxogl.dll/3dfxvgl.dll or fxmesa or similar, if you don't know what this is for, you don't need it
1875         i = COM_CheckParm("-gl_driver");
1876         if (i && i < com_argc - 1)
1877                 drivername = com_argv[i + 1];
1878         if (SDL_GL_LoadLibrary(drivername) < 0)
1879         {
1880                 Con_Printf("Unable to load GL driver \"%s\": %s\n", drivername, SDL_GetError());
1881                 return false;
1882         }
1883
1884 #ifdef __IPHONEOS__
1885         // mobile platforms are always fullscreen, we'll get the resolution after opening the window
1886         mode->fullscreen = true;
1887         // hide the menu with SDL_WINDOW_BORDERLESS
1888         windowflags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1889 #else
1890         if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
1891         {
1892                 VID_Shutdown();
1893                 Con_Print("Required OpenGL function glGetString not found\n");
1894                 return false;
1895         }
1896 #endif
1897
1898         // Knghtbrd: should do platform-specific extension string function here
1899
1900         vid_isfullscreen = false;
1901         if (mode->fullscreen) {
1902 #if SETVIDEOMODE
1903                 flags |= SDL_FULLSCREEN;
1904 #else
1905                 windowflags |= SDL_WINDOW_FULLSCREEN;
1906 #endif
1907                 vid_isfullscreen = true;
1908         }
1909         //flags |= SDL_HWSURFACE;
1910
1911         SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
1912         if (mode->bitsperpixel >= 32)
1913         {
1914                 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
1915                 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
1916                 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
1917                 SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8);
1918                 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
1919                 SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
1920         }
1921         else
1922         {
1923                 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
1924                 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
1925                 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
1926                 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
1927         }
1928         if (mode->stereobuffer)
1929                 SDL_GL_SetAttribute (SDL_GL_STEREO, 1);
1930         if (mode->samples > 1)
1931         {
1932                 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
1933                 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples);
1934         }
1935 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
1936         if (vid_vsync.integer)
1937                 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
1938         else
1939                 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
1940 #else
1941 #ifdef __IPHONEOS__
1942         SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1943         SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
1944         SDL_GL_SetAttribute (SDL_GL_RETAINED_BACKING, 1);
1945         // FIXME: get proper resolution from OS somehow (iPad for instance...)
1946         mode->width = 320;
1947         mode->height = 480;
1948 #endif
1949 #endif
1950
1951         video_bpp = mode->bitsperpixel;
1952 #if SETVIDEOMODE
1953         video_flags = flags;
1954         VID_SetIcon_Pre();
1955         screen = SDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
1956         VID_SetIcon_Post();
1957         if (screen == NULL)
1958         {
1959                 Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
1960                 VID_Shutdown();
1961                 return false;
1962         }
1963         mode->width = screen->w;
1964         mode->height = screen->h;
1965 #else
1966         window_flags = windowflags;
1967         window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags);
1968         if (window == NULL)
1969         {
1970                 Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
1971                 VID_Shutdown();
1972                 return false;
1973         }
1974         SDL_GetWindowSize(window, &mode->width, &mode->height);
1975         context = SDL_GL_CreateContext(window);
1976         if (context == NULL)
1977         {
1978                 Con_Printf("Failed to initialize OpenGL context: %s\n", SDL_GetError());
1979                 VID_Shutdown();
1980                 return false;
1981         }
1982 #endif
1983
1984         vid_softsurface = NULL;
1985         vid.softpixels = NULL;
1986
1987 #if SETVIDEOMODE
1988         // set window title
1989         VID_SetCaption();
1990 #endif
1991         // init keyboard
1992         SDL_EnableUNICODE( SDL_ENABLE );
1993         // enable key repeat since everyone expects it
1994         SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
1995
1996 #if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
1997         SDL_GL_SetSwapInterval(vid_vsync.integer != 0);
1998         vid_usingvsync = (vid_vsync.integer != 0);
1999 #endif
2000
2001         gl_platform = "SDL";
2002         gl_platformextensions = "";
2003
2004 #ifdef __IPHONEOS__
2005         GLES_Init();
2006 #else
2007         GL_Init();
2008 #endif
2009
2010         vid_numjoysticks = SDL_NumJoysticks();
2011         vid_numjoysticks = bound(0, vid_numjoysticks, MAX_JOYSTICKS);
2012         Cvar_SetValueQuick(&joy_detected, vid_numjoysticks);
2013         Con_Printf("%d SDL joystick(s) found:\n", vid_numjoysticks);
2014         memset(vid_joysticks, 0, sizeof(vid_joysticks));
2015         for (i = 0;i < vid_numjoysticks;i++)
2016         {
2017                 SDL_Joystick *joy;
2018                 joy = vid_joysticks[i] = SDL_JoystickOpen(i);
2019                 if (!joy)
2020                 {
2021                         Con_Printf("joystick #%i: open failed: %s\n", i, SDL_GetError());
2022                         continue;
2023                 }
2024                 Con_Printf("joystick #%i: opened \"%s\" with %i axes, %i buttons, %i balls\n", i, SDL_JoystickName(i), (int)SDL_JoystickNumAxes(joy), (int)SDL_JoystickNumButtons(joy), (int)SDL_JoystickNumBalls(joy));
2025         }
2026
2027         vid_hidden = false;
2028         vid_activewindow = false;
2029         vid_usingmouse = false;
2030         vid_usinghidecursor = false;
2031
2032 #if SETVIDEOMODE
2033         SDL_WM_GrabInput(SDL_GRAB_OFF);
2034 #endif
2035         return true;
2036 }
2037
2038 extern cvar_t gl_info_extensions;
2039 extern cvar_t gl_info_vendor;
2040 extern cvar_t gl_info_renderer;
2041 extern cvar_t gl_info_version;
2042 extern cvar_t gl_info_platform;
2043 extern cvar_t gl_info_driver;
2044
2045 qboolean VID_InitModeSoft(viddef_mode_t *mode)
2046 {
2047         int i;
2048 #if SETVIDEOMODE
2049         int flags = SDL_HWSURFACE;
2050 #else
2051         int windowflags = SDL_WINDOW_SHOWN;
2052 #endif
2053
2054         win_half_width = mode->width>>1;
2055         win_half_height = mode->height>>1;
2056
2057         if(vid_resizable.integer)
2058 #if SETVIDEOMODE
2059                 flags |= SDL_RESIZABLE;
2060 #else
2061                 windowflags |= SDL_WINDOW_RESIZABLE;
2062 #endif
2063
2064         VID_OutputVersion();
2065
2066         vid_isfullscreen = false;
2067         if (mode->fullscreen) {
2068 #if SETVIDEOMODE
2069                 flags |= SDL_FULLSCREEN;
2070 #else
2071                 windowflags |= SDL_WINDOW_FULLSCREEN;
2072 #endif
2073                 vid_isfullscreen = true;
2074         }
2075
2076         video_bpp = mode->bitsperpixel;
2077 #if SETVIDEOMODE
2078         video_flags = flags;
2079         VID_SetIcon_Pre();
2080         screen = SDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
2081         VID_SetIcon_Post();
2082         if (screen == NULL)
2083         {
2084                 Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
2085                 VID_Shutdown();
2086                 return false;
2087         }
2088         mode->width = screen->w;
2089         mode->height = screen->h;
2090 #else
2091         window_flags = windowflags;
2092         window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags);
2093         if (window == NULL)
2094         {
2095                 Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
2096                 VID_Shutdown();
2097                 return false;
2098         }
2099         SDL_GetWindowSize(window, &mode->width, &mode->height);
2100 #endif
2101
2102         // create a framebuffer using our specific color format, we let the SDL blit function convert it in VID_Finish
2103         vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, mode->width, mode->height, 32, 0x00FF0000, 0x0000FF00, 0x00000000FF, 0xFF000000);
2104         if (vid_softsurface == NULL)
2105         {
2106                 Con_Printf("Failed to setup software rasterizer framebuffer %ix%ix32bpp: %s\n", mode->width, mode->height, SDL_GetError());
2107                 VID_Shutdown();
2108                 return false;
2109         }
2110         SDL_SetAlpha(vid_softsurface, 0, 255);
2111
2112         vid.softpixels = (unsigned int *)vid_softsurface->pixels;
2113         vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
2114         if (DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid_softsurface->pixels, (unsigned int *)vid.softdepthpixels) < 0)
2115         {
2116                 Con_Printf("Failed to initialize software rasterizer\n");
2117                 VID_Shutdown();
2118                 return false;
2119         }
2120
2121 #if SETVIDEOMODE
2122         // set window title
2123         VID_SetCaption();
2124 #endif
2125         // init keyboard
2126         SDL_EnableUNICODE( SDL_ENABLE );
2127         // enable key repeat since everyone expects it
2128         SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
2129
2130         gl_platform = "SDLSoft";
2131         gl_platformextensions = "";
2132
2133         gl_renderer = "DarkPlaces-Soft";
2134         gl_vendor = "Forest Hale";
2135         gl_version = "0.0";
2136         gl_extensions = "";
2137
2138         // clear the extension flags
2139         memset(&vid.support, 0, sizeof(vid.support));
2140         Cvar_SetQuick(&gl_info_extensions, "");
2141
2142         vid.forcevbo = false;
2143         vid.support.arb_depth_texture = true;
2144         vid.support.arb_draw_buffers = true;
2145         vid.support.arb_occlusion_query = true;
2146         vid.support.arb_shadow = true;
2147         //vid.support.arb_texture_compression = true;
2148         vid.support.arb_texture_cube_map = true;
2149         vid.support.arb_texture_non_power_of_two = false;
2150         vid.support.arb_vertex_buffer_object = true;
2151         vid.support.ext_blend_subtract = true;
2152         vid.support.ext_draw_range_elements = true;
2153         vid.support.ext_framebuffer_object = true;
2154         vid.support.ext_texture_3d = true;
2155         //vid.support.ext_texture_compression_s3tc = true;
2156         vid.support.ext_texture_filter_anisotropic = true;
2157         vid.support.ati_separate_stencil = true;
2158
2159         vid.maxtexturesize_2d = 16384;
2160         vid.maxtexturesize_3d = 512;
2161         vid.maxtexturesize_cubemap = 16384;
2162         vid.texunits = 4;
2163         vid.teximageunits = 32;
2164         vid.texarrayunits = 8;
2165         vid.max_anisotropy = 1;
2166         vid.maxdrawbuffers = 4;
2167
2168         vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
2169         vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
2170         vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
2171         Con_DPrintf("Using DarkPlaces Software Rasterizer rendering path\n");
2172         vid.renderpath = RENDERPATH_SOFT;
2173         vid.useinterleavedarrays = false;
2174
2175         Cvar_SetQuick(&gl_info_vendor, gl_vendor);
2176         Cvar_SetQuick(&gl_info_renderer, gl_renderer);
2177         Cvar_SetQuick(&gl_info_version, gl_version);
2178         Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
2179         Cvar_SetQuick(&gl_info_driver, gl_driver);
2180
2181         // LordHavoc: report supported extensions
2182         Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
2183
2184         // clear to black (loading plaque will be seen over this)
2185         GL_Clear(GL_COLOR_BUFFER_BIT, NULL, 1.0f, 128);
2186
2187         vid_numjoysticks = SDL_NumJoysticks();
2188         vid_numjoysticks = bound(0, vid_numjoysticks, MAX_JOYSTICKS);
2189         Cvar_SetValueQuick(&joy_detected, vid_numjoysticks);
2190         Con_Printf("%d SDL joystick(s) found:\n", vid_numjoysticks);
2191         memset(vid_joysticks, 0, sizeof(vid_joysticks));
2192         for (i = 0;i < vid_numjoysticks;i++)
2193         {
2194                 SDL_Joystick *joy;
2195                 joy = vid_joysticks[i] = SDL_JoystickOpen(i);
2196                 if (!joy)
2197                 {
2198                         Con_Printf("joystick #%i: open failed: %s\n", i, SDL_GetError());
2199                         continue;
2200                 }
2201                 Con_Printf("joystick #%i: opened \"%s\" with %i axes, %i buttons, %i balls\n", i, SDL_JoystickName(i), (int)SDL_JoystickNumAxes(joy), (int)SDL_JoystickNumButtons(joy), (int)SDL_JoystickNumBalls(joy));
2202         }
2203
2204         vid_hidden = false;
2205         vid_activewindow = false;
2206         vid_usingmouse = false;
2207         vid_usinghidecursor = false;
2208
2209 #if SETVIDEOMODE
2210         SDL_WM_GrabInput(SDL_GRAB_OFF);
2211 #endif
2212         return true;
2213 }
2214
2215 qboolean VID_InitMode(viddef_mode_t *mode)
2216 {
2217         if (!SDL_WasInit(SDL_INIT_VIDEO) && SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
2218                 Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError());
2219 #ifdef SSE2_PRESENT
2220         if (vid_soft.integer)
2221                 return VID_InitModeSoft(mode);
2222         else
2223 #endif
2224                 return VID_InitModeGL(mode);
2225 }
2226
2227 void VID_Shutdown (void)
2228 {
2229         VID_SetMouse(false, false, false);
2230         VID_RestoreSystemGamma();
2231
2232 #if SETVIDEOMODE
2233 #ifndef WIN32
2234         if (icon)
2235                 SDL_FreeSurface(icon);
2236         icon = NULL;
2237 #endif
2238 #endif
2239
2240         if (vid_softsurface)
2241                 SDL_FreeSurface(vid_softsurface);
2242         vid_softsurface = NULL;
2243         vid.softpixels = NULL;
2244         if (vid.softdepthpixels)
2245                 free(vid.softdepthpixels);
2246         vid.softdepthpixels = NULL;
2247
2248 #if SETVIDEOMODE
2249 #else
2250         SDL_DestroyWindow(window);
2251         window = NULL;
2252 #endif
2253
2254         SDL_QuitSubSystem(SDL_INIT_VIDEO);
2255
2256         gl_driver[0] = 0;
2257         gl_extensions = "";
2258         gl_platform = "";
2259         gl_platformextensions = "";
2260 }
2261
2262 int VID_SetGamma (unsigned short *ramps, int rampsize)
2263 {
2264         return !SDL_SetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
2265 }
2266
2267 int VID_GetGamma (unsigned short *ramps, int rampsize)
2268 {
2269         return !SDL_GetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
2270 }
2271
2272 void VID_Finish (void)
2273 {
2274 #if SETVIDEOMODE
2275         Uint8 appstate;
2276
2277         //react on appstate changes
2278         appstate = SDL_GetAppState();
2279
2280         vid_hidden = !(appstate & SDL_APPACTIVE);
2281         vid_hasfocus = (appstate & SDL_APPMOUSEFOCUS) && (appstate & SDL_APPINPUTFOCUS);
2282 #endif
2283         vid_activewindow = !vid_hidden && vid_hasfocus;
2284
2285         VID_UpdateGamma(false, 256);
2286
2287         if (!vid_hidden)
2288         {
2289                 switch(vid.renderpath)
2290                 {
2291                 case RENDERPATH_GL11:
2292                 case RENDERPATH_GL13:
2293                 case RENDERPATH_GL20:
2294                 case RENDERPATH_GLES2:
2295                         CHECKGLERROR
2296                         if (r_speeds.integer == 2 || gl_finish.integer)
2297                         {
2298                                 qglFinish();CHECKGLERROR
2299                         }
2300 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
2301 #else
2302 {
2303         qboolean vid_usevsync;
2304         vid_usevsync = (vid_vsync.integer && !cls.timedemo);
2305         if (vid_usingvsync != vid_usevsync)
2306         {
2307                 if (SDL_GL_SetSwapInterval(vid_usevsync != 0) >= 0)
2308                         Con_DPrintf("Vsync %s\n", vid_usevsync ? "activated" : "deactivated");
2309                 else
2310                         Con_DPrintf("ERROR: can't %s vsync\n", vid_usevsync ? "activate" : "deactivate");
2311         }
2312 }
2313 #endif
2314 #if SETVIDEOMODE
2315                         SDL_GL_SwapBuffers();
2316 #else
2317                         SDL_GL_SwapWindow(window);
2318 #endif
2319                         break;
2320                 case RENDERPATH_SOFT:
2321                         DPSOFTRAST_Finish();
2322 #if SETVIDEOMODE
2323                         SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
2324                         SDL_Flip(screen);
2325 #else
2326                         {
2327                                 SDL_Surface *screen = SDL_GetWindowSurface(window);
2328                                 SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
2329                                 SDL_UpdateWindowSurface(window);
2330                         }
2331 #endif
2332                         break;
2333                 case RENDERPATH_D3D9:
2334                 case RENDERPATH_D3D10:
2335                 case RENDERPATH_D3D11:
2336                         break;
2337                 }
2338         }
2339 }
2340
2341 size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
2342 {
2343         size_t k;
2344         SDL_Rect **vidmodes;
2345         int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
2346
2347         k = 0;
2348         for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); *vidmodes; ++vidmodes)
2349         {
2350                 if(k >= maxcount)
2351                         break;
2352                 modes[k].width = (*vidmodes)->w;
2353                 modes[k].height = (*vidmodes)->h;
2354                 modes[k].bpp = bpp;
2355                 modes[k].refreshrate = 60; // no support for refresh rate in SDL
2356                 modes[k].pixelheight_num = 1;
2357                 modes[k].pixelheight_denom = 1; // SDL does not provide this
2358                 ++k;
2359         }
2360         return k;
2361 }