Skip to content
Merged
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
2 changes: 0 additions & 2 deletions src/Core/GameController.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ MA 02110-1301, USA.

- (void)windowDidResize:(NSNotification *)aNotification;

- (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize;

- (NSURL *) snapshotsURLCreatingIfNeeded:(BOOL)create;

@end
Expand Down
60 changes: 0 additions & 60 deletions src/Core/GameController.m
Original file line number Diff line number Diff line change
Expand Up @@ -970,66 +970,6 @@ - (void)reportUnhandledStartupException:(NSException *)exception
}


- (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize
{
OOOpenGLExtensionManager *extMgr = [OOOpenGLExtensionManager sharedManager];

float ratio = 0.5;
float aspect = viewSize.height/viewSize.width;

OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

OOGL(glClearDepth(1.0));
OOGL(glViewport(0, 0, viewSize.width, viewSize.height));

OOGLResetProjection(); // reset matrix
OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix

OOGL(glDepthFunc(GL_LESS)); // depth buffer

if (UNIVERSE)
{
[UNIVERSE setLighting];
}
else
{
GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};

OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, black));
OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, white));
OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, white));
OOGL(glLightfv(GL_LIGHT1, GL_POSITION, black));
OOGL(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient));

}

if ([extMgr usePointSmoothing]) OOGL(glEnable(GL_POINT_SMOOTH));
if ([extMgr useLineSmoothing]) OOGL(glEnable(GL_LINE_SMOOTH));

// world's simplest OpenGL optimisations...
#if GL_APPLE_transform_hint
if ([extMgr haveExtension:@"GL_APPLE_transform_hint"])
{
OOGL(glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST));
}
#endif

OOGL(glDisable(GL_NORMALIZE));
OOGL(glDisable(GL_RESCALE_NORMAL));

#if GL_VERSION_1_2
// For OpenGL 1.2 or later, we want GL_SEPARATE_SPECULAR_COLOR all the time.
if ([extMgr versionIsAtLeastMajor:1 minor:2])
{
OOGL(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
}
#endif
}


#ifndef NDEBUG
/* This method exists purely to suppress Clang static analyzer warnings that
these ivars are unused (but may be used by categories, which they are).
Expand Down
1 change: 0 additions & 1 deletion src/SDL/MyOpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ extern int debug;

int keycodetrans[255];

BOOL m_glContextInitialized;
NSPoint mouseDragStartPoint;

BOOL mouseWarped;
Expand Down
225 changes: 127 additions & 98 deletions src/SDL/MyOpenGLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ - (id) init

_mouseWheelDelta = 0.0f;

m_glContextInitialized = NO;

return self;
}

Expand Down Expand Up @@ -523,10 +521,131 @@ - (void) endSplashScreen
*/
}

[self initialiseGLWithSize:firstScreen];
[self updateScreen];
[self autoShowMouse];
}

- (void) updateGLSize:(NSSize) size
{
bounds.size = size;
viewSize = size;

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;
}

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);
}


- (void) setUpBasicOpenGLStateWithSize
{
OOOpenGLExtensionManager *extMgr = [OOOpenGLExtensionManager sharedManager];

OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
OOGL(glClearDepth(1.0));
OOGL(glDepthFunc(GL_LESS)); // depth buffer

if (UNIVERSE)
{
[UNIVERSE setLighting];
}
else
{
GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};

OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, black));
OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, white));
OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, white));
OOGL(glLightfv(GL_LIGHT1, GL_POSITION, black));
OOGL(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient));
}

if ([extMgr usePointSmoothing])
{
OOGL(glEnable(GL_POINT_SMOOTH));
}

if ([extMgr useLineSmoothing])
{
OOGL(glEnable(GL_LINE_SMOOTH));
}

OOGL(glDisable(GL_NORMALIZE));
OOGL(glDisable(GL_RESCALE_NORMAL));

OOGL(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
}


- (void) initialiseGLWithSize:(NSSize) v_size
{
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

SDL_SetWindowFullscreen(window, fullScreen);

if (!fullScreen)
{
SDL_SetWindowSize(window, viewSize.width, viewSize.height);
SDL_SetWindowBordered(window, YES);
}
#if OOLITE_WINDOWS
else // Hack for Windows SDL3 pause issue: https://github.com/libsdl-org/SDL/issues/12791
{ // Occurs on some systems eg. when going fullscreen -> window or vice versa
LONG currentWindowStyle = GetWindowLong(windowHandle, GWL_STYLE);
currentWindowStyle &= ~WS_POPUP;
SetWindowLong(windowHandle, GWL_STYLE, currentWindowStyle);
}
#endif

int pixelWidth, pixelHeight;
SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);

