Skip to content

Commit bebf954

Browse files
authored
[CORE,RLGL] Fix scale issues when ending a mode (#3746)
* Only restore GL scale back to screen scale if we are returning to a screen, not a render texture. * blankspace * reset back to default screen scale when ending a render texture since we are back on the default fbo
1 parent 812645b commit bebf954

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/rcore.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,6 @@ void BeginMode2D(Camera2D camera)
952952

953953
// Apply 2d camera transformation to modelview
954954
rlMultMatrixf(MatrixToFloat(GetCameraMatrix2D(camera)));
955-
956-
// Apply screen scaling if required
957-
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale));
958955
}
959956

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

965962
rlLoadIdentity(); // Reset current matrix (modelview)
966-
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
963+
964+
if (rlGetActiveFramebuffer() == 0)
965+
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
967966
}
968967

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

1019-
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
1018+
if (rlGetActiveFramebuffer() == 0)
1019+
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
10201020

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

1065+
// go back to the modelview state from BeginDrawing since we are back to the default FBO
1066+
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
1067+
rlLoadIdentity(); // Reset current matrix (modelview)
1068+
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
1069+
10651070
// Reset current fbo to screen size
10661071
CORE.Window.currentFbo.width = CORE.Window.render.width;
10671072
CORE.Window.currentFbo.height = CORE.Window.render.height;

src/rlgl.h

+12
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ RLAPI void rlDisableShader(void); // Disable shader progra
621621
// Framebuffer state
622622
RLAPI void rlEnableFramebuffer(unsigned int id); // Enable render texture (fbo)
623623
RLAPI void rlDisableFramebuffer(void); // Disable render texture (fbo), return to default framebuffer
624+
RLAPI unsigned int rlGetActiveFramebuffer(void); // Returns the active render texture (fbo), 0 for default framebuffer
624625
RLAPI void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
625626
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
626627
RLAPI void rlBindFramebuffer(unsigned int target, unsigned int framebuffer); // Bind framebuffer (FBO)
@@ -1725,6 +1726,17 @@ void rlEnableFramebuffer(unsigned int id)
17251726
#endif
17261727
}
17271728

1729+
// return the active render texture (fbo)
1730+
unsigned int rlGetActiveFramebuffer(void)
1731+
{
1732+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES3)) && defined(RLGL_RENDER_TEXTURES_HINT)
1733+
GLint fboId = 0;
1734+
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fboId);
1735+
return fboId;
1736+
#endif
1737+
return 0;
1738+
}
1739+
17281740
// Disable rendering to texture
17291741
void rlDisableFramebuffer(void)
17301742
{

0 commit comments

Comments
 (0)