Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Core/GameController.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ - (void) beginSplashScreen
[gameView initSplashScreen];
}
#else
[gameView updateScreen];
[gameView updateScreenWithVideoMode:YES];
#endif
}

Expand Down Expand Up @@ -404,7 +404,7 @@ - (void) doPerformGameTick

@try
{
[gameView display];
[gameView updateScreenWithVideoMode:YES];
}
@catch (id exception) {}
}
Expand Down Expand Up @@ -902,7 +902,7 @@ - (void) exitAppCommandQ

- (void)windowDidResize:(NSNotification *)aNotification
{
[gameView updateScreen];
[gameView updateScreenWithVideoMode:YES];
}


Expand Down
94 changes: 52 additions & 42 deletions src/SDL/MyOpenGLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,15 @@ - (id) init
OOLog(@"display.mode.list", @"%@", @"CREATING MODE LIST");



m_glContextInitialized = NO;
#if OOLITE_WINDOWS
ShowWindow(windowHandle,SW_SHOWMINIMIZED);
updateContext = !showSplashScreen;
#endif
if (!showSplashScreen)
{
// blank the surface / go to fullscreen
[self createWindowWithSize: firstScreen];
[self initialiseGLWithSize: firstScreen];
}

Expand All @@ -476,8 +477,6 @@ - (id) init

_mouseWheelDelta = 0.0f;

m_glContextInitialized = NO;

return self;
}

Expand Down Expand Up @@ -528,7 +527,7 @@ - (void) endSplashScreen

#endif // OOLITE_LINUX

[self updateScreen];
[self updateScreenWithVideoMode:YES];
[self autoShowMouse];
}

Expand Down Expand Up @@ -784,32 +783,13 @@ - (NSSize) modeAsSize:(int)sizeIndex

#endif

- (void) display
{
[self updateScreen];
}

- (void) updateScreen
{
[self drawRect: NSMakeRect(0, 0, viewSize.width, viewSize.height)];
}

- (void) drawRect:(NSRect)rect
{
SDL_SetWindowSize(window, (int)NSWidth(rect), (int)NSHeight(rect));
[self updateScreenWithVideoMode:YES];
}

- (void) updateScreenWithVideoMode:(BOOL) v_mode
{
SDL_Surface* surface = SDL_GetWindowSurface(window);
int windowWidth, windowHeight;
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
SDL_GetWindowSizeInPixels(window, &windowWidth, &windowHeight);
if ((viewSize.width != windowWidth)||(viewSize.height != windowHeight)) // resized
{
#if OOLITE_LINUX
m_glContextInitialized = NO; //probably not needed
#endif
viewSize.width = windowWidth;
viewSize.height = windowHeight;
}
Expand Down Expand Up @@ -1456,13 +1436,9 @@ - (void) initialiseGLWithSize:(NSSize) v_size

- (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode
{
if (!window)
{
[self createWindowWithSize: v_size];
}
viewSize = v_size;
OOLog(@"display.initGL", @"Requested a new surface of %d x %d, %@.", (int)viewSize.width, (int)viewSize.height,(fullScreen ? @"fullscreen" : @"windowed"));
SDL_GL_SwapWindow(window); // clear the buffer before resize
int pixelWidth, pixelHeight;

#if OOLITE_WINDOWS
if (!updateContext) return;
Expand Down Expand Up @@ -1627,9 +1603,10 @@ - (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode
SDL_SetWindowBordered(window, v_mode);
SDL_SetWindowFullscreen(window, fullScreen);
SDL_SetWindowSize(window, viewSize.width, viewSize.height);
SDL_Surface *surface = SDL_GetWindowSurface(window);
bounds.size.width = surface->w;
bounds.size.height = surface->h;

SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
bounds.size.width = pixelWidth;
bounds.size.height = pixelHeight;

#endif
OOLog(@"display.initGL", @"Created a new surface of %d x %d, %@.", (int)viewSize.width, (int)viewSize.height,(fullScreen ? @"fullscreen" : @"windowed"));
Expand All @@ -1646,11 +1623,14 @@ - (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode

[self autoShowMouse];

int pixelWidth, pixelHeight;
#if OOLITE_WINDOWS
SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
#endif
NSSize pixelSize = NSMakeSize(pixelWidth, pixelHeight);
[[self gameController] setUpBasicOpenGLStateWithSize:pixelSize];
#if OOLITE_WINDOWS
SDL_GL_SwapWindow(window);
#endif
squareX = 0.0f;

m_glContextInitialized = YES;
Expand Down Expand Up @@ -2465,10 +2445,10 @@ reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call
}
break;

case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
{
SDL_WindowEvent *rsevt=(SDL_WindowEvent *)&event;
#if OOLITE_WINDOWS
SDL_WindowEvent *rsevt=(SDL_WindowEvent *)&event;
NSSize newSize=NSMakeSize(rsevt->data1, rsevt->data2);
if (!fullScreen && updateContext)
{
Expand All @@ -2482,18 +2462,19 @@ reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call
{
[self initialiseGLWithSize: newSize];
[self saveWindowSize: newSize];

}
}
#else
newSize=NSMakeSize(rsevt->data1, rsevt->data2);
resize_pending = true;
#endif
// certain gui screens will require an immediate redraw after
// certain gui screens will require an immediate redraw after
// a resize event - Nikos 20140129
if ([PlayerEntity sharedPlayer])
{
[[PlayerEntity sharedPlayer] doGuiScreenResizeUpdates];
}
#else
newSize = NSMakeSize(event.window.data1, event.window.data2);
resize_pending = true;
#endif
break;
}

Expand Down Expand Up @@ -2623,9 +2604,38 @@ reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call
#if OOLITE_LINUX
if (resize_pending)
{
[self initialiseGLWithSize: newSize];
[self saveWindowSize: newSize];
resize_pending = false;

// 1. Tell SDL to update the window dimensions
// SDL_SetWindowSize(window, newSize.width, newSize.height);

// 2. Fetch actual pixel bounds back from SDL
int pixelWidth, pixelHeight;
SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
bounds.size = NSMakeSize(pixelWidth, pixelHeight);
viewSize = bounds.size;

// 3. Recalculate aspect-ratio-dependent projection offsets
if (bounds.size.width / bounds.size.height > 4.0 / 3.0) {
display_z = 480.0 * bounds.size.width / bounds.size.height;
x_offset = 240.0 * bounds.size.width / bounds.size.height;
y_offset = 240.0;
} else {
display_z = 640.0;
x_offset = 320.0;
y_offset = 320.0 * bounds.size.height / bounds.size.width;
}

// 4. Update OpenGL Viewport and Projection Matrix
float ratio = 0.5;
float aspect = bounds.size.height / bounds.size.width;

OOGL(glViewport(0, 0, bounds.size.width, bounds.size.height));
OOGLResetProjection();
OOGLFrustum(-ratio, ratio, -aspect * ratio, aspect * ratio, 1.0, MAX_CLEAR_DEPTH);

// 5. Save the updated window size
[self saveWindowSize: newSize];
}
#endif
}
Expand Down
Loading