Skip to content

Commit

Permalink
Fix rendering issue after window resize raysan5#1982
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudValensi committed Sep 12, 2021
1 parent 024adc2 commit e3d126f
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,13 +1537,25 @@ void SetWindowSize(int width, int height)
// Get current screen width
int GetScreenWidth(void)
{
return CORE.Window.currentFbo.width;
return CORE.Window.screen.width;
}

// Get current screen height
int GetScreenHeight(void)
{
return CORE.Window.currentFbo.height;
return CORE.Window.screen.height;
}

// Get current render width which is equal to screen width * dpi scale
int GetRenderWidth(void)
{
return CORE.Window.render.width;
}

// Get current screen height which is equal to screen height * dpi scale
int GetRenderHeight(void)
{
return CORE.Window.render.height;
}

// Get native window handle
Expand Down Expand Up @@ -3820,16 +3832,6 @@ static bool InitGraphicsDevice(int width, int height)
TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
return false;
}
else
{
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
#if defined(PLATFORM_DESKTOP)
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
#endif
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
}

// Set window callback events
glfwSetWindowSizeCallback(CORE.Window.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default!
Expand Down Expand Up @@ -4273,12 +4275,8 @@ static bool InitGraphicsDevice(int width, int height)
rlLoadExtensions(eglGetProcAddress);
#endif

// Initialize OpenGL context (states and resources)
// NOTE: CORE.Window.screen.width and CORE.Window.screen.height not used, just stored as globals in rlgl
rlglInit(CORE.Window.screen.width, CORE.Window.screen.height);

int fbWidth = CORE.Window.render.width;
int fbHeight = CORE.Window.render.height;
int fbWidth = CORE.Window.screen.width;
int fbHeight = CORE.Window.screen.height;

#if defined(PLATFORM_DESKTOP)
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
Expand All @@ -4297,11 +4295,25 @@ static bool InitGraphicsDevice(int width, int height)
}
#endif

CORE.Window.currentFbo.width = fbWidth;
CORE.Window.currentFbo.height = fbHeight;
CORE.Window.render.width = CORE.Window.currentFbo.width;
CORE.Window.render.height = CORE.Window.currentFbo.height;

// Initialize OpenGL context (states and resources)
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);

// Setup default viewport
SetupViewport(fbWidth, fbHeight);

CORE.Window.currentFbo.width = CORE.Window.screen.width;
CORE.Window.currentFbo.height = CORE.Window.screen.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
#if defined(PLATFORM_DESKTOP)
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
#endif
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, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);

ClearBackground(RAYWHITE); // Default background color for raylib games :P

Expand Down Expand Up @@ -4865,10 +4877,17 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)

if (IsWindowFullscreen()) return;

Vector2 windowScaleDPI = GetWindowScaleDPI();

// Set current screen size
#if defined(__APPLE__)
CORE.Window.screen.width = width;
CORE.Window.screen.height = height;

#else
CORE.Window.screen.width = width / windowScaleDPI.x;
CORE.Window.screen.height = height / windowScaleDPI.y;
#endif

// NOTE: Postprocessing texture is not scaled to new size
}

Expand Down

0 comments on commit e3d126f

Please sign in to comment.