Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE,RLGL] Fix scale issues when ending a mode #3746

Merged
merged 3 commits into from
Jan 29, 2024
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
15 changes: 10 additions & 5 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,6 @@ void BeginMode2D(Camera2D camera)

// Apply 2d camera transformation to modelview
rlMultMatrixf(MatrixToFloat(GetCameraMatrix2D(camera)));

// Apply screen scaling if required
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale));
}

// Ends 2D mode with custom camera
Expand All @@ -963,7 +960,9 @@ void EndMode2D(void)
rlDrawRenderBatchActive(); // Update and draw internal render batch

rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required

if (rlGetActiveFramebuffer() == 0)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
}

// Initializes 3D mode with custom camera (3D)
Expand Down Expand Up @@ -1016,7 +1015,8 @@ void EndMode3D(void)
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview)

rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
if (rlGetActiveFramebuffer() == 0)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required

rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
}
Expand Down Expand Up @@ -1062,6 +1062,11 @@ void EndTextureMode(void)
// Set viewport to default framebuffer size
SetupViewport(CORE.Window.render.width, CORE.Window.render.height);

// go back to the modelview state from BeginDrawing since we are back to the default FBO
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required

// Reset current fbo to screen size
CORE.Window.currentFbo.width = CORE.Window.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height;
Expand Down
12 changes: 12 additions & 0 deletions src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ RLAPI void rlDisableShader(void); // Disable shader progra
// Framebuffer state
RLAPI void rlEnableFramebuffer(unsigned int id); // Enable render texture (fbo)
RLAPI void rlDisableFramebuffer(void); // Disable render texture (fbo), return to default framebuffer
RLAPI unsigned int rlGetActiveFramebuffer(void); // Returns the active render texture (fbo), 0 for default framebuffer
RLAPI void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
RLAPI void rlBlitFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int bufferMask); // Blit active framebuffer to main framebuffer
RLAPI void rlBindFramebuffer(unsigned int target, unsigned int framebuffer); // Bind framebuffer (FBO)
Expand Down Expand Up @@ -1725,6 +1726,17 @@ void rlEnableFramebuffer(unsigned int id)
#endif
}

// return the active render texture (fbo)
unsigned int rlGetActiveFramebuffer(void)
{
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES3)) && defined(RLGL_RENDER_TEXTURES_HINT)
GLint fboId = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fboId);
return fboId;
#endif
return 0;
}

// Disable rendering to texture
void rlDisableFramebuffer(void)
{
Expand Down
Loading