[self updateGLSize:NSMakeSize(pixelWidth, pixelHeight)];

OOLog(@"display.initGL",
@"Created a new surface of %d x %d, %@.",
(int)viewSize.width,
(int)viewSize.height,
(fullScreen ? @"fullscreen" : @"windowed"));

[self autoShowMouse];

[self setUpBasicOpenGLStateWithSize];

SDL_GL_SwapWindow(window);

squareX = 0.0f;
}


- (void) initKeyMappingData
{
Expand Down Expand Up @@ -766,34 +885,13 @@ - (NSSize) modeAsSize:(int)sizeIndex

- (void) updateScreen
{
SDL_SetWindowSize(window, (int)viewSize.width, (int)viewSize.height);
SDL_Surface* surface = SDL_GetWindowSurface(window);
int windowWidth, windowHeight;
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
if ((viewSize.width != windowWidth)||(viewSize.height != windowHeight)) // resized
{
viewSize.width = windowWidth;
viewSize.height = windowHeight;
}

if (m_glContextInitialized == NO)
{
[self initialiseGLWithSize:viewSize];
}

if (surface == 0)
return;

// do all the drawing!
//
if (UNIVERSE)
{
[UNIVERSE drawUniverse];
[UNIVERSE drawUniverse]; // do all the drawing!
}
else
{
// not set up yet, draw a black screen
glClearColor( 0.0, 0.0, 0.0, 0.0);
glClearColor( 0.0, 0.0, 0.0, 0.0); // not set up yet, draw a black screen
glClear( GL_COLOR_BUFFER_BIT);
}

Expand Down Expand Up @@ -1316,60 +1414,6 @@ - (void) setSDRToneMapper: (OOSDRToneMapper)newToneMapper
}


- (void) initialiseGLWithSize:(NSSize) v_size
{
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

SDL_SetWindowFullscreen(window, fullScreen);
if (!fullScreen)
{
SDL_SetWindowSize(window, viewSize.width, viewSize.height);
SDL_SetWindowBordered(window, YES);
}
#if OOLITE_WINDOWS
else // Hack for Windows SDL3 pause issue: https://github.com/libsdl-org/SDL/issues/12791
{ // Occurs on some systems eg. when going fullscreen -> window or vice versa
LONG currentWindowStyle = GetWindowLong(windowHandle, GWL_STYLE);
currentWindowStyle &= ~WS_POPUP;
SetWindowLong(windowHandle, GWL_STYLE, currentWindowStyle);
}
#endif
int w, h;
SDL_GetWindowSize(window, &w, &h);
bounds.size.width = w;
bounds.size.height = h;
viewSize = bounds.size;
OOLog(@"display.initGL", @"Created a new surface of %d x %d, %@.", (int)viewSize.width, (int)viewSize.height,(fullScreen ? @"fullscreen" : @"windowed"));

if (viewSize.width/viewSize.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;
}

[self autoShowMouse];

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

m_glContextInitialized = YES;
}


- (float) colorSaturation
{
return _colorSaturation;
Expand Down Expand Up @@ -2213,28 +2257,13 @@ reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call
{
_mouseWheelDelta = 0.0f;
}
if (resize_pending)
if (resize_pending)
{
int pixelWidth, pixelHeight; // Fetch actual pixel bounds back from SDL
int pixelWidth, pixelHeight;
// Fetch actual pixel bounds back from SDL
SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
bounds.size = NSMakeSize(pixelWidth, pixelHeight);
viewSize = bounds.size;

if (bounds.size.width / bounds.size.height > 4.0 / 3.0) { // Recalculate aspect-ratio-dependent
display_z = 480.0 * bounds.size.width / bounds.size.height; // projection offsets
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;
}

float ratio = 0.5; // Update OpenGL Viewport and Projection Matrix
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);
[self updateGLSize:NSMakeSize(pixelWidth, pixelHeight)];

if (!fullScreen)
{
Expand Down