Browse Source

Tried to fix fullscreen mode

Thomas Buck 11 years ago
parent
commit
2446501e04
4 changed files with 54 additions and 7 deletions
  1. 47
    7
      src/SDLSystem.cpp
  2. 3
    0
      src/SDLSystem.h
  3. 2
    0
      src/System.cpp
  4. 2
    0
      src/System.h

+ 47
- 7
src/SDLSystem.cpp View File

247
 
247
 
248
 	flags |= SDL_OPENGL;
248
 	flags |= SDL_OPENGL;
249
 
249
 
250
-	if (fullscreen)
250
+    mFullscreen = fullscreen;
251
+	if (mFullscreen)
251
 	{
252
 	{
252
 		flags |= SDL_FULLSCREEN;
253
 		flags |= SDL_FULLSCREEN;
253
         SDL_ShowCursor(SDL_DISABLE);
254
         SDL_ShowCursor(SDL_DISABLE);
278
 
279
 
279
 void SDLSystem::resize(unsigned int width, unsigned int height)
280
 void SDLSystem::resize(unsigned int width, unsigned int height)
280
 {
281
 {
282
+    int flags;
283
+
281
 	GLfloat aspect;
284
 	GLfloat aspect;
282
 
285
 
283
 
286
 
302
 	glLoadIdentity();
305
 	glLoadIdentity();
303
 
306
 
304
 	// Resize window
307
 	// Resize window
305
-	mWindow = SDL_SetVideoMode(width, height, 16, SDL_OPENGL);
308
+    flags = SDL_OPENGL;
309
+    if (mFullscreen)
310
+        flags |= SDL_FULLSCREEN;
311
+
312
+	mWindow = SDL_SetVideoMode(width, height, 16, flags);
306
 
313
 
307
 	// Resize context
314
 	// Resize context
308
 	resizeGL(width, height);
315
 	resizeGL(width, height);
491
 				{
498
 				{
492
 					if (event.type == SDL_KEYDOWN)
499
 					if (event.type == SDL_KEYDOWN)
493
 					{
500
 					{
494
-                        printf("Toggling console: %d!\n", mConsoleMode);
495
 						mConsoleMode = !mConsoleMode;
501
 						mConsoleMode = !mConsoleMode;
496
 						// Tmp hack
502
 						// Tmp hack
497
 						handleConsoleKeyPressEvent(mConsoleKey, 0);
503
 						handleConsoleKeyPressEvent(mConsoleKey, 0);
502
 					switch (event.type)
508
 					switch (event.type)
503
 					{
509
 					{
504
 					case SDL_KEYDOWN:
510
 					case SDL_KEYDOWN:
505
-                        printf("Console key press!\n");
506
 						handleConsoleKeyPressEvent(key, mod);
511
 						handleConsoleKeyPressEvent(key, mod);
507
 						break;
512
 						break;
508
 					default:
513
 					default:
514
 					//if (key < 255 && mKeyEvents[key] != 0)
519
 					//if (key < 255 && mKeyEvents[key] != 0)
515
 					key = mKeyEvents[key];
520
 					key = mKeyEvents[key];
516
 
521
 
517
-                    printf("Bound key press!\n");
518
 					switch (event.type)
522
 					switch (event.type)
519
 					{
523
 					{
520
 					case SDL_KEYDOWN:
524
 					case SDL_KEYDOWN:
526
 				}
530
 				}
527
 				else // 'Classic' key event handlers
531
 				else // 'Classic' key event handlers
528
 				{
532
 				{
529
-                    printf("Unbound key press!\n");
530
 					switch (event.type)
533
 					switch (event.type)
531
 					{
534
 					{
532
 					case SDL_KEYDOWN:
535
 					case SDL_KEYDOWN:
568
 {
571
 {
569
 	if (mWindow)
572
 	if (mWindow)
570
 	{
573
 	{
574
+        mFullscreen = !mFullscreen;
571
 		SDL_ShowCursor(SDL_DISABLE);
575
 		SDL_ShowCursor(SDL_DISABLE);
572
-		SDL_WM_ToggleFullScreen(mWindow);
576
+
577
+        // SDL_WM_ToggleFullScreen does not work on all platforms
578
+        // eg. Mac OS X
579
+		// SDL_WM_ToggleFullScreen(mWindow);
580
+
581
+        // I added a mFullscreen flag to this class. Then I modified it's
582
+        // resize() method to use the SDL_FULLSCREEN flag in the
583
+        // SetVideoMode() call based on the mFullscreen flag.
584
+        // Then, I modified this method to find out an available
585
+        // resolution for the fullscreen mode.
586
+        // Now you can see something when switching to Fullscreen,
587
+        // but it's full of graphical glitches...? I don't know...
588
+        // -- xythobuz 2013-12-31
589
+        int width, height;
590
+        if (mFullscreen) {
591
+            m_old_width = m_width;
592
+            m_old_height = m_height;
593
+            SDL_Rect **dimensions = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
594
+            if (dimensions == NULL) {
595
+                printf("Can't enter fullscreen!\n");
596
+                mFullscreen = !mFullscreen;
597
+            }
598
+            if (dimensions != (SDL_Rect **)-1) {
599
+                // TODO dont just use first available resolution...
600
+                width = dimensions[0]->w;
601
+                height = dimensions[0]->h;
602
+            } else {
603
+                // No restrictions, use current resolution
604
+                width = m_width;
605
+                height = m_height;
606
+            }
607
+        }
608
+        if (!mFullscreen) {
609
+            width = m_old_width;
610
+            height = m_old_height;
611
+        }
612
+        resize(width, height);
573
 	}
613
 	}
574
 }
614
 }
575
 
615
 

+ 3
- 0
src/SDLSystem.h View File

220
 	 * Mongoose - Created
220
 	 * Mongoose - Created
221
 	 ------------------------------------------------------*/
221
 	 ------------------------------------------------------*/
222
 
222
 
223
+ protected:
224
+    int m_old_width;
225
+    int m_old_height;
223
 
226
 
224
  private:
227
  private:
225
 
228
 

+ 2
- 0
src/System.cpp View File

78
 
78
 
79
 	mConsoleMode = false;
79
 	mConsoleMode = false;
80
 
80
 
81
+    mFullscreen = false;
82
+
81
 	printf("[System.Core]\n");
83
 	printf("[System.Core]\n");
82
 
84
 
83
 	// Hack for bad Map class, as well as reserved commands
85
 	// Hack for bad Map class, as well as reserved commands

+ 2
- 0
src/System.h View File

494
 
494
 
495
 	unsigned int mConsoleKey;	/* Console toggle event now handled lower */
495
 	unsigned int mConsoleKey;	/* Console toggle event now handled lower */
496
 
496
 
497
+    bool mFullscreen;
498
+
497
  private:
499
  private:
498
 
500
 
499
 	////////////////////////////////////////////////////////////
501
 	////////////////////////////////////////////////////////////

Loading…
Cancel
Save