mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-22 15:19:18 -05:00
REVIEWED: InitPlatform(), code simplification
This commit is contained in:
@ -1565,13 +1565,18 @@ int InitPlatform(void)
|
|||||||
CORE.Window.previousScreen.height = 450;
|
CORE.Window.previousScreen.height = 450;
|
||||||
CORE.Window.previousPosition.x = CORE.Window.display.width/2 - 800/2;
|
CORE.Window.previousPosition.x = CORE.Window.display.width/2 - 800/2;
|
||||||
CORE.Window.previousPosition.y = CORE.Window.display.height/2 - 450/2;
|
CORE.Window.previousPosition.y = CORE.Window.display.height/2 - 450/2;
|
||||||
|
|
||||||
|
// Set screen width/height to the display width/height
|
||||||
|
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||||
|
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CORE.Window.previousScreen = CORE.Window.screen;
|
||||||
|
CORE.Window.screen = CORE.Window.display;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set screen width/height to the display width/height
|
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
|
||||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
|
||||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
|
||||||
|
|
||||||
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
|
|
||||||
if (!platform.handle)
|
if (!platform.handle)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -1630,13 +1635,13 @@ int InitPlatform(void)
|
|||||||
|
|
||||||
glfwMakeContextCurrent(platform.handle);
|
glfwMakeContextCurrent(platform.handle);
|
||||||
result = glfwGetError(NULL);
|
result = glfwGetError(NULL);
|
||||||
|
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR)) CORE.Window.ready = true; // Checking context activation
|
||||||
|
|
||||||
// Check context activation
|
if (CORE.Window.ready)
|
||||||
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
|
|
||||||
{
|
{
|
||||||
CORE.Window.ready = true;
|
// Setup additional windows configs and register required window size info
|
||||||
|
|
||||||
glfwSwapInterval(0); // No V-Sync by default
|
glfwSwapInterval(0); // No V-Sync by default
|
||||||
|
|
||||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||||
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
||||||
@ -1677,25 +1682,13 @@ int InitPlatform(void)
|
|||||||
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
// Try to center window on screen but avoiding window-bar outside of screen
|
||||||
|
|
||||||
// If graphic device is no properly initialized, we end program
|
|
||||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int monitorCount = 0;
|
int monitorCount = 0;
|
||||||
int monitorIndex = GetCurrentMonitor();
|
int monitorIndex = GetCurrentMonitor();
|
||||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||||
GLFWmonitor *monitor = monitors[monitorIndex];
|
GLFWmonitor *monitor = monitors[monitorIndex];
|
||||||
|
|
||||||
// Try to center window on screen but avoiding window-bar outside of screen
|
|
||||||
int monitorX = 0;
|
int monitorX = 0;
|
||||||
int monitorY = 0;
|
int monitorY = 0;
|
||||||
int monitorWidth = 0;
|
int monitorWidth = 0;
|
||||||
@ -1704,15 +1697,19 @@ int InitPlatform(void)
|
|||||||
|
|
||||||
// TODO: Here CORE.Window.render.width/height should be used instead of
|
// TODO: Here CORE.Window.render.width/height should be used instead of
|
||||||
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
||||||
int posX = monitorX + (monitorWidth - (int)CORE.Window.render.width)/2;
|
CORE.Window.position.x = monitorX + (monitorWidth - (int)CORE.Window.screen.width)/2;
|
||||||
int posY = monitorY + (monitorHeight - (int)CORE.Window.render.height)/2;
|
CORE.Window.position.y = monitorY + (monitorHeight - (int)CORE.Window.screen.height)/2;
|
||||||
if (posX < monitorX) posX = monitorX;
|
//if (CORE.Window.position.x < monitorX) CORE.Window.position.x = monitorX;
|
||||||
if (posY < monitorY) posY = monitorY;
|
//if (CORE.Window.position.y < monitorY) CORE.Window.position.y = monitorY;
|
||||||
SetWindowPosition(posX, posY);
|
|
||||||
|
|
||||||
// Update CORE.Window.position here so it is correct from the start
|
SetWindowPosition(CORE.Window.position.x, CORE.Window.position.y);
|
||||||
CORE.Window.position.x = posX;
|
|
||||||
CORE.Window.position.y = posY;
|
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply window flags requested previous to initialization
|
// Apply window flags requested previous to initialization
|
||||||
|
|||||||
Reference in New Issue
Block a user