34 #if defined (SDL_WINDOWING) && defined (HAVE_SDL)
44 static SDL_Surface *screen = NULL;
56 static bool keepRunning =
true;
151 passive_motion_func = func;
163 SDL_GL_SwapBuffers();
175 SDL_WarpMouse( x, y );
185 static bool setup_sdl_video_mode()
187 Uint32 video_flags = SDL_OPENGL;
191 video_flags |= SDL_FULLSCREEN;
194 video_flags |= SDL_RESIZABLE;
200 rs = gs = bs = (bpp == 16) ? 5 : 8;
201 string rgbfmt =
vs_config->
getVariable(
"graphics",
"rgb_pixel_format", ( (bpp == 16) ?
"555" :
"888" ) );
205 if ( (rgbfmt.length() == 3) && isdigit( rgbfmt[0] ) && isdigit( rgbfmt[1] ) && isdigit( rgbfmt[2] ) ) {
215 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rs );
216 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, gs );
217 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, bs );
218 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, zs );
219 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
223 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rs );
224 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, gs );
225 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, bs );
226 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, zs );
227 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
229 #if SDL_VERSION_ATLEAST( 1, 2, 10 )
230 if (gl_accelerated_visual)
231 SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
235 if ( ( screen = SDL_SetVideoMode( width, height, bpp, video_flags ) )
239 for (
int counter = 0; screen == NULL && counter < 2; ++counter) {
240 for (
int bpd = 4; bpd > 1; --bpd) {
241 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, bpd*8 );
242 if ( ( screen = SDL_SetVideoMode( width, height, bpp, video_flags|SDL_ANYFORMAT ) )
245 bpp, bpd*8, SDL_GetError() );
249 if (screen == NULL) {
250 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, otherattributes );
251 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, otherattributes );
252 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, otherattributes );
256 if (screen == NULL) {
262 std::string version = (
const char*)glGetString(GL_RENDERER);
263 if (version ==
"GDI Generic")
265 if (gl_accelerated_visual) {
272 "GDI Generic software driver reported, reset failed.\n "
273 "Please make sure a graphics card driver is installed and functioning properly.\n" );
281 screen->format->BitsPerPixel,
282 screen->format->BytesPerPixel );
296 void winsys_init(
int *argc,
char **argv,
char const *window_title,
char const *icon_title )
301 Uint32 sdl_flags = SDL_INIT_VIDEO|SDL_INIT_JOYSTICK;
309 if (SDL_Init( sdl_flags ) < 0) {
313 SDL_EnableUNICODE( 1 );
316 SDL_Surface *icon = NULL;
318 if (icon_title) icon = SDL_LoadBMP( icon_title );
320 SDL_SetColorKey( icon, SDL_SRCCOLORKEY, ( (Uint32*) (icon->pixels) )[0] );
325 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
327 #if defined (USE_STENCIL_BUFFER)
329 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
332 SDL_WM_SetCaption( window_title, window_title );
333 if (icon) SDL_WM_SetIcon( icon, 0 );
335 if (!setup_sdl_video_mode()) {
338 glutInit( argc, argv );
349 void winsys_cleanup()
374 SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY,
375 SDL_DEFAULT_REPEAT_INTERVAL );
377 SDL_EnableKeyRepeat( 0, 0 );
389 static bool vis =
true;
390 if (visible != vis) {
391 SDL_ShowCursor( visible );
418 static unsigned int keysym_to_unicode[256];
419 static bool keysym_to_unicode_init =
false;
420 if (!keysym_to_unicode_init) {
421 keysym_to_unicode_init =
true;
422 memset( keysym_to_unicode, 0,
sizeof (keysym_to_unicode) );
428 while ( SDL_PollEvent( &event ) ) {
437 SDL_GetMouseState( &x, &y );
439 bool maybe_unicode = handle_unicode_kb && !(
event.key.keysym.sym&~0xFF);
441 if (state && maybe_unicode
442 && keysym_to_unicode[event.key.keysym.sym&0xFF])
443 event.key.keysym.unicode = keysym_to_unicode[
event.key.keysym.sym&0xFF];
444 bool is_unicode = maybe_unicode &&
event.key.keysym.unicode;
447 keysym_to_unicode[
event.key.keysym.sym&0xFF] =
event.key.keysym.unicode;
450 bool shifton =
event.key.keysym.mod&(KMOD_LSHIFT|KMOD_RSHIFT|KMOD_CAPS);
451 if (shifton && is_unicode
452 &&
shiftup(
shiftdown( event.key.keysym.unicode ) ) != event.key.keysym.unicode) {
453 event.key.keysym.mod = SDLMod( event.key.keysym.mod&~(KMOD_LSHIFT|KMOD_RSHIFT|KMOD_CAPS) );
462 : event.key.keysym.unicode
463 ) : event.key.keysym.sym;
465 (*keyboard_func)(key,
466 event.key.keysym.mod,
472 case SDL_MOUSEBUTTONDOWN:
473 case SDL_MOUSEBUTTONUP:
475 (*mouse_func)(
event.button.button,
481 case SDL_MOUSEMOTION:
482 if (event.motion.state) {
485 (*motion_func)(
event.motion.x,
489 if (passive_motion_func) {
490 (*passive_motion_func)(
event.motion.x,
495 case SDL_VIDEORESIZE:
496 #if !(defined (_WIN32) && defined (SDL_WINDOWING ) )
499 setup_sdl_video_mode();
501 (*reshape_func)(
event.resize.w,
512 }
else if (idle_func) {
531 static bool called =
false;
589 glutDisplayFunc( func );
601 glutIdleFunc( func );
613 glutReshapeFunc( func );
620 }
else if (ch >=
'0' && ch <=
'9') {}
else if (ch >= 27 && ch <= 31) {
622 }
else if (ch == 127) {
624 }
else if (ch <= 26) {
634 int gm = glutGetModifiers();
637 if (gm&GLUT_ACTIVE_CTRL)
639 (*keyboard_func)(ch, gm,
false,
x,
y);
646 (*keyboard_func)(key+128, glutGetModifiers(),
false,
x,
y);
652 int gm = glutGetModifiers();
655 if (gm&GLUT_ACTIVE_CTRL)
657 (*keyboard_func)(ch, gm,
true,
x,
y);
664 (*keyboard_func)(key+128, glutGetModifiers(),
true,
x,
y);
676 keyboard_func = func;
688 glutMouseFunc( func );
700 glutMotionFunc( func );
712 glutPassiveMotionFunc( func );
736 glutWarpPointer( x, y );
747 void winsys_init(
int *argc,
char **argv,
char const *window_title,
char const *icon_title )
755 glutInit( argc, argv );
759 if ( !(glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL ), 1) )
760 glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
762 glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL );
765 glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
769 glutGameModeString( str );
770 VSFileSystem::vs_dprintf(
'3',
"Game Mode Params %dx%d at depth %d @ %d Hz\n", glutGameModeGet( GLUT_GAME_MODE_WIDTH ),
771 glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH ),
772 glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
775 glutInitWindowPosition( 0, 0 );
778 GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet(
779 GLUT_GAME_MODE_PIXEL_DEPTH ), glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
784 glutWindow = glutCreateWindow( window_title );
785 if (glutWindow == 0) {
801 static bool shutdown =
false;
819 glutIgnoreKeyRepeat( !enabled );
831 static bool vis =
true;
832 if (visible != vis) {
834 glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
836 glutSetCursor( GLUT_CURSOR_NONE );
869 static bool called =
false;