mirror of https://github.com/raysan5/raylib
Moved viewport code into SetupViewport so high-DPI fix can be applied to EndTextureMode
This commit is contained in:
parent
17f09cb034
commit
06b8727d70
36
src/core.c
36
src/core.c
|
@ -264,6 +264,7 @@ static void SwapBuffers(void); // Copy back buffer to f
|
||||||
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
static void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
static void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
||||||
|
static void SetupViewport(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
@ -744,8 +745,7 @@ void EndTextureMode(void)
|
||||||
rlDisableRenderTexture(); // Disable render target
|
rlDisableRenderTexture(); // Disable render target
|
||||||
|
|
||||||
// Set viewport to default framebuffer size (screen size)
|
// Set viewport to default framebuffer size (screen size)
|
||||||
// TODO: consider possible viewport offsets
|
SetupViewport();
|
||||||
rlViewport(0, 0, GetScreenWidth(), GetScreenHeight());
|
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
||||||
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
||||||
|
@ -1776,19 +1776,8 @@ static void InitGraphicsDevice(int width, int height)
|
||||||
// NOTE: screenWidth and screenHeight not used, just stored as globals
|
// NOTE: screenWidth and screenHeight not used, just stored as globals
|
||||||
rlglInit(screenWidth, screenHeight);
|
rlglInit(screenWidth, screenHeight);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
// Setup default viewport
|
||||||
// Get framebuffer size of current window
|
SetupViewport();
|
||||||
// NOTE: Required to handle HighDPI display correctly on OSX because framebuffer
|
|
||||||
// is automatically reasized to adapt to new DPI.
|
|
||||||
// When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback()
|
|
||||||
int fbWidth, fbHeight;
|
|
||||||
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
|
|
||||||
rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY);
|
|
||||||
#else
|
|
||||||
// Initialize screen viewport (area of the screen that you will actually draw to)
|
|
||||||
// NOTE: Viewport must be recalculated if screen is resized
|
|
||||||
rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize internal projection and modelview matrices
|
// Initialize internal projection and modelview matrices
|
||||||
// NOTE: Default to orthographic projection mode with top-left corner at (0,0)
|
// NOTE: Default to orthographic projection mode with top-left corner at (0,0)
|
||||||
|
@ -1805,6 +1794,23 @@ static void InitGraphicsDevice(int width, int height)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetupViewport(void)
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Get framebuffer size of current window
|
||||||
|
// NOTE: Required to handle HighDPI display correctly on OSX because framebuffer
|
||||||
|
// is automatically reasized to adapt to new DPI.
|
||||||
|
// When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback()
|
||||||
|
int fbWidth, fbHeight;
|
||||||
|
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
|
||||||
|
rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY);
|
||||||
|
#else
|
||||||
|
// Initialize screen viewport (area of the screen that you will actually draw to)
|
||||||
|
// NOTE: Viewport must be recalculated if screen is resized
|
||||||
|
rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Compute framebuffer size relative to screen size and display size
|
// Compute framebuffer size relative to screen size and display size
|
||||||
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
||||||
static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
||||||
|
|
Loading…
Reference in New Issue