From 4b0e25d3af79ce4c5cd94e8279473764d969cca3 Mon Sep 17 00:00:00 2001 From: KotzaBoss Date: Tue, 23 Apr 2024 14:24:37 +0200 Subject: [PATCH 01/19] Add rlCullDistance variables/getters and rlSetClipPlanes function (#3912) The `RL_CULL_DISTANCE_` definition remains as the initial value of the variables. Basic usage can be: ```c #include #include rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, MY_CULL_DISTANCE_FAR); if (must_reset_clip_planes) rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); ``` --- examples/models/models_skybox.c | 2 +- src/rcore.c | 14 +++++++------- src/rlgl.h | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 1b8aad9a9..e0e08f3a1 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -208,7 +208,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s rlEnableShader(shader.id); // Define projection matrix and send it to shader - Matrix matFboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + Matrix matFboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, rlGetCullDistanceNear(), rlGetCullDistanceFar()); rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_PROJECTION], matFboProjection); // Define view matrix for every side of the cubemap diff --git a/src/rcore.c b/src/rcore.c index a68067fe8..29885c397 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -992,10 +992,10 @@ void BeginMode3D(Camera camera) if (camera.projection == CAMERA_PERSPECTIVE) { // Setup perspective projection - double top = RL_CULL_DISTANCE_NEAR*tan(camera.fovy*0.5*DEG2RAD); + double top = rlGetCullDistanceNear()*tan(camera.fovy*0.5*DEG2RAD); double right = top*aspect; - rlFrustum(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + rlFrustum(-right, right, -top, top, rlGetCullDistanceNear(), rlGetCullDistanceFar()); } else if (camera.projection == CAMERA_ORTHOGRAPHIC) { @@ -1003,7 +1003,7 @@ void BeginMode3D(Camera camera) double top = camera.fovy/2.0; double right = top*aspect; - rlOrtho(-right, right, -top,top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + rlOrtho(-right, right, -top,top, rlGetCullDistanceNear(), rlGetCullDistanceFar()); } rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix @@ -1207,7 +1207,7 @@ VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device) // Compute camera projection matrices float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1] - Matrix proj = MatrixPerspective(fovy, aspect, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + Matrix proj = MatrixPerspective(fovy, aspect, rlGetCullDistanceNear(), rlGetCullDistanceFar()); config.projection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f)); config.projection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f)); @@ -1446,7 +1446,7 @@ Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height if (camera.projection == CAMERA_PERSPECTIVE) { // Calculate projection matrix from perspective - matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), rlGetCullDistanceNear(), rlGetCullDistanceFar()); } else if (camera.projection == CAMERA_ORTHOGRAPHIC) { @@ -1533,7 +1533,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh if (camera.projection == CAMERA_PERSPECTIVE) { // Calculate projection matrix from perspective - matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), rlGetCullDistanceNear(), rlGetCullDistanceFar()); } else if (camera.projection == CAMERA_ORTHOGRAPHIC) { @@ -1542,7 +1542,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh double right = top*aspect; // Calculate projection matrix from orthographic - matProj = MatrixOrtho(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + matProj = MatrixOrtho(-right, right, -top, top, rlGetCullDistanceNear(), rlGetCullDistanceFar()); } // Calculate view matrix from camera look at (and transpose it) diff --git a/src/rlgl.h b/src/rlgl.h index 1787d97a8..137dcd20f 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -559,6 +559,10 @@ typedef enum { extern "C" { // Prevents name mangling of functions #endif +RLAPI void rlSetClipPlanes(double near, double far); +RLAPI double rlGetCullDistanceNear(); +RLAPI double rlGetCullDistanceFar(); + RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed RLAPI void rlPushMatrix(void); // Push the current matrix to stack RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack @@ -1083,6 +1087,10 @@ typedef void *(*rlglLoadProc)(const char *name); // OpenGL extension functions //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- + +static double rlCullDistanceNear = RL_CULL_DISTANCE_NEAR; +static double rlCullDistanceFar = RL_CULL_DISTANCE_FAR; + #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) static rlglData RLGL = { 0 }; #endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 @@ -1127,6 +1135,22 @@ static Matrix rlMatrixInvert(Matrix mat); // Invert provided m // Module Functions Definition - Matrix operations //---------------------------------------------------------------------------------- +void rlSetClipPlanes(double near, double far) +{ + rlCullDistanceNear = near; + rlCullDistanceFar = far; +} + +double rlGetCullDistanceFar() +{ + return rlCullDistanceFar; +} + +double rlGetCullDistanceNear() +{ + return rlCullDistanceNear; +} + #if defined(GRAPHICS_API_OPENGL_11) // Fallback to OpenGL 1.1 function calls //--------------------------------------- From f15455552da353dfb7055b6fa020ba73d71de88e Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 23 Apr 2024 19:38:45 +0200 Subject: [PATCH 02/19] Review formatting --- src/rlgl.h | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 137dcd20f..9477558c8 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -559,10 +559,6 @@ typedef enum { extern "C" { // Prevents name mangling of functions #endif -RLAPI void rlSetClipPlanes(double near, double far); -RLAPI double rlGetCullDistanceNear(); -RLAPI double rlGetCullDistanceFar(); - RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed RLAPI void rlPushMatrix(void); // Push the current matrix to stack RLAPI void rlPopMatrix(void); // Pop latest inserted matrix from stack @@ -574,6 +570,9 @@ RLAPI void rlMultMatrixf(const float *matf); // Multiply the current RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar); RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area +RLAPI void rlSetClipPlanes(double near, double far); // Set clip planes distances +RLAPI double rlGetCullDistanceNear(); // Get cull plane distance near +RLAPI double rlGetCullDistanceFar(); // Get cull plane distance far //------------------------------------------------------------------------------------ // Functions Declaration - Vertex level operations @@ -1087,7 +1086,6 @@ typedef void *(*rlglLoadProc)(const char *name); // OpenGL extension functions //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- - static double rlCullDistanceNear = RL_CULL_DISTANCE_NEAR; static double rlCullDistanceFar = RL_CULL_DISTANCE_FAR; @@ -1135,22 +1133,6 @@ static Matrix rlMatrixInvert(Matrix mat); // Invert provided m // Module Functions Definition - Matrix operations //---------------------------------------------------------------------------------- -void rlSetClipPlanes(double near, double far) -{ - rlCullDistanceNear = near; - rlCullDistanceFar = far; -} - -double rlGetCullDistanceFar() -{ - return rlCullDistanceFar; -} - -double rlGetCullDistanceNear() -{ - return rlCullDistanceNear; -} - #if defined(GRAPHICS_API_OPENGL_11) // Fallback to OpenGL 1.1 function calls //--------------------------------------- @@ -1388,6 +1370,25 @@ void rlViewport(int x, int y, int width, int height) glViewport(x, y, width, height); } +// Set clip planes distances +void rlSetClipPlanes(double near, double far) +{ + rlCullDistanceNear = near; + rlCullDistanceFar = far; +} + +// Get cull plane distance near +double rlGetCullDistanceNear(void) +{ + return rlCullDistanceNear; +} + +// Get cull plane distance far +double rlGetCullDistanceFar(void) +{ + return rlCullDistanceFar; +} + //---------------------------------------------------------------------------------- // Module Functions Definition - Vertex level operations //---------------------------------------------------------------------------------- From 2e774432090db1be697d2e4e5f49ea91ca038cd3 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 23 Apr 2024 22:55:51 +0200 Subject: [PATCH 03/19] WARNING: Fix breaking issue (introduced some days ago) --- src/rcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index 29885c397..b229589f7 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1964,7 +1964,7 @@ const char *GetFileName(const char *filePath) if (filePath != NULL) fileName = strprbrk(filePath, "\\/"); - if (fileName != NULL) return filePath; + if (fileName == NULL) return filePath; return fileName + 1; } From e47ebec66134800e734710038ea4e5f070f3ef06 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 24 Apr 2024 17:02:03 +0200 Subject: [PATCH 04/19] FIX: Issue with texcoords loading for glTF --- src/rmodels.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 293aee9b1..5efc32283 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -5121,14 +5121,6 @@ static Model LoadGLTF(const char *fileName) { // Support up to 2 texture coordinates attributes float *texcoordPtr = NULL; - int index = data->meshes[i].primitives[p].attributes[j].index; - if (index == 0) texcoordPtr = model.meshes[meshIndex].texcoords; - else if (index == 1) texcoordPtr = model.meshes[meshIndex].texcoords2; - else - { - TRACELOG(LOG_WARNING, "MODEL: [%s] No more than 2 texture coordinates attributes supported", fileName); - continue; - } cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data; @@ -5137,7 +5129,7 @@ static Model LoadGLTF(const char *fileName) if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float { // Init raylib mesh texcoords to copy glTF attribute data - texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); + texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float)); // Load 3 components of float data type into mesh.texcoords LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr) @@ -5145,10 +5137,10 @@ static Model LoadGLTF(const char *fileName) else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n { // Init raylib mesh texcoords to copy glTF attribute data - texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); + texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float)); // Load data into a temp buffer to be converted to raylib data type - unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned char)); + unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*2*sizeof(unsigned char)); LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp); // Convert data to raylib texcoord data type (float) @@ -5159,10 +5151,10 @@ static Model LoadGLTF(const char *fileName) else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n { // Init raylib mesh texcoords to copy glTF attribute data - texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); + texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float)); // Load data into a temp buffer to be converted to raylib data type - unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned short)); + unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*2*sizeof(unsigned short)); LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp); // Convert data to raylib texcoord data type (float) @@ -5173,6 +5165,15 @@ static Model LoadGLTF(const char *fileName) else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported", fileName); } else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported, use vec2 float", fileName); + + int index = data->meshes[i].primitives[p].attributes[j].index; + if (index == 0) model.meshes[meshIndex].texcoords = texcoordPtr; + else if (index == 1) model.meshes[meshIndex].texcoords2 = texcoordPtr; + else + { + TRACELOG(LOG_WARNING, "MODEL: [%s] No more than 2 texture coordinates attributes supported", fileName); + if (texcoordPtr != NULL) RL_FREE(texcoordPtr); + } } else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_color) // COLOR_n, vec3/vec4, float/u8n/u16n { From 10e702facd84f7558947b4d6780f1b758405ab13 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi <65001595+lima-limon-inc@users.noreply.github.com> Date: Sun, 28 Apr 2024 15:28:19 -0300 Subject: [PATCH 05/19] FIX: Added CAMERA_CUSTOM check in `UpdateCamera(Camera *camera, int mode)` (#3938) Signed-off-by: Tomas Fabrizio Orsi --- src/rcamera.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rcamera.h b/src/rcamera.h index 8e513ef1c..9c19556c4 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -444,7 +444,8 @@ void UpdateCamera(Camera *camera, int mode) bool lockView = ((mode == CAMERA_FREE) || (mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL)); bool rotateUp = false; - if (mode == CAMERA_ORBITAL) + if (mode == CAMERA_CUSTOM) {} + else if (mode == CAMERA_ORBITAL) { // Orbital can just orbit Matrix rotation = MatrixRotate(GetCameraUp(camera), CAMERA_ORBITAL_SPEED*GetFrameTime()); From f78721991f735a11b2d47faa014748f0f19d0883 Mon Sep 17 00:00:00 2001 From: OetkenPurveyorOfCode Date: Sun, 28 Apr 2024 20:29:45 +0200 Subject: [PATCH 06/19] Use builtin_clz for clang on windows (#3939) --- src/external/sinfl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/external/sinfl.h b/src/external/sinfl.h index 1f6bf6f02..3c7173777 100644 --- a/src/external/sinfl.h +++ b/src/external/sinfl.h @@ -171,7 +171,7 @@ extern int zsinflate(void *out, int cap, const void *in, int size); static int sinfl_bsr(unsigned n) { -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) _BitScanReverse(&n, n); return n; #elif defined(__GNUC__) || defined(__clang__) From 80d318461f297c039e3edb5da80a7beee67fc979 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi <65001595+lima-limon-inc@users.noreply.github.com> Date: Sun, 28 Apr 2024 17:39:28 -0300 Subject: [PATCH 07/19] Made comments on raylib.h match those present in rcamera.h (#3942) Signed-off-by: Tomas Fabrizio Orsi --- src/raylib.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index b9463228b..2fa60a058 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -913,11 +913,11 @@ typedef enum { // Camera system modes typedef enum { - CAMERA_CUSTOM = 0, // Custom camera - CAMERA_FREE, // Free camera - CAMERA_ORBITAL, // Orbital camera - CAMERA_FIRST_PERSON, // First person camera - CAMERA_THIRD_PERSON // Third person camera + CAMERA_CUSTOM = 0, // Camera custom, controlled by user (UpdateCamera() does nothing) + CAMERA_FREE, // Camera free mode + CAMERA_ORBITAL, // Camera orbital, around target, zoom supported + CAMERA_FIRST_PERSON, // Camera first person + CAMERA_THIRD_PERSON // Camera third person } CameraMode; // Camera projection From 915dd95d88cb9fe7b47d3d48e61ffcc7bfafce40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 28 Apr 2024 20:39:44 +0000 Subject: [PATCH 08/19] Update raylib_api.* by CI --- parser/output/raylib_api.json | 10 +++++----- parser/output/raylib_api.lua | 10 +++++----- parser/output/raylib_api.xml | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/parser/output/raylib_api.json b/parser/output/raylib_api.json index c7caabfac..d81014e05 100644 --- a/parser/output/raylib_api.json +++ b/parser/output/raylib_api.json @@ -2957,27 +2957,27 @@ { "name": "CAMERA_CUSTOM", "value": 0, - "description": "Custom camera" + "description": "Camera custom, controlled by user (UpdateCamera() does nothing)" }, { "name": "CAMERA_FREE", "value": 1, - "description": "Free camera" + "description": "Camera free mode" }, { "name": "CAMERA_ORBITAL", "value": 2, - "description": "Orbital camera" + "description": "Camera orbital, around target, zoom supported" }, { "name": "CAMERA_FIRST_PERSON", "value": 3, - "description": "First person camera" + "description": "Camera first person" }, { "name": "CAMERA_THIRD_PERSON", "value": 4, - "description": "Third person camera" + "description": "Camera third person" } ] }, diff --git a/parser/output/raylib_api.lua b/parser/output/raylib_api.lua index 607904bbc..105a20bbb 100644 --- a/parser/output/raylib_api.lua +++ b/parser/output/raylib_api.lua @@ -2957,27 +2957,27 @@ return { { name = "CAMERA_CUSTOM", value = 0, - description = "Custom camera" + description = "Camera custom, controlled by user (UpdateCamera() does nothing)" }, { name = "CAMERA_FREE", value = 1, - description = "Free camera" + description = "Camera free mode" }, { name = "CAMERA_ORBITAL", value = 2, - description = "Orbital camera" + description = "Camera orbital, around target, zoom supported" }, { name = "CAMERA_FIRST_PERSON", value = 3, - description = "First person camera" + description = "Camera first person" }, { name = "CAMERA_THIRD_PERSON", value = 4, - description = "Third person camera" + description = "Camera third person" } } }, diff --git a/parser/output/raylib_api.xml b/parser/output/raylib_api.xml index 8183d5cf8..37786d2cf 100644 --- a/parser/output/raylib_api.xml +++ b/parser/output/raylib_api.xml @@ -627,11 +627,11 @@ - - - - - + + + + + From e0027eb767031bdf8f4fb688b6bf5a977c250c05 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 28 Apr 2024 22:59:35 +0200 Subject: [PATCH 09/19] REVIEWED: `DrawLine()` to avoid pixel rounding issues #3931 --- src/rshapes.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rshapes.c b/src/rshapes.c index 902019599..f13f4b019 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -178,8 +178,9 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f((float)startPosX, (float)startPosY); - rlVertex2f((float)endPosX, (float)endPosY); + // WARNING: Adding 0.5f offset to "center" point on selected pixel + rlVertex2f((float)startPosX + 0.5f, (float)startPosY + 0.5f); + rlVertex2f((float)endPosX + 0.5f, (float)endPosY + 0.5f); rlEnd(); } @@ -188,8 +189,9 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color) { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(startPos.x, startPos.y); - rlVertex2f(endPos.x, endPos.y); + // WARNING: Adding 0.5f offset to "center" point on selected pixel + rlVertex2f(startPos.x + 0.5f, startPos.y + 0.5f); + rlVertex2f(endPos.x + 0.5f, endPos.y + 0.5f); rlEnd(); } From b03c8ba945a06ed1ec3d6ed7c3185e1264909323 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 28 Apr 2024 23:07:21 +0200 Subject: [PATCH 10/19] WARNING: BREAKING: REDESIGN: `SetTextLineSpacing()` Redesigned function to only consider separation between the end of vertical size of one line and the beginning of next line --- examples/text/text_codepoints_loading.c | 2 +- examples/text/text_font_loading.c | 2 +- src/rtext.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/text/text_codepoints_loading.c b/examples/text/text_codepoints_loading.c index c69803c12..95a81dfc3 100644 --- a/examples/text/text_codepoints_loading.c +++ b/examples/text/text_codepoints_loading.c @@ -52,7 +52,7 @@ int main(void) // Set bilinear scale filter for better font scaling SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR); - SetTextLineSpacing(54); // Set line spacing for multiline text (when line breaks are included '\n') + SetTextLineSpacing(20); // Set line spacing for multiline text (when line breaks are included '\n') // Free codepoints, atlas has already been generated free(codepointsNoDups); diff --git a/examples/text/text_font_loading.c b/examples/text/text_font_loading.c index 2c8786c42..6b98a4e8a 100644 --- a/examples/text/text_font_loading.c +++ b/examples/text/text_font_loading.c @@ -47,7 +47,7 @@ int main(void) // NOTE: We define a font base size of 32 pixels tall and up-to 250 characters Font fontTtf = LoadFontEx("resources/pixantiqua.ttf", 32, 0, 250); - SetTextLineSpacing(48); // Set line spacing for multiline text (when line breaks are included '\n') + SetTextLineSpacing(16); // Set line spacing for multiline text (when line breaks are included '\n') bool useTtf = false; diff --git a/src/rtext.c b/src/rtext.c index 47f3e062a..3544ff8da 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -144,7 +144,7 @@ static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode #if defined(SUPPORT_FILEFORMAT_BDF) static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, int *codepoints, int codepointCount, int *outFontSize); #endif -static int textLineSpacing = 15; // Text vertical line spacing in pixels +static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines) #if defined(SUPPORT_DEFAULT_FONT) extern void LoadFontDefault(void); @@ -1166,7 +1166,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f if (codepoint == '\n') { // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup - textOffsetY += textLineSpacing; + textOffsetY += (fontSize + textLineSpacing); textOffsetX = 0.0f; } else @@ -1237,7 +1237,7 @@ void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Ve if (codepoints[i] == '\n') { // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup - textOffsetY += textLineSpacing; + textOffsetY += (fontSize + textLineSpacing); textOffsetX = 0.0f; } else @@ -1319,7 +1319,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing textWidth = 0; // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup - textHeight += (float)textLineSpacing; + textHeight += (fontSize + textLineSpacing); } if (tempByteCounter < byteCounter) tempByteCounter = byteCounter; From 7246d798adeac4e0d8713cfdaf89fb9a19f71d69 Mon Sep 17 00:00:00 2001 From: UmgefallenesGlas <108078099+UmgefallenesGlas@users.noreply.github.com> Date: Tue, 30 Apr 2024 23:47:11 +0200 Subject: [PATCH 11/19] Changed one minor Comment (#3949) --- src/raylib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raylib.h b/src/raylib.h index 2fa60a058..035f6f2bf 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -726,7 +726,7 @@ typedef enum { GAMEPAD_BUTTON_RIGHT_FACE_LEFT, // Gamepad right button left (i.e. PS3: Square, Xbox: X) GAMEPAD_BUTTON_LEFT_TRIGGER_1, // Gamepad top/back trigger left (first), it could be a trailing button GAMEPAD_BUTTON_LEFT_TRIGGER_2, // Gamepad top/back trigger left (second), it could be a trailing button - GAMEPAD_BUTTON_RIGHT_TRIGGER_1, // Gamepad top/back trigger right (one), it could be a trailing button + GAMEPAD_BUTTON_RIGHT_TRIGGER_1, // Gamepad top/back trigger right (first), it could be a trailing button GAMEPAD_BUTTON_RIGHT_TRIGGER_2, // Gamepad top/back trigger right (second), it could be a trailing button GAMEPAD_BUTTON_MIDDLE_LEFT, // Gamepad center buttons, left one (i.e. PS3: Select) GAMEPAD_BUTTON_MIDDLE, // Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX) From 27a015d022ecdf771ea64b23f495a3b66101e170 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Apr 2024 21:47:28 +0000 Subject: [PATCH 12/19] Update raylib_api.* by CI --- parser/output/raylib_api.json | 2 +- parser/output/raylib_api.lua | 2 +- parser/output/raylib_api.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parser/output/raylib_api.json b/parser/output/raylib_api.json index d81014e05..d50085a4a 100644 --- a/parser/output/raylib_api.json +++ b/parser/output/raylib_api.json @@ -2254,7 +2254,7 @@ { "name": "GAMEPAD_BUTTON_RIGHT_TRIGGER_1", "value": 11, - "description": "Gamepad top/back trigger right (one), it could be a trailing button" + "description": "Gamepad top/back trigger right (first), it could be a trailing button" }, { "name": "GAMEPAD_BUTTON_RIGHT_TRIGGER_2", diff --git a/parser/output/raylib_api.lua b/parser/output/raylib_api.lua index 105a20bbb..ef8e1c51e 100644 --- a/parser/output/raylib_api.lua +++ b/parser/output/raylib_api.lua @@ -2254,7 +2254,7 @@ return { { name = "GAMEPAD_BUTTON_RIGHT_TRIGGER_1", value = 11, - description = "Gamepad top/back trigger right (one), it could be a trailing button" + description = "Gamepad top/back trigger right (first), it could be a trailing button" }, { name = "GAMEPAD_BUTTON_RIGHT_TRIGGER_2", diff --git a/parser/output/raylib_api.xml b/parser/output/raylib_api.xml index 37786d2cf..e17c59d09 100644 --- a/parser/output/raylib_api.xml +++ b/parser/output/raylib_api.xml @@ -476,7 +476,7 @@ - + From 763129e96b0ae8a795f62d40d1b75736e4e6ae46 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 May 2024 18:12:57 +0200 Subject: [PATCH 13/19] Reviewed some warnings --- src/rmodels.c | 2 +- src/rshapes.c | 16 ++++++++-------- src/rtext.c | 4 ++-- src/rtextures.c | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 5efc32283..27c19a3c7 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -5549,7 +5549,7 @@ static bool GetPoseAtTimeGLTF(cgltf_interpolation_type interpolationType, cgltf_ } } - float duration = fmax((tend - tstart), EPSILON); + float duration = fmaxf((tend - tstart), EPSILON); float t = (time - tstart)/duration; t = (t < 0.0f)? 0.0f : t; t = (t > 1.0f)? 1.0f : t; diff --git a/src/rshapes.c b/src/rshapes.c index f13f4b019..80df64e2d 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -815,17 +815,17 @@ void DrawRectangleLines(int posX, int posY, int width, int height, Color color) { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(posX, posY); - rlVertex2f(posX + width, posY + 1); + rlVertex2f((float)posX, (float)posY); + rlVertex2f((float)posX + (float)width, (float)posY + 1); - rlVertex2f(posX + width, posY + 1); - rlVertex2f(posX + width, posY + height); + rlVertex2f((float)posX + (float)width, (float)posY + 1); + rlVertex2f((float)posX + (float)width, (float)posY + (float)height); - rlVertex2f(posX + width, posY + height); - rlVertex2f(posX + 1, posY + height); + rlVertex2f((float)posX + (float)width, (float)posY + (float)height); + rlVertex2f((float)posX + 1, (float)posY + (float)height); - rlVertex2f(posX + 1, posY + height); - rlVertex2f(posX + 1, posY + 1); + rlVertex2f((float)posX + 1, (float)posY + (float)height); + rlVertex2f((float)posX + 1, (float)posY + 1); rlEnd(); } diff --git a/src/rtext.c b/src/rtext.c index 3544ff8da..b5ba17e3a 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1151,7 +1151,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f int size = TextLength(text); // Total size in bytes of the text, scanned by codepoints in loop - int textOffsetY = 0; // Offset between lines (on linebreak '\n') + float textOffsetY = 0; // Offset between lines (on linebreak '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor @@ -1225,7 +1225,7 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz // Draw multiple character (codepoints) void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Vector2 position, float fontSize, float spacing, Color tint) { - int textOffsetY = 0; // Offset between lines (on linebreak '\n') + float textOffsetY = 0; // Offset between lines (on linebreak '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor diff --git a/src/rtextures.c b/src/rtextures.c index 0658a6807..47ff83f5c 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -314,7 +314,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int if (fileData != NULL) { unsigned char *dataPtr = fileData; - unsigned int size = GetPixelDataSize(width, height, format); + int size = GetPixelDataSize(width, height, format); if (size <= dataSize) // Security check { @@ -697,8 +697,8 @@ Image LoadImageFromScreen(void) Vector2 scale = GetWindowScaleDPI(); Image image = { 0 }; - image.width = GetScreenWidth()*scale.x; - image.height = GetScreenHeight()*scale.y; + image.width = (int)(GetScreenWidth()*scale.x); + image.height = (int)(GetScreenHeight()*scale.y); image.mipmaps = 1; image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; image.data = rlReadScreenPixels(image.width, image.height); From c21edadab0e24d9340508329b454abe05227cdec Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 May 2024 18:39:38 +0200 Subject: [PATCH 14/19] Update rprand.h --- src/external/rprand.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/external/rprand.h b/src/external/rprand.h index 7e27d980f..8d77bf757 100644 --- a/src/external/rprand.h +++ b/src/external/rprand.h @@ -202,7 +202,7 @@ int *rprand_load_sequence(unsigned int count, int min, int max) { value = ((unsigned int)rprand_xoshiro()%(abs(max - min) + 1)) + min; - for (int j = 0; j < i; j++) + for (unsigned int j = 0; j < i; j++) { if (sequence[j] == value) { From 33b32ca53a7817a9cfdb1840a8ab75fa7cb47723 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 May 2024 18:41:28 +0200 Subject: [PATCH 15/19] Default shader attrib locations need to be exposed They need to be exposed on `rlgl.h` header section (not implementation section) because with some specific use cases (custom config.h, rmodels module enabled), building fails otherwise. --- src/rlgl.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 9477558c8..ae53b4efb 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -322,6 +322,26 @@ #define RL_READ_FRAMEBUFFER 0x8CA8 // GL_READ_FRAMEBUFFER #define RL_DRAW_FRAMEBUFFER 0x8CA9 // GL_DRAW_FRAMEBUFFER +// Default shader vertex attribute locations +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0 +#endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD 1 +#endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL 2 +#endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3 +#endif + #ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT +#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4 +#endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5 +#endif + //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- @@ -934,26 +954,6 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad #endif #endif -// Default shader vertex attribute locations -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0 -#endif -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD 1 -#endif -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL 2 -#endif -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3 -#endif -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4 -#endif -#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 - #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5 -#endif - // Default shader vertex attribute names to set location points #ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION From f1007554a0a8145060797c0aa8169bdaf2c1c6b8 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 May 2024 22:58:33 +0200 Subject: [PATCH 16/19] Set default init values for random #3954 --- src/external/rprand.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/external/rprand.h b/src/external/rprand.h index 8d77bf757..ded6708e5 100644 --- a/src/external/rprand.h +++ b/src/external/rprand.h @@ -147,8 +147,13 @@ RPRANDAPI void rprand_unload_sequence(int *sequence); // Unload pseudo //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -static uint64_t rprand_seed = 0; // SplitMix64 actual seed -static uint32_t rprand_state[4] = { 0 }; // Xoshiro128** state, nitialized by SplitMix64 +static uint64_t rprand_seed = 0xAABBCCDD; // SplitMix64 default seed (aligned to rprand_state) +static uint32_t rprand_state[4] = { // Xoshiro128** state, initialized by SplitMix64 + 0x96ea83c1, + 0x218b21e5, + 0xaa91febd, + 0x976414d4 +}; //---------------------------------------------------------------------------------- // Module internal functions declaration From 34d00d52177230cb3434240c263a0529aa0b4891 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 5 May 2024 19:46:31 +0200 Subject: [PATCH 17/19] Minor formatting tweaks --- .../resources/shaders/glsl100/palette_switch.fs | 16 +++++++++------- .../resources/shaders/glsl330/palette_switch.fs | 13 ++++++++----- src/external/rl_gputex.h | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/shaders/resources/shaders/glsl100/palette_switch.fs b/examples/shaders/resources/shaders/glsl100/palette_switch.fs index 25b496321..d8d696d4f 100644 --- a/examples/shaders/resources/shaders/glsl100/palette_switch.fs +++ b/examples/shaders/resources/shaders/glsl100/palette_switch.fs @@ -2,7 +2,7 @@ precision mediump float; -const int colors = 8; +const int MAX_INDEXED_COLORS = 8; // Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; @@ -10,7 +10,8 @@ varying vec4 fragColor; // Input uniform values uniform sampler2D texture0; -uniform ivec3 palette[colors]; +uniform ivec3 palette[MAX_INDEXED_COLORS]; +//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture void main() { @@ -18,13 +19,13 @@ void main() vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor; // Convert the (normalized) texel color RED component (GB would work, too) - // to the palette index by scaling up from [0, 1] to [0, 255]. + // to the palette index by scaling up from [0..1] to [0..255] int index = int(texelColor.r*255.0); - + ivec3 color = ivec3(0); // NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value, - // a constantmust be used, so this logic... + // a constant must be used, so this logic... if (index == 0) color = palette[0]; else if (index == 1) color = palette[1]; else if (index == 2) color = palette[2]; @@ -33,9 +34,10 @@ void main() else if (index == 5) color = palette[5]; else if (index == 6) color = palette[6]; else if (index == 7) color = palette[7]; + + //gl_FragColor = texture2D(palette, texelColor.xy); // Alternative to ivec3 // Calculate final fragment color. Note that the palette color components - // are defined in the range [0, 255] and need to be normalized to [0, 1] - // for OpenGL to work. + // are defined in the range [0..255] and need to be normalized to [0..1] gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a); } diff --git a/examples/shaders/resources/shaders/glsl330/palette_switch.fs b/examples/shaders/resources/shaders/glsl330/palette_switch.fs index 7c8a488cd..6a82529b1 100644 --- a/examples/shaders/resources/shaders/glsl330/palette_switch.fs +++ b/examples/shaders/resources/shaders/glsl330/palette_switch.fs @@ -1,6 +1,6 @@ #version 330 -const int colors = 8; +const int MAX_INDEXED_COLORS = 8; // Input fragment attributes (from fragment shader) in vec2 fragTexCoord; @@ -8,7 +8,8 @@ in vec4 fragColor; // Input uniform values uniform sampler2D texture0; -uniform ivec3 palette[colors]; +uniform ivec3 palette[MAX_INDEXED_COLORS]; +//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture // Output fragment color out vec4 finalColor; @@ -16,15 +17,17 @@ out vec4 finalColor; void main() { // Texel color fetching from texture sampler + // NOTE: The texel is actually the a GRAYSCALE index color vec4 texelColor = texture(texture0, fragTexCoord)*fragColor; // Convert the (normalized) texel color RED component (GB would work, too) - // to the palette index by scaling up from [0, 1] to [0, 255]. + // to the palette index by scaling up from [0..1] to [0..255] int index = int(texelColor.r*255.0); ivec3 color = palette[index]; + + //finalColor = texture(palette, texelColor.xy); // Alternative to ivec3 // Calculate final fragment color. Note that the palette color components - // are defined in the range [0, 255] and need to be normalized to [0, 1] - // for OpenGL to work. + // are defined in the range [0..255] and need to be normalized to [0..1] finalColor = vec4(color/255.0, texelColor.a); } diff --git a/src/external/rl_gputex.h b/src/external/rl_gputex.h index 2cbe59636..c57730552 100644 --- a/src/external/rl_gputex.h +++ b/src/external/rl_gputex.h @@ -229,7 +229,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_ } } } - else if (header->ddspf.flags == 0x40 && header->ddspf.rgb_bit_count == 24) // DDS_RGB, no compressed + else if ((header->ddspf.flags == 0x40) && (header->ddspf.rgb_bit_count == 24)) // DDS_RGB, no compressed { int data_size = image_pixel_size*3*sizeof(unsigned char); image_data = RL_MALLOC(data_size); @@ -238,7 +238,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_ *format = PIXELFORMAT_UNCOMPRESSED_R8G8B8; } - else if (header->ddspf.flags == 0x41 && header->ddspf.rgb_bit_count == 32) // DDS_RGBA, no compressed + else if ((header->ddspf.flags == 0x41) && (header->ddspf.rgb_bit_count == 32)) // DDS_RGBA, no compressed { int data_size = image_pixel_size*4*sizeof(unsigned char); image_data = RL_MALLOC(data_size); From 23385231c6c5ed6e9ace97e7305d3b7002c62171 Mon Sep 17 00:00:00 2001 From: bohonghuang <1281299809@qq.com> Date: Mon, 6 May 2024 02:19:25 +0800 Subject: [PATCH 18/19] [rlgl] Fix incorrect matrix multiplication order in `rlMultMatrixf` (#3935) --- src/rlgl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index ae53b4efb..513dd3ed7 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1296,7 +1296,7 @@ void rlMultMatrixf(const float *matf) matf[2], matf[6], matf[10], matf[14], matf[3], matf[7], matf[11], matf[15] }; - *RLGL.State.currentMatrix = rlMatrixMultiply(*RLGL.State.currentMatrix, mat); + *RLGL.State.currentMatrix = rlMatrixMultiply(mat, *RLGL.State.currentMatrix); } // Multiply the current matrix by a perspective matrix generated by parameters From 3d9aafed3b5d183f35a1e8060d0985475101f6db Mon Sep 17 00:00:00 2001 From: Christian Haas Date: Sun, 5 May 2024 20:22:58 +0200 Subject: [PATCH 19/19] [rcore_desktop] Fix 3693 initial window geometry (#3950) * Rework window placement and dimensions for multi-monitor setups; - fullscreen apps use primary monitor, exclusively - non-fullscreen apps come in two variants: a) pre-determined window size by user b) use-active-monitor dimensions by user specifying 0x0 Either way, the window shall be centred at the monitor where it was created This may have been the original intent, yet the primary monitor was used also for the second case, regardless where the window opened. * Clean up code, handle error, fix integer-overflow for centering windowed fullscreen --- src/platforms/rcore_desktop.c | 95 +++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 26 deletions(-) diff --git a/src/platforms/rcore_desktop.c b/src/platforms/rcore_desktop.c index de289ca0a..f08774165 100644 --- a/src/platforms/rcore_desktop.c +++ b/src/platforms/rcore_desktop.c @@ -1218,6 +1218,19 @@ void PollInputEvents(void) // Module Internal Functions Definition //---------------------------------------------------------------------------------- +static void SetDimensionsFromMonitor(GLFWmonitor *monitor) +{ + const GLFWvidmode *mode = glfwGetVideoMode(monitor); + + // Default display resolution to that of the current mode + CORE.Window.display.width = mode->width; + CORE.Window.display.height = mode->height; + + // Set screen width/height to the display width/height if they are 0 + 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; +} + // Initialize platform: graphics, inputs and more int InitPlatform(void) { @@ -1358,26 +1371,22 @@ int InitPlatform(void) // REF: https://github.com/raysan5/raylib/issues/1554 glfwSetJoystickCallback(NULL); - // Find monitor resolution - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - if (!monitor) - { - TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor"); - return -1; - } - - const GLFWvidmode *mode = glfwGetVideoMode(monitor); - - CORE.Window.display.width = mode->width; - CORE.Window.display.height = mode->height; - - // Set screen width/height to the display width/height if they are 0 - 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; - + GLFWmonitor *monitor = NULL; if (CORE.Window.fullscreen) { - // Remember center for switchinging from fullscreen to window + // According to glfwCreateWindow(), if the user does not have a choice, fullscreen applications + // should default to the primary monitor. + + monitor = glfwGetPrimaryMonitor(); + if (!monitor) + { + TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor"); + return -1; + } + + SetDimensionsFromMonitor(monitor); + + // Remember center for switching from fullscreen to window if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) { // If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed. @@ -1396,7 +1405,7 @@ int InitPlatform(void) // Obtain recommended CORE.Window.display.width/CORE.Window.display.height from a valid videomode for the monitor int count = 0; - const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count); + const GLFWvidmode *modes = glfwGetVideoModes(monitor, &count); // Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height for (int i = 0; i < count; i++) @@ -1426,21 +1435,55 @@ int InitPlatform(void) // HighDPI monitors are properly considered in a following similar function: SetupViewport() SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); - platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", glfwGetPrimaryMonitor(), NULL); + platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL); // NOTE: Full-screen change, not working properly... //glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); } else { - // If we are windowed fullscreen, ensures that window does not minimize when focus is lost - if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) + // No-fullscreen window creation + bool wantWindowedFullscreen = (CORE.Window.screen.height == 0) && (CORE.Window.screen.width == 0); + + // If we are windowed fullscreen, ensures that window does not minimize when focus is lost. + // This hinting code will not work if the user already specified the correct monitor dimensions; + // at this point we don't know the monitor's dimensions. (Though, how did the user then?) + if (wantWindowedFullscreen) { glfwWindowHint(GLFW_AUTO_ICONIFY, 0); } - // No-fullscreen window creation - platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); + // Default to at least one pixel in size, as creation with a zero dimension is not allowed. + int creationWidth = CORE.Window.screen.width != 0 ? CORE.Window.screen.width : 1; + int creationHeight = CORE.Window.screen.height != 0 ? CORE.Window.screen.height : 1; + + platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); + + // After the window was created, determine the monitor that the window manager assigned. + // Derive display sizes, and, if possible, window size in case it was zero at beginning. + + int monitorCount = 0; + int monitorIndex = GetCurrentMonitor(); + GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); + + if (monitorIndex < monitorCount) + { + monitor = monitors[monitorIndex]; + SetDimensionsFromMonitor(monitor); + + TRACELOG(LOG_INFO, "wantWindowed: %d, size: %dx%d", wantWindowedFullscreen, CORE.Window.screen.width, CORE.Window.screen.height); + if (wantWindowedFullscreen) + { + glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height); + } + } + else + { + // The monitor for the window-manager-created window can not be determined, so it can not be centered. + glfwTerminate(); + TRACELOG(LOG_WARNING, "GLFW: Failed to determine Monitor to center Window"); + return -1; + } if (platform.handle) { @@ -1524,8 +1567,8 @@ int InitPlatform(void) int monitorHeight = 0; glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight); - int posX = monitorX + (monitorWidth - CORE.Window.screen.width)/2; - int posY = monitorY + (monitorHeight - CORE.Window.screen.height)/2; + int posX = monitorX + (monitorWidth - (int)CORE.Window.screen.width)/2; + int posY = monitorY + (monitorHeight - (int)CORE.Window.screen.height)/2; if (posX < monitorX) posX = monitorX; if (posY < monitorY) posY = monitorY; SetWindowPosition(posX, posY);