From c7476f0aa508b4d04428e340ef1ffddca5b90b9a Mon Sep 17 00:00:00 2001 From: jpe230 Date: Sun, 14 Feb 2021 10:36:24 -0600 Subject: [PATCH 01/51] Fix support of touchscreens for RPI (#1586) -Checks for absolute pressure in absolute events to simulate a touch or a left mouse click. -Updates touch position on absolute events. --- src/core.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/core.c b/src/core.c index 3c179bd6e..60620085e 100644 --- a/src/core.c +++ b/src/core.c @@ -5753,8 +5753,9 @@ static void *EventThread(void *arg) // Basic movement if (event.code == ABS_X) { - CORE.Input.Mouse.position.x = (event.value - worker->absRange.x)*CORE.Window.screen.width/worker->absRange.width; // Scale acording to absRange - + CORE.Input.Mouse.position.x = (event.value - worker->absRange.x)*CORE.Window.screen.width/worker->absRange.width; // Scale acording to absRange + CORE.Input.Touch.position[0].x = (event.value - worker->absRange.x)*CORE.Window.screen.width/worker->absRange.width; // Scale acording to absRange + #if defined(SUPPORT_GESTURES_SYSTEM) touchAction = TOUCH_MOVE; gestureUpdate = true; @@ -5763,7 +5764,8 @@ static void *EventThread(void *arg) if (event.code == ABS_Y) { - CORE.Input.Mouse.position.y = (event.value - worker->absRange.y)*CORE.Window.screen.height/worker->absRange.height; // Scale acording to absRange + CORE.Input.Mouse.position.y = (event.value - worker->absRange.y)*CORE.Window.screen.height/worker->absRange.height; // Scale acording to absRange + CORE.Input.Touch.position[0].y = (event.value - worker->absRange.y)*CORE.Window.screen.height/worker->absRange.height; // Scale acording to absRange #if defined(SUPPORT_GESTURES_SYSTEM) touchAction = TOUCH_MOVE; @@ -5772,7 +5774,7 @@ static void *EventThread(void *arg) } // Multitouch movement - if (event.code == ABS_MT_SLOT) worker->touchSlot = event.value; // Remeber the slot number for the folowing events + if (event.code == ABS_MT_SLOT) worker->touchSlot = event.value; // Remember the slot number for the folowing events if (event.code == ABS_MT_POSITION_X) { @@ -5793,6 +5795,33 @@ static void *EventThread(void *arg) CORE.Input.Touch.position[worker->touchSlot].y = -1; } } + + // Touchscreen tap + if(event.code == ABS_PRESSURE) + { + int previousMouseLeftButtonState = CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON]; + + if(!event.value && previousMouseLeftButtonState) + { + CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = 0; + + #if defined(SUPPORT_GESTURES_SYSTEM) + touchAction = TOUCH_UP; + gestureUpdate = true; + #endif + } + + if(event.value && !previousMouseLeftButtonState) + { + CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = 1; + + #if defined(SUPPORT_GESTURES_SYSTEM) + touchAction = TOUCH_DOWN; + gestureUpdate = true; + #endif + } + } + } // Button parsing From ccb083af52989c8681aa8047cd6380f7081d3381 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 14 Feb 2021 16:37:34 +0000 Subject: [PATCH 02/51] [raudio] Fix load and unload issues with Music (#1588) * Add MUSIC_AUDIO_NONE to MusicContextType and format fixes - Useful to check the context type to see if the format is recognized. Defaulting to wav causes issues where formats are assumed to be wav. * Fix memory issues with LoadMusicStream and UnloadMusicStream - Set ctxType and ctxData even if the format fails to load. - Set ctxData to NULL if it fails and check for null inside UnloadMusicStream. - Change RL_MALLOC when loading formats to RL_CALLOC to prevent undefined behavior. - Add NULL check when unloading xm file. --- src/external/jar_xm.h | 4 ++- src/raudio.c | 69 ++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/external/jar_xm.h b/src/external/jar_xm.h index 1839e619c..bfd63ec07 100644 --- a/src/external/jar_xm.h +++ b/src/external/jar_xm.h @@ -696,7 +696,9 @@ int jar_xm_create_context_safe(jar_xm_context_t** ctxp, const char* moddata, siz } void jar_xm_free_context(jar_xm_context_t* ctx) { - JARXM_FREE(ctx->allocated_memory); + if (ctx != NULL) { + JARXM_FREE(ctx->allocated_memory); + } } void jar_xm_set_max_loop_count(jar_xm_context_t* ctx, uint8_t loopcnt) { diff --git a/src/raudio.c b/src/raudio.c index 854e21455..6a122720d 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -275,7 +275,8 @@ typedef struct tagBITMAPINFOHEADER { // NOTE: Depends on data structure provided by the library // in charge of reading the different file types typedef enum { - MUSIC_AUDIO_WAV = 0, + MUSIC_AUDIO_NONE = 0, + MUSIC_AUDIO_WAV, MUSIC_AUDIO_OGG, MUSIC_AUDIO_FLAC, MUSIC_AUDIO_MP3, @@ -465,7 +466,7 @@ void InitAudioDevice(void) ma_context_uninit(&AUDIO.System.context); return; } - + // Init dummy audio buffers pool for multichannel sound playing for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) { @@ -491,7 +492,7 @@ void CloseAudioDevice(void) { // Unload dummy audio buffers pool // WARNING: They can be pointing to already unloaded data - for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) + for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) { //UnloadAudioBuffer(AUDIO.MultiChannel.pool[i]); if (AUDIO.MultiChannel.pool[i] != NULL) @@ -502,7 +503,7 @@ void CloseAudioDevice(void) RL_FREE(AUDIO.MultiChannel.pool[i]); } } - + ma_mutex_uninit(&AUDIO.System.lock); ma_device_uninit(&AUDIO.System.device); ma_context_uninit(&AUDIO.System.context); @@ -1112,9 +1113,9 @@ float *LoadWaveSamples(Wave wave) for (unsigned int i = 0; i < wave.sampleCount; i++) { - if (wave.sampleSize == 8) samples[i] = (float)(((unsigned char *)wave.data)[i] - 127)/256.0f; - else if (wave.sampleSize == 16) samples[i] = (float)(((short *)wave.data)[i])/32767.0f; - else if (wave.sampleSize == 32) samples[i] = ((float *)wave.data)[i]; + if (wave.sampleSize == 8) samples[i] = (float)(((unsigned char *)wave.data)[i] - 127)/256.0f; + else if (wave.sampleSize == 16) samples[i] = (float)(((short *)wave.data)[i])/32767.0f; + else if (wave.sampleSize == 32) samples[i] = ((float *)wave.data)[i]; } return samples; @@ -1140,14 +1141,14 @@ Music LoadMusicStream(const char *fileName) #if defined(SUPPORT_FILEFORMAT_WAV) else if (IsFileExtension(fileName, ".wav")) { - drwav *ctxWav = RL_MALLOC(sizeof(drwav)); + drwav *ctxWav = RL_CALLOC(1, sizeof(drwav)); bool success = drwav_init_file(ctxWav, fileName, NULL); + music.ctxType = MUSIC_AUDIO_WAV; + music.ctxData = ctxWav; + if (success) { - music.ctxType = MUSIC_AUDIO_WAV; - music.ctxData = ctxWav; - int sampleSize = ctxWav->bitsPerSample; if (ctxWav->bitsPerSample == 24) sampleSize = 16; // Forcing conversion to s16 on UpdateMusicStream() @@ -1162,11 +1163,11 @@ Music LoadMusicStream(const char *fileName) else if (IsFileExtension(fileName, ".ogg")) { // Open ogg audio stream + music.ctxType = MUSIC_AUDIO_OGG; music.ctxData = stb_vorbis_open_filename(fileName, NULL, NULL); if (music.ctxData != NULL) { - music.ctxType = MUSIC_AUDIO_OGG; stb_vorbis_info info = stb_vorbis_get_info((stb_vorbis *)music.ctxData); // Get Ogg file info // OGG bit rate defaults to 16 bit, it's enough for compressed format @@ -1182,11 +1183,11 @@ Music LoadMusicStream(const char *fileName) #if defined(SUPPORT_FILEFORMAT_FLAC) else if (IsFileExtension(fileName, ".flac")) { + music.ctxType = MUSIC_AUDIO_FLAC; music.ctxData = drflac_open_file(fileName, NULL); if (music.ctxData != NULL) { - music.ctxType = MUSIC_AUDIO_FLAC; drflac *ctxFlac = (drflac *)music.ctxData; music.stream = InitAudioStream(ctxFlac->sampleRate, ctxFlac->bitsPerSample, ctxFlac->channels); @@ -1199,15 +1200,14 @@ Music LoadMusicStream(const char *fileName) #if defined(SUPPORT_FILEFORMAT_MP3) else if (IsFileExtension(fileName, ".mp3")) { - drmp3 *ctxMp3 = RL_MALLOC(sizeof(drmp3)); - music.ctxData = ctxMp3; - + drmp3 *ctxMp3 = RL_CALLOC(1, sizeof(drmp3)); int result = drmp3_init_file(ctxMp3, fileName, NULL); + music.ctxType = MUSIC_AUDIO_MP3; + music.ctxData = ctxMp3; + if (result > 0) { - music.ctxType = MUSIC_AUDIO_MP3; - music.stream = InitAudioStream(ctxMp3->sampleRate, 32, ctxMp3->channels); music.sampleCount = (unsigned int)drmp3_get_pcm_frame_count(ctxMp3)*ctxMp3->channels; music.looping = true; // Looping enabled by default @@ -1219,12 +1219,13 @@ Music LoadMusicStream(const char *fileName) else if (IsFileExtension(fileName, ".xm")) { jar_xm_context_t *ctxXm = NULL; - int result = jar_xm_create_context_from_file(&ctxXm, 48000, fileName); + music.ctxType = MUSIC_MODULE_XM; + music.ctxData = ctxXm; + if (result == 0) // XM AUDIO.System.context created successfully { - music.ctxType = MUSIC_MODULE_XM; jar_xm_set_max_loop_count(ctxXm, 0); // Set infinite number of loops // NOTE: Only stereo is supported for XM @@ -1233,30 +1234,26 @@ Music LoadMusicStream(const char *fileName) music.looping = true; // Looping enabled by default jar_xm_reset(ctxXm); // make sure we start at the beginning of the song musicLoaded = true; - - music.ctxData = ctxXm; } } #endif #if defined(SUPPORT_FILEFORMAT_MOD) else if (IsFileExtension(fileName, ".mod")) { - jar_mod_context_t *ctxMod = RL_MALLOC(sizeof(jar_mod_context_t)); - + jar_mod_context_t *ctxMod = RL_CALLOC(1, sizeof(jar_mod_context_t)); jar_mod_init(ctxMod); int result = jar_mod_load_file(ctxMod, fileName); + music.ctxType = MUSIC_MODULE_MOD; + music.ctxData = ctxMod; + if (result > 0) { - music.ctxType = MUSIC_MODULE_MOD; - // NOTE: Only stereo is supported for MOD music.stream = InitAudioStream(48000, 16, 2); music.sampleCount = (unsigned int)jar_mod_max_samples(ctxMod)*2; // 2 channels music.looping = true; // Looping enabled by default musicLoaded = true; - - music.ctxData = ctxMod; } } #endif @@ -1284,6 +1281,7 @@ Music LoadMusicStream(const char *fileName) else if (music.ctxType == MUSIC_MODULE_MOD) { jar_mod_unload((jar_mod_context_t *)music.ctxData); RL_FREE(music.ctxData); } #endif + music.ctxData = NULL; TRACELOG(LOG_WARNING, "FILEIO: [%s] Music file could not be opened", fileName); } else @@ -1304,25 +1302,28 @@ void UnloadMusicStream(Music music) { CloseAudioStream(music.stream); - if (false) { } + if (music.ctxData != NULL) + { + if (false) { } #if defined(SUPPORT_FILEFORMAT_WAV) - else if (music.ctxType == MUSIC_AUDIO_WAV) drwav_uninit((drwav *)music.ctxData); + else if (music.ctxType == MUSIC_AUDIO_WAV) drwav_uninit((drwav *)music.ctxData); #endif #if defined(SUPPORT_FILEFORMAT_OGG) - else if (music.ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close((stb_vorbis *)music.ctxData); + else if (music.ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close((stb_vorbis *)music.ctxData); #endif #if defined(SUPPORT_FILEFORMAT_FLAC) - else if (music.ctxType == MUSIC_AUDIO_FLAC) drflac_free((drflac *)music.ctxData, NULL); + else if (music.ctxType == MUSIC_AUDIO_FLAC) drflac_free((drflac *)music.ctxData, NULL); #endif #if defined(SUPPORT_FILEFORMAT_MP3) else if (music.ctxType == MUSIC_AUDIO_MP3) { drmp3_uninit((drmp3 *)music.ctxData); RL_FREE(music.ctxData); } #endif #if defined(SUPPORT_FILEFORMAT_XM) - else if (music.ctxType == MUSIC_MODULE_XM) jar_xm_free_context((jar_xm_context_t *)music.ctxData); + else if (music.ctxType == MUSIC_MODULE_XM) jar_xm_free_context((jar_xm_context_t *)music.ctxData); #endif #if defined(SUPPORT_FILEFORMAT_MOD) - else if (music.ctxType == MUSIC_MODULE_MOD) { jar_mod_unload((jar_mod_context_t *)music.ctxData); RL_FREE(music.ctxData); } + else if (music.ctxType == MUSIC_MODULE_MOD) { jar_mod_unload((jar_mod_context_t *)music.ctxData); RL_FREE(music.ctxData); } #endif + } } // Start music playing (open stream) From e300d268f90ec759d07329a07b864b648e7de2d2 Mon Sep 17 00:00:00 2001 From: Rabia Alhaffar Date: Mon, 15 Feb 2021 14:28:52 +0200 Subject: [PATCH 03/51] Fixed problem related to `IsKeyPressed` function! (#1589) --- examples/shapes/shapes_logo_raylib_anim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/shapes/shapes_logo_raylib_anim.c b/examples/shapes/shapes_logo_raylib_anim.c index b8558393e..fe5eeffb4 100644 --- a/examples/shapes/shapes_logo_raylib_anim.c +++ b/examples/shapes/shapes_logo_raylib_anim.c @@ -90,7 +90,7 @@ int main(void) } else if (state == 4) // State 4: Reset and Replay { - if (IsKeyPressed('R')) + if (IsKeyPressed(KEY_R)) { framesCounter = 0; lettersCount = 0; @@ -157,4 +157,4 @@ int main(void) //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +} From b530b584b520af81d5a6517ebe30f086dcf79d60 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 15 Feb 2021 11:41:15 -0500 Subject: [PATCH 04/51] Rename raylib-js to raylib-duktape (#1591) While it is JavaScript, I'd rather this be named raylib-duktape since there are different implementations of javascript available. Like QuickJS, V7, or Node.js. --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 7a7578e64..1fdec5672 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -53,7 +53,7 @@ Here it is a list with the ones I'm aware of: | clj-raylib | 3.0 | [Clojure](https://clojure.org/) | https://github.com/lsevero/clj-raylib | | node-raylib | 3.5 | [Node.js](https://nodejs.org/en/) | https://github.com/RobLoach/node-raylib | | QuickJS-raylib | 3.0 | [QuickJS](https://bellard.org/quickjs/) | https://github.com/sntg-p/QuickJS-raylib | -| raylib-js | 2.6 | [JavaScript](https://en.wikipedia.org/wiki/JavaScript) | https://github.com/RobLoach/raylib-js | +| raylib-duktape | 2.6 | [JavaScript](https://en.wikipedia.org/wiki/JavaScript) | https://github.com/RobLoach/raylib-duktape | | raylib-chaiscript | 2.6 | [ChaiScript](http://chaiscript.com/) | https://github.com/RobLoach/raylib-chaiscript | | raylib-squirrel | 2.5 | [Squirrel](http://www.squirrel-lang.org/) | https://github.com/RobLoach/raylib-squirrel | | racket-raylib-2d | 2.5 | [Racket](https://racket-lang.org/) | https://github.com/arvyy/racket-raylib-2d | From 0f5aab3a1ca2ffaae6c6e784d485007d7d6e7182 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Tue, 16 Feb 2021 01:29:00 -0800 Subject: [PATCH 05/51] check to make sure parent bone is not null before trying to compute its offset from the root (#1594) --- src/models.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/models.c b/src/models.c index 68e80acd3..f4b79e395 100644 --- a/src/models.c +++ b/src/models.c @@ -3733,7 +3733,7 @@ static Model LoadGLTF(const char *fileName) for (unsigned int j = 0; j < data->nodes_count; j++) { strcpy(model.bones[j].name, data->nodes[j].name == 0 ? "ANIMJOINT" : data->nodes[j].name); - model.bones[j].parent = j != 0 ? data->nodes[j].parent - data->nodes : 0; + model.bones[j].parent = (j != 0 && data->nodes[j].parent != NULL) ? data->nodes[j].parent - data->nodes : 0; } for (unsigned int i = 0; i < data->nodes_count; i++) @@ -3771,7 +3771,10 @@ static Model LoadGLTF(const char *fileName) { Transform* currentTransform = model.bindPose + i; BoneInfo* currentBone = model.bones + i; - Transform* parentTransform = model.bindPose + currentBone->parent; + int root = currentBone->parent; + if (root >= model.boneCount) + root = 0; + Transform* parentTransform = model.bindPose + root; if (currentBone->parent >= 0) { From d96b422809d84e445e9d581ea359b491f50dbddc Mon Sep 17 00:00:00 2001 From: Rabia Alhaffar Date: Thu, 18 Feb 2021 22:52:39 +0200 Subject: [PATCH 06/51] Fixed example doesn't show gamepad for Xbox 360 controllers with different drivers (#1597) --- examples/core/core_input_gamepad.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/core/core_input_gamepad.c b/examples/core/core_input_gamepad.c index bf9d219c5..eb9b1b11e 100644 --- a/examples/core/core_input_gamepad.c +++ b/examples/core/core_input_gamepad.c @@ -19,11 +19,12 @@ // NOTE: Gamepad name ID depends on drivers and OS #if defined(PLATFORM_RPI) - #define XBOX360_NAME_ID "Microsoft X-Box 360 pad" - #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" + #define XBOX360_NAME_ID "Microsoft X-Box 360 pad" + #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" #else - #define XBOX360_NAME_ID "Xbox 360 Controller" - #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" + #define XBOX360_NAME_ID "Xbox 360 Controller" + #define XBOX360_LEGACY_NAME_ID "Xbox Controller" + #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" #endif int main(void) @@ -61,7 +62,7 @@ int main(void) { DrawText(TextFormat("GP1: %s", GetGamepadName(GAMEPAD_PLAYER1)), 10, 10, 10, BLACK); - if (IsGamepadName(GAMEPAD_PLAYER1, XBOX360_NAME_ID)) + if (IsGamepadName(GAMEPAD_PLAYER1, XBOX360_NAME_ID) || IsGamepadName(GAMEPAD_PLAYER1, XBOX360_LEGACY_NAME_ID)) { DrawTexture(texXboxPad, 0, 0, DARKGRAY); @@ -191,4 +192,4 @@ int main(void) //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +} From 2375464213f9bb08e9ae9f0a5b264aaa268a6a3b Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sat, 20 Feb 2021 02:15:40 -0800 Subject: [PATCH 07/51] [Physics] Fix typecast warnings generated by visual studio 2019 (#1599) * More warning fixes for physics and math * fix a crash introduced with the warning changed. Co-authored-by: Jeffery Myers --- src/physac.h | 186 +++++++++++++++++++++++++++----------------------- src/raymath.h | 2 +- 2 files changed, 101 insertions(+), 87 deletions(-) diff --git a/src/physac.h b/src/physac.h index 0ed2646ef..fde0b90e3 100644 --- a/src/physac.h +++ b/src/physac.h @@ -112,7 +112,7 @@ #define PHYSAC_PENETRATION_ALLOWANCE 0.05f #define PHYSAC_PENETRATION_CORRECTION 0.4f -#define PHYSAC_PI 3.14159265358979323846 +#define PHYSAC_PI 3.14159265358979323846f #define PHYSAC_DEG2RAD (PHYSAC_PI/180.0f) //---------------------------------------------------------------------------------- @@ -412,11 +412,11 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float float area = 0.0f; float inertia = 0.0f; - for (int i = 0; i < body->shape.vertexData.vertexCount; i++) + for (unsigned int i = 0; i < body->shape.vertexData.vertexCount; i++) { // Triangle vertices, third vertex implied as (0, 0) Vector2 p1 = body->shape.vertexData.positions[i]; - int nextIndex = (((i + 1) < body->shape.vertexData.vertexCount) ? (i + 1) : 0); + unsigned int nextIndex = (((i + 1) < body->shape.vertexData.vertexCount) ? (i + 1) : 0); Vector2 p2 = body->shape.vertexData.positions[nextIndex]; float D = MathVector2CrossProduct(p1, p2); @@ -438,7 +438,7 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space) // Note: this is not really necessary - for (int i = 0; i < body->shape.vertexData.vertexCount; i++) + for (unsigned int i = 0; i < body->shape.vertexData.vertexCount; i++) { body->shape.vertexData.positions[i].x -= center.x; body->shape.vertexData.positions[i].y -= center.y; @@ -494,11 +494,11 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int si float area = 0.0f; float inertia = 0.0f; - for (int i = 0; i < body->shape.vertexData.vertexCount; i++) + for (unsigned int i = 0; i < body->shape.vertexData.vertexCount; i++) { // Triangle vertices, third vertex implied as (0, 0) Vector2 position1 = body->shape.vertexData.positions[i]; - int nextIndex = (((i + 1) < body->shape.vertexData.vertexCount) ? (i + 1) : 0); + unsigned int nextIndex = (((i + 1) < body->shape.vertexData.vertexCount) ? (i + 1) : 0); Vector2 position2 = body->shape.vertexData.positions[nextIndex]; float cross = MathVector2CrossProduct(position1, position2); @@ -520,7 +520,7 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int si // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space) // Note: this is not really necessary - for (int i = 0; i < body->shape.vertexData.vertexCount; i++) + for (unsigned int i = 0; i < body->shape.vertexData.vertexCount; i++) { body->shape.vertexData.positions[i].x -= center.x; body->shape.vertexData.positions[i].y -= center.y; @@ -570,11 +570,11 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force) PhysicsVertexData vertexData = body->shape.vertexData; bool collision = false; - for (int i = 0; i < vertexData.vertexCount; i++) + for (unsigned int i = 0; i < vertexData.vertexCount; i++) { Vector2 positionA = body->position; Vector2 positionB = MathMatVector2Product(body->shape.transform, MathVector2Add(body->position, vertexData.positions[i])); - int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0); + unsigned int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0); Vector2 positionC = MathMatVector2Product(body->shape.transform, MathVector2Add(body->position, vertexData.positions[nextIndex])); // Check collision between each triangle @@ -629,9 +629,9 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force) vertexData.positions[2].y *= 0.95f; // Calculate polygon faces normals - for (int j = 0; j < vertexData.vertexCount; j++) + for (unsigned int j = 0; j < vertexData.vertexCount; j++) { - int nextVertex = (((j + 1) < vertexData.vertexCount) ? (j + 1) : 0); + unsigned int nextVertex = (((j + 1) < vertexData.vertexCount) ? (j + 1) : 0); Vector2 face = MathVector2Subtract(vertexData.positions[nextVertex], vertexData.positions[j]); vertexData.normals[j] = CLITERAL(Vector2){ face.y, -face.x }; @@ -647,11 +647,11 @@ PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force) float area = 0.0f; float inertia = 0.0f; - for (int j = 0; j < body->shape.vertexData.vertexCount; j++) + for (unsigned int j = 0; j < body->shape.vertexData.vertexCount; j++) { // Triangle vertices, third vertex implied as (0, 0) Vector2 p1 = body->shape.vertexData.positions[j]; - int nextVertex = (((j + 1) < body->shape.vertexData.vertexCount) ? (j + 1) : 0); + unsigned int nextVertex = (((j + 1) < body->shape.vertexData.vertexCount) ? (j + 1) : 0); Vector2 p2 = body->shape.vertexData.positions[nextVertex]; float D = MathVector2CrossProduct(p1, p2); @@ -708,7 +708,7 @@ PHYSACDEF PhysicsBody GetPhysicsBody(int index) { PhysicsBody body = NULL; - if (index < physicsBodiesCount) + if (index < (int)physicsBodiesCount) { body = bodies[index]; @@ -724,7 +724,7 @@ PHYSACDEF int GetPhysicsShapeType(int index) { int result = -1; - if (index < physicsBodiesCount) + if (index < (int)physicsBodiesCount) { PhysicsBody body = bodies[index]; @@ -741,7 +741,7 @@ PHYSACDEF int GetPhysicsShapeVerticesCount(int index) { int result = 0; - if (index < physicsBodiesCount) + if (index < (int)physicsBodiesCount) { PhysicsBody body = bodies[index]; @@ -807,7 +807,7 @@ PHYSACDEF void DestroyPhysicsBody(PhysicsBody body) int id = body->id; int index = -1; - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { if (bodies[i]->id == id) { @@ -828,7 +828,7 @@ PHYSACDEF void DestroyPhysicsBody(PhysicsBody body) bodies[index] = NULL; // Reorder physics bodies pointers array and its catched index - for (int i = index; i < physicsBodiesCount; i++) + for (unsigned int i = index; i < physicsBodiesCount; i++) { if ((i + 1) < physicsBodiesCount) bodies[i] = bodies[i + 1]; } @@ -844,35 +844,41 @@ PHYSACDEF void DestroyPhysicsBody(PhysicsBody body) // Destroys created physics bodies and manifolds and resets global values PHYSACDEF void ResetPhysics(void) { - // Unitialize physics bodies dynamic memory allocations - for (int i = physicsBodiesCount - 1; i >= 0; i--) + if (physicsBodiesCount > 0) { - PhysicsBody body = bodies[i]; - - if (body != NULL) + // Unitialize physics bodies dynamic memory allocations + for (unsigned int i = physicsBodiesCount - 1; i >= 0; i--) { - PHYSAC_FREE(body); - bodies[i] = NULL; - usedMemory -= sizeof(PhysicsBodyData); + PhysicsBody body = bodies[i]; + + if (body != NULL) + { + PHYSAC_FREE(body); + bodies[i] = NULL; + usedMemory -= sizeof(PhysicsBodyData); + } } + + physicsBodiesCount = 0; } - physicsBodiesCount = 0; - - // Unitialize physics manifolds dynamic memory allocations - for (int i = physicsManifoldsCount - 1; i >= 0; i--) + if (physicsManifoldsCount > 0) { - PhysicsManifold manifold = contacts[i]; - - if (manifold != NULL) + // Unitialize physics manifolds dynamic memory allocations + for (unsigned int i = physicsManifoldsCount - 1; i >= 0; i--) { - PHYSAC_FREE(manifold); - contacts[i] = NULL; - usedMemory -= sizeof(PhysicsManifoldData); - } - } + PhysicsManifold manifold = contacts[i]; - physicsManifoldsCount = 0; + if (manifold != NULL) + { + PHYSAC_FREE(manifold); + contacts[i] = NULL; + usedMemory -= sizeof(PhysicsManifoldData); + } + } + + physicsManifoldsCount = 0; + } TRACELOG("[PHYSAC] Physics module reseted successfully\n"); } @@ -881,10 +887,18 @@ PHYSACDEF void ResetPhysics(void) PHYSACDEF void ClosePhysics(void) { // Unitialize physics manifolds dynamic memory allocations - for (int i = physicsManifoldsCount - 1; i >= 0; i--) DestroyPhysicsManifold(contacts[i]); - + if (physicsManifoldsCount > 0) + { + for (unsigned int i = physicsManifoldsCount - 1; i >= 0; i--) + DestroyPhysicsManifold(contacts[i]); + } + // Unitialize physics bodies dynamic memory allocations - for (int i = physicsBodiesCount - 1; i >= 0; i--) DestroyPhysicsBody(bodies[i]); + if (physicsBodiesCount > 0) + { + for (unsigned int i = physicsBodiesCount - 1; i >= 0; i--) + DestroyPhysicsBody(bodies[i]); + } // Trace log info if ((physicsBodiesCount > 0) || (usedMemory != 0)) @@ -910,7 +924,7 @@ static int FindAvailableBodyIndex() int currentId = i; // Check if current id already exist in other physics body - for (int k = 0; k < physicsBodiesCount; k++) + for (unsigned int k = 0; k < physicsBodiesCount; k++) { if (bodies[k]->id == currentId) { @@ -920,9 +934,9 @@ static int FindAvailableBodyIndex() } // If it is not used, use it as new physics body id - if (currentId == i) + if (currentId == (int)i) { - index = i; + index = (int)i; break; } } @@ -937,14 +951,14 @@ static PhysicsVertexData CreateDefaultPolygon(float radius, int sides) data.vertexCount = sides; // Calculate polygon vertices positions - for (int i = 0; i < data.vertexCount; i++) + for (unsigned int i = 0; i < data.vertexCount; i++) { - data.positions[i].x = cosf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius; - data.positions[i].y = sinf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius; + data.positions[i].x = (float)cosf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius; + data.positions[i].y = (float)sinf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius; } // Calculate polygon faces normals - for (int i = 0; i < data.vertexCount; i++) + for (int i = 0; i < (int)data.vertexCount; i++) { int nextIndex = (((i + 1) < sides) ? (i + 1) : 0); Vector2 face = MathVector2Subtract(data.positions[nextIndex], data.positions[i]); @@ -969,7 +983,7 @@ static PhysicsVertexData CreateRectanglePolygon(Vector2 pos, Vector2 size) data.positions[3] = CLITERAL(Vector2){ pos.x - size.x/2, pos.y - size.y/2 }; // Calculate polygon faces normals - for (int i = 0; i < data.vertexCount; i++) + for (unsigned int i = 0; i < data.vertexCount; i++) { int nextIndex = (((i + 1) < data.vertexCount) ? (i + 1) : 0); Vector2 face = MathVector2Subtract(data.positions[nextIndex], data.positions[i]); @@ -985,27 +999,27 @@ static PhysicsVertexData CreateRectanglePolygon(Vector2 pos, Vector2 size) void UpdatePhysicsStep(void) { // Clear previous generated collisions information - for (int i = physicsManifoldsCount - 1; i >= 0; i--) + for (int i = (int)physicsManifoldsCount - 1; i >= 0; i--) { PhysicsManifold manifold = contacts[i]; if (manifold != NULL) DestroyPhysicsManifold(manifold); } // Reset physics bodies grounded state - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { PhysicsBody body = bodies[i]; body->isGrounded = false; } - + // Generate new collision information - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { PhysicsBody bodyA = bodies[i]; if (bodyA != NULL) { - for (int j = i + 1; j < physicsBodiesCount; j++) + for (unsigned int j = i + 1; j < physicsBodiesCount; j++) { PhysicsBody bodyB = bodies[j]; @@ -1035,23 +1049,23 @@ void UpdatePhysicsStep(void) } // Integrate forces to physics bodies - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { PhysicsBody body = bodies[i]; if (body != NULL) IntegratePhysicsForces(body); } // Initialize physics manifolds to solve collisions - for (int i = 0; i < physicsManifoldsCount; i++) + for (unsigned int i = 0; i < physicsManifoldsCount; i++) { PhysicsManifold manifold = contacts[i]; if (manifold != NULL) InitializePhysicsManifolds(manifold); } // Integrate physics collisions impulses to solve collisions - for (int i = 0; i < PHYSAC_COLLISION_ITERATIONS; i++) + for (unsigned int i = 0; i < PHYSAC_COLLISION_ITERATIONS; i++) { - for (int j = 0; j < physicsManifoldsCount; j++) + for (unsigned int j = 0; j < physicsManifoldsCount; j++) { PhysicsManifold manifold = contacts[i]; if (manifold != NULL) IntegratePhysicsImpulses(manifold); @@ -1059,21 +1073,21 @@ void UpdatePhysicsStep(void) } // Integrate velocity to physics bodies - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { PhysicsBody body = bodies[i]; if (body != NULL) IntegratePhysicsVelocity(body); } // Correct physics bodies positions based on manifolds collision information - for (int i = 0; i < physicsManifoldsCount; i++) + for (unsigned int i = 0; i < physicsManifoldsCount; i++) { PhysicsManifold manifold = contacts[i]; if (manifold != NULL) CorrectPhysicsPositions(manifold); } // Clear physics bodies forces - for (int i = 0; i < physicsBodiesCount; i++) + for (unsigned int i = 0; i < physicsBodiesCount; i++) { PhysicsBody body = bodies[i]; if (body != NULL) @@ -1128,7 +1142,7 @@ static int FindAvailableManifoldIndex() int currentId = i; // Check if current id already exist in other physics body - for (int k = 0; k < physicsManifoldsCount; k++) + for (unsigned int k = 0; k < physicsManifoldsCount; k++) { if (contacts[k]->id == currentId) { @@ -1187,7 +1201,7 @@ static void DestroyPhysicsManifold(PhysicsManifold manifold) int id = manifold->id; int index = -1; - for (int i = 0; i < physicsManifoldsCount; i++) + for (unsigned int i = 0; i < physicsManifoldsCount; i++) { if (contacts[i]->id == id) { @@ -1204,7 +1218,7 @@ static void DestroyPhysicsManifold(PhysicsManifold manifold) contacts[index] = NULL; // Reorder physics manifolds pointers array and its catched index - for (int i = index; i < physicsManifoldsCount; i++) + for (unsigned int i = index; i < physicsManifoldsCount; i++) { if ((i + 1) < physicsManifoldsCount) contacts[i] = contacts[i + 1]; } @@ -1306,7 +1320,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold) int faceNormal = 0; PhysicsVertexData vertexData = bodyB->shape.vertexData; - for (int i = 0; i < vertexData.vertexCount; i++) + for (unsigned int i = 0; i < vertexData.vertexCount; i++) { float currentSeparation = MathVector2DotProduct(vertexData.normals[i], MathVector2Subtract(center, vertexData.positions[i])); @@ -1321,7 +1335,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold) // Grab face's vertices Vector2 v1 = vertexData.positions[faceNormal]; - int nextIndex = (((faceNormal + 1) < vertexData.vertexCount) ? (faceNormal + 1) : 0); + int nextIndex = (((faceNormal + 1) < (int)vertexData.vertexCount) ? (faceNormal + 1) : 0); Vector2 v2 = vertexData.positions[nextIndex]; // Check to see if center is within polygon @@ -1443,7 +1457,7 @@ static void SolvePolygonToPolygon(PhysicsManifold manifold) // Setup reference face vertices PhysicsVertexData refData = refPoly.vertexData; Vector2 v1 = refData.positions[referenceIndex]; - referenceIndex = (((referenceIndex + 1) < refData.vertexCount) ? (referenceIndex + 1) : 0); + referenceIndex = (((referenceIndex + 1) < (int)refData.vertexCount) ? (referenceIndex + 1) : 0); Vector2 v2 = refData.positions[referenceIndex]; // Transform vertices to world space @@ -1500,16 +1514,16 @@ static void IntegratePhysicsForces(PhysicsBody body) { if ((body == NULL) || (body->inverseMass == 0.0f) || !body->enabled) return; - body->velocity.x += (body->force.x*body->inverseMass)*(deltaTime/2.0); - body->velocity.y += (body->force.y*body->inverseMass)*(deltaTime/2.0); + body->velocity.x += (float)((body->force.x*body->inverseMass)*(deltaTime/2.0)); + body->velocity.y += (float)((body->force.y*body->inverseMass)*(deltaTime/2.0)); if (body->useGravity) { - body->velocity.x += gravityForce.x*(deltaTime/1000/2.0); - body->velocity.y += gravityForce.y*(deltaTime/1000/2.0); + body->velocity.x += (float)(gravityForce.x*(deltaTime/1000/2.0)); + body->velocity.y += (float)(gravityForce.y*(deltaTime/1000/2.0)); } - if (!body->freezeOrient) body->angularVelocity += body->torque*body->inverseInertia*(deltaTime/2.0); + if (!body->freezeOrient) body->angularVelocity += (float)(body->torque*body->inverseInertia*(deltaTime/2.0)); } // Initializes physics manifolds to solve collisions @@ -1525,7 +1539,7 @@ static void InitializePhysicsManifolds(PhysicsManifold manifold) manifold->staticFriction = sqrtf(bodyA->staticFriction*bodyB->staticFriction); manifold->dynamicFriction = sqrtf(bodyA->dynamicFriction*bodyB->dynamicFriction); - for (int i = 0; i < manifold->contactsCount; i++) + for (unsigned int i = 0; i < manifold->contactsCount; i++) { // Caculate radius from center of mass to contact Vector2 radiusA = MathVector2Subtract(manifold->contacts[i], bodyA->position); @@ -1540,7 +1554,7 @@ static void InitializePhysicsManifolds(PhysicsManifold manifold) // Determine if we should perform a resting collision or not; // The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution - if (MathVector2SqrLen(radiusV) < (MathVector2SqrLen(CLITERAL(Vector2){ gravityForce.x*deltaTime/1000, gravityForce.y*deltaTime/1000 }) + PHYSAC_EPSILON)) manifold->restitution = 0; + if (MathVector2SqrLen(radiusV) < (MathVector2SqrLen(CLITERAL(Vector2){ (float)(gravityForce.x*deltaTime/1000), (float)(gravityForce.y*deltaTime/1000) }) + PHYSAC_EPSILON)) manifold->restitution = 0; } } @@ -1560,7 +1574,7 @@ static void IntegratePhysicsImpulses(PhysicsManifold manifold) return; } - for (int i = 0; i < manifold->contactsCount; i++) + for (unsigned int i = 0; i < manifold->contactsCount; i++) { // Calculate radius from center of mass to contact Vector2 radiusA = MathVector2Subtract(manifold->contacts[i], bodyA->position); @@ -1616,7 +1630,7 @@ static void IntegratePhysicsImpulses(PhysicsManifold manifold) impulseTangent /= inverseMassSum; impulseTangent /= (float)manifold->contactsCount; - float absImpulseTangent = fabs(impulseTangent); + float absImpulseTangent = (float)fabs(impulseTangent); // Don't apply tiny friction impulses if (absImpulseTangent <= PHYSAC_EPSILON) return; @@ -1650,10 +1664,10 @@ static void IntegratePhysicsVelocity(PhysicsBody body) { if ((body == NULL) ||!body->enabled) return; - body->position.x += body->velocity.x*deltaTime; - body->position.y += body->velocity.y*deltaTime; + body->position.x += (float)(body->velocity.x*deltaTime); + body->position.y += (float)(body->velocity.y*deltaTime); - if (!body->freezeOrient) body->orient += body->angularVelocity*deltaTime; + if (!body->freezeOrient) body->orient += (float)(body->angularVelocity*deltaTime); body->shape.transform = MathMatFromRadians(body->orient); IntegratePhysicsForces(body); @@ -1691,7 +1705,7 @@ static Vector2 GetSupport(PhysicsShape shape, Vector2 dir) Vector2 bestVertex = { 0.0f, 0.0f }; PhysicsVertexData data = shape.vertexData; - for (int i = 0; i < data.vertexCount; i++) + for (unsigned int i = 0; i < data.vertexCount; i++) { Vector2 vertex = data.positions[i]; float projection = MathVector2DotProduct(vertex, dir); @@ -1715,7 +1729,7 @@ static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, Physi PhysicsVertexData dataA = shapeA.vertexData; //PhysicsVertexData dataB = shapeB.vertexData; - for (int i = 0; i < dataA.vertexCount; i++) + for (unsigned int i = 0; i < dataA.vertexCount; i++) { // Retrieve a face normal from A shape Vector2 normal = dataA.normals[i]; @@ -1766,7 +1780,7 @@ static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, Physics int incidentFace = 0; float minDot = PHYSAC_FLT_MAX; - for (int i = 0; i < incData.vertexCount; i++) + for (unsigned int i = 0; i < incData.vertexCount; i++) { float dot = MathVector2DotProduct(referenceNormal, incData.normals[i]); @@ -1780,7 +1794,7 @@ static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, Physics // Assign face vertices for incident face *v0 = MathMatVector2Product(inc.transform, incData.positions[incidentFace]); *v0 = MathVector2Add(*v0, inc.body->position); - incidentFace = (((incidentFace + 1) < incData.vertexCount) ? (incidentFace + 1) : 0); + incidentFace = (((incidentFace + 1) < (int)incData.vertexCount) ? (incidentFace + 1) : 0); *v1 = MathMatVector2Product(inc.transform, incData.positions[incidentFace]); *v1 = MathVector2Add(*v1, inc.body->position); } @@ -1849,8 +1863,8 @@ static void InitTimer(void) frequency = (timebase.denom*1e9)/timebase.numer; #endif - baseClockTicks = GetClockTicks(); // Get MONOTONIC clock time offset - startTime = GetCurrentTime(); // Get current time in milliseconds + baseClockTicks = (double)GetClockTicks(); // Get MONOTONIC clock time offset + startTime = GetCurrentTime(); // Get current time in milliseconds } // Get hi-res MONOTONIC time measure in clock ticks diff --git a/src/raymath.h b/src/raymath.h index 44d41d4d7..c9848a7fb 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1162,7 +1162,7 @@ RMDEF Quaternion QuaternionIdentity(void) // Computes the length of a quaternion RMDEF float QuaternionLength(Quaternion q) { - float result = (float)sqrt(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); + float result = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); return result; } From 0a8cb60eee5902de9c81f2d83fa19e3bc24668ed Mon Sep 17 00:00:00 2001 From: Redcamellia <46075102+Redcamellia@users.noreply.github.com> Date: Sat, 20 Feb 2021 13:18:43 +0300 Subject: [PATCH 08/51] fixed the right and left button not working (#1595) --- examples/textures/textures_mouse_painting.c | 107 +++++++++++--------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/examples/textures/textures_mouse_painting.c b/examples/textures/textures_mouse_painting.c index dedb8df35..fed6ece92 100644 --- a/examples/textures/textures_mouse_painting.c +++ b/examples/textures/textures_mouse_painting.c @@ -15,7 +15,7 @@ #define MAX_COLORS_COUNT 23 // Number of colors available -int main(void) +int main(void) { // Initialization //-------------------------------------------------------------------------------------- @@ -29,13 +29,13 @@ int main(void) RAYWHITE, YELLOW, GOLD, ORANGE, PINK, RED, MAROON, GREEN, LIME, DARKGREEN, SKYBLUE, BLUE, DARKBLUE, PURPLE, VIOLET, DARKPURPLE, BEIGE, BROWN, DARKBROWN, LIGHTGRAY, GRAY, DARKGRAY, BLACK }; - + // Define colorsRecs data (for every rectangle) Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; for (int i = 0; i < MAX_COLORS_COUNT; i++) { - colorsRecs[i].x = 10 + 30*i + 2*i; + colorsRecs[i].x = 10 + 30 * i + 2 * i; colorsRecs[i].y = 10; colorsRecs[i].width = 30; colorsRecs[i].height = 30; @@ -45,7 +45,8 @@ int main(void) int colorSelectedPrev = colorSelected; int colorMouseHover = 0; int brushSize = 20; - + bool mouseWasPressed = false; + Rectangle btnSaveRec = { 750, 10, 40, 30 }; bool btnSaveMouseHover = false; bool showSaveMessage = false; @@ -68,11 +69,11 @@ int main(void) // Update //---------------------------------------------------------------------------------- Vector2 mousePos = GetMousePosition(); - + // Move between colors with keys if (IsKeyPressed(KEY_RIGHT)) colorSelected++; else if (IsKeyPressed(KEY_LEFT)) colorSelected--; - + if (colorSelected >= MAX_COLORS_COUNT) colorSelected = MAX_COLORS_COUNT - 1; else if (colorSelected < 0) colorSelected = 0; @@ -86,19 +87,19 @@ int main(void) } else colorMouseHover = -1; } - - if ((colorMouseHover >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + + if ((colorMouseHover >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { colorSelected = colorMouseHover; colorSelectedPrev = colorSelected; } // Change brush size - brushSize += GetMouseWheelMove()*5; + brushSize += GetMouseWheelMove() * 5; if (brushSize < 2) brushSize = 2; if (brushSize > 50) brushSize = 50; - if (IsKeyPressed(KEY_C)) + if (IsKeyPressed(KEY_C)) { // Clear render texture to clear color BeginTextureMode(target); @@ -118,19 +119,29 @@ int main(void) if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) { - colorSelected = 0; - + if (!mouseWasPressed) + { + colorSelectedPrev = colorSelected; + colorSelected = 0; + } + + mouseWasPressed = true; + // Erase circle from render texture BeginTextureMode(target); if (mousePos.y > 50) DrawCircle(mousePos.x, mousePos.y, brushSize, colors[0]); EndTextureMode(); } - else colorSelected = colorSelectedPrev; - + else if (IsMouseButtonReleased(MOUSE_RIGHT_BUTTON) && mouseWasPressed) + { + colorSelected = colorSelectedPrev; + mouseWasPressed = false; + } + // Check mouse hover save button if (CheckCollisionPointRec(mousePos, btnSaveRec)) btnSaveMouseHover = true; else btnSaveMouseHover = false; - + // Image saving logic // NOTE: Saving painted texture to a default named image if ((btnSaveMouseHover && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) || IsKeyPressed(KEY_S)) @@ -141,7 +152,7 @@ int main(void) UnloadImage(image); showSaveMessage = true; } - + if (showSaveMessage) { // On saving, show a full screen message for 2 seconds @@ -158,42 +169,44 @@ int main(void) //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + ClearBackground(RAYWHITE); - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); + // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) + DrawTextureRec(target.texture, (Rectangle) { 0, 0, target.texture.width, -target.texture.height }, (Vector2) { 0, 0 }, WHITE); - // Draw drawing circle for reference - if (mousePos.y > 50) - { - if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) DrawCircleLines(mousePos.x, mousePos.y, brushSize, GRAY); - else DrawCircle(GetMouseX(), GetMouseY(), brushSize, colors[colorSelected]); - } - - // Draw top panel - DrawRectangle(0, 0, GetScreenWidth(), 50, RAYWHITE); - DrawLine(0, 50, GetScreenWidth(), 50, LIGHTGRAY); + // Draw drawing circle for reference + if (mousePos.y > 50) + { + if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) DrawCircleLines(mousePos.x, mousePos.y, brushSize, GRAY); + else DrawCircle(GetMouseX(), GetMouseY(), brushSize, colors[colorSelected]); + } - // Draw color selection rectangles - for (int i = 0; i < MAX_COLORS_COUNT; i++) DrawRectangleRec(colorsRecs[i], colors[i]); - DrawRectangleLines(10, 10, 30, 30, LIGHTGRAY); + // Draw top panel + DrawRectangle(0, 0, GetScreenWidth(), 50, RAYWHITE); + DrawLine(0, 50, GetScreenWidth(), 50, LIGHTGRAY); - if (colorMouseHover >= 0) DrawRectangleRec(colorsRecs[colorMouseHover], Fade(WHITE, 0.6f)); + // Draw color selection rectangles + for (int i = 0; i < MAX_COLORS_COUNT; i++) DrawRectangleRec(colorsRecs[i], colors[i]); + DrawRectangleLines(10, 10, 30, 30, LIGHTGRAY); - DrawRectangleLinesEx((Rectangle){ colorsRecs[colorSelected].x - 2, colorsRecs[colorSelected].y - 2, - colorsRecs[colorSelected].width + 4, colorsRecs[colorSelected].height + 4 }, 2, BLACK); + if (colorMouseHover >= 0) DrawRectangleRec(colorsRecs[colorMouseHover], Fade(WHITE, 0.6f)); - // Draw save image button - DrawRectangleLinesEx(btnSaveRec, 2, btnSaveMouseHover? RED : BLACK); - DrawText("SAVE!", 755, 20, 10, btnSaveMouseHover? RED : BLACK); - - // Draw save image message - if (showSaveMessage) - { - DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); - DrawRectangle(0, 150, GetScreenWidth(), 80, BLACK); - DrawText("IMAGE SAVED: my_amazing_texture_painting.png", 150, 180, 20, RAYWHITE); - } + DrawRectangleLinesEx((Rectangle) { + colorsRecs[colorSelected].x - 2, colorsRecs[colorSelected].y - 2, + colorsRecs[colorSelected].width + 4, colorsRecs[colorSelected].height + 4 + }, 2, BLACK); + + // Draw save image button + DrawRectangleLinesEx(btnSaveRec, 2, btnSaveMouseHover ? RED : BLACK); + DrawText("SAVE!", 755, 20, 10, btnSaveMouseHover ? RED : BLACK); + + // Draw save image message + if (showSaveMessage) + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); + DrawRectangle(0, 150, GetScreenWidth(), 80, BLACK); + DrawText("IMAGE SAVED: my_amazing_texture_painting.png", 150, 180, 20, RAYWHITE); + } EndDrawing(); //---------------------------------------------------------------------------------- @@ -202,7 +215,7 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- UnloadRenderTexture(target); // Unload render texture - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- From 4604271c6ae82f7d861d12958e9fcf2608058280 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 20 Feb 2021 11:22:32 +0100 Subject: [PATCH 09/51] Code formatting tweaks --- examples/textures/textures_mouse_painting.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/textures/textures_mouse_painting.c b/examples/textures/textures_mouse_painting.c index fed6ece92..e9b876b43 100644 --- a/examples/textures/textures_mouse_painting.c +++ b/examples/textures/textures_mouse_painting.c @@ -35,7 +35,7 @@ int main(void) for (int i = 0; i < MAX_COLORS_COUNT; i++) { - colorsRecs[i].x = 10 + 30 * i + 2 * i; + colorsRecs[i].x = 10 + 30*i + 2*i; colorsRecs[i].y = 10; colorsRecs[i].width = 30; colorsRecs[i].height = 30; @@ -95,7 +95,7 @@ int main(void) } // Change brush size - brushSize += GetMouseWheelMove() * 5; + brushSize += GetMouseWheelMove()*5; if (brushSize < 2) brushSize = 2; if (brushSize > 50) brushSize = 50; @@ -191,10 +191,8 @@ int main(void) if (colorMouseHover >= 0) DrawRectangleRec(colorsRecs[colorMouseHover], Fade(WHITE, 0.6f)); - DrawRectangleLinesEx((Rectangle) { - colorsRecs[colorSelected].x - 2, colorsRecs[colorSelected].y - 2, - colorsRecs[colorSelected].width + 4, colorsRecs[colorSelected].height + 4 - }, 2, BLACK); + DrawRectangleLinesEx((Rectangle){ colorsRecs[colorSelected].x - 2, colorsRecs[colorSelected].y - 2, + colorsRecs[colorSelected].width + 4, colorsRecs[colorSelected].height + 4 }, 2, BLACK); // Draw save image button DrawRectangleLinesEx(btnSaveRec, 2, btnSaveMouseHover ? RED : BLACK); From eb47cc5e93de9ffa1457e503a1e80bf3dbaaa423 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sat, 20 Feb 2021 10:42:32 -0800 Subject: [PATCH 10/51] Fix warnings generated by Visual Studio 2019 in new model loading code. (#1600) Co-authored-by: Jeffery Myers --- src/models.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/models.c b/src/models.c index f4b79e395..f4c6a9c97 100644 --- a/src/models.c +++ b/src/models.c @@ -3723,7 +3723,7 @@ static Model LoadGLTF(const char *fileName) model.materialCount = (int)data->materials_count + 1; model.materials = RL_MALLOC(model.materialCount*sizeof(Material)); model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int)); - model.boneCount = data->nodes_count; + model.boneCount = (int)data->nodes_count; model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo)); model.bindPose = RL_CALLOC(model.boneCount, sizeof(Transform)); @@ -3733,7 +3733,7 @@ static Model LoadGLTF(const char *fileName) for (unsigned int j = 0; j < data->nodes_count; j++) { strcpy(model.bones[j].name, data->nodes[j].name == 0 ? "ANIMJOINT" : data->nodes[j].name); - model.bones[j].parent = (j != 0 && data->nodes[j].parent != NULL) ? data->nodes[j].parent - data->nodes : 0; + model.bones[j].parent = (int)((j != 0 && data->nodes[j].parent != NULL) ? data->nodes[j].parent - data->nodes : 0); } for (unsigned int i = 0; i < data->nodes_count; i++) @@ -3875,7 +3875,7 @@ static Model LoadGLTF(const char *fileName) else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_normal) { cgltf_accessor *acc = data->meshes[i].primitives[p].attributes[j].data; - int bufferSize = acc->count*3*sizeof(float); + int bufferSize = (int)(acc->count*3*sizeof(float)); model.meshes[primitiveIndex].normals = RL_MALLOC(bufferSize); model.meshes[primitiveIndex].animNormals = RL_MALLOC(bufferSize); @@ -4064,7 +4064,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo for (unsigned int i = 0; i < animation->channels_count; i++) { cgltf_animation_channel* channel = animation->channels + i; - int frameCounts = channel->sampler->input->count; + int frameCounts = (int)channel->sampler->input->count; float lastFrameTime = 0.0f; if (GltfReadFloat(channel->sampler->input, frameCounts - 1, &lastFrameTime, 1)) { @@ -4073,7 +4073,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo } output->frameCount = (int)(animationDuration / TIMESTEP); - output->boneCount = data->nodes_count; + output->boneCount = (int)data->nodes_count; output->bones = RL_MALLOC(output->boneCount*sizeof(BoneInfo)); output->framePoses = RL_MALLOC(output->frameCount*sizeof(Transform *)); // output->framerate = // TODO: Use framerate instead of const timestep @@ -4106,7 +4106,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo cgltf_animation_channel* channel = animation->channels + channelId; cgltf_animation_sampler* sampler = channel->sampler; - int boneId = channel->target_node - data->nodes; + int boneId = (int)(channel->target_node - data->nodes); for (int frame = 0; frame < output->frameCount; frame++) { From 0726491ef864176f9b15ab1dbd22b88293a3d3c9 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sat, 20 Feb 2021 12:13:20 -0800 Subject: [PATCH 11/51] Fixes to make rnet and it's examples build on Windows in visual studio 2019. (#1602) Mostly typecasts, and some int to unsigned short changes, and including the windsock 2 library in the examples. Co-authored-by: Jeffery Myers --- examples/network/network_tcp_client.c | 6 +++--- examples/network/network_tcp_server.c | 6 +++--- examples/network/network_udp_client.c | 6 +++--- examples/network/network_udp_server.c | 6 +++--- .../VS2019/examples/network_ping_pong.vcxproj | 16 ++++++++-------- .../VS2019/examples/network_resolve_host.vcxproj | 16 ++++++++-------- .../VS2019/examples/network_tcp_client.vcxproj | 16 ++++++++-------- .../VS2019/examples/network_tcp_server.vcxproj | 16 ++++++++-------- projects/VS2019/examples/network_test.vcxproj | 16 ++++++++-------- .../VS2019/examples/network_udp_client.vcxproj | 16 ++++++++-------- .../VS2019/examples/network_udp_server.vcxproj | 16 ++++++++-------- src/rnet.h | 16 ++++++++++------ 12 files changed, 78 insertions(+), 74 deletions(-) diff --git a/examples/network/network_tcp_client.c b/examples/network/network_tcp_client.c index 4259e25d7..b2daab48f 100644 --- a/examples/network/network_tcp_client.c +++ b/examples/network/network_tcp_client.c @@ -80,7 +80,7 @@ int main(void) // IsSocketReady, if the socket is ready, attempt to receive data from the socket int bytesRecv = 0; - if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, strlen(pingmsg) + 1); + if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1); // If we received data, was that data a "Ping!" or a "Pong!" if (bytesRecv > 0) @@ -96,12 +96,12 @@ int main(void) if (ping) { ping = false; - SocketSend(clientResult->socket, pingmsg, strlen(pingmsg) + 1); + SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1); } else if (pong) { pong = false; - SocketSend(clientResult->socket, pongmsg, strlen(pingmsg) + 1); + SocketSend(clientResult->socket, pongmsg, (int)strlen(pingmsg) + 1); } elapsed = 0.0f; diff --git a/examples/network/network_tcp_server.c b/examples/network/network_tcp_server.c index ee64acfc0..3e1942c57 100644 --- a/examples/network/network_tcp_server.c +++ b/examples/network/network_tcp_server.c @@ -94,7 +94,7 @@ int main(void) // IsSocketReady, if the socket is ready, attempt to receive data from the socket int bytesRecv = 0; - if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, strlen(pingmsg) + 1); + if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, (int)strlen(pingmsg) + 1); // If we received data, was that data a "Ping!" or a "Pong!" if (bytesRecv > 0) @@ -110,12 +110,12 @@ int main(void) if (ping) { ping = false; - SocketSend(connection, pingmsg, strlen(pingmsg) + 1); + SocketSend(connection, pingmsg, (int)strlen(pingmsg) + 1); } else if (pong) { pong = false; - SocketSend(connection, pongmsg, strlen(pingmsg) + 1); + SocketSend(connection, pongmsg, (int)strlen(pingmsg) + 1); } elapsed = 0.0f; diff --git a/examples/network/network_udp_client.c b/examples/network/network_udp_client.c index 74a241b67..680ed00e5 100644 --- a/examples/network/network_udp_client.c +++ b/examples/network/network_udp_client.c @@ -73,7 +73,7 @@ int main(void) // IsSocketReady, if the socket is ready, attempt to receive data from the socket int bytesRecv = 0; - if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, strlen(pingmsg) + 1); + if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1); // If we received data, was that data a "Ping!" or a "Pong!" if (bytesRecv > 0) @@ -89,12 +89,12 @@ int main(void) if (ping) { ping = false; - SocketSend(clientResult->socket, pingmsg, strlen(pingmsg) + 1); + SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1); } else if (pong) { pong = false; - SocketSend(clientResult->socket, pongmsg, strlen(pongmsg) + 1); + SocketSend(clientResult->socket, pongmsg, (int)strlen(pongmsg) + 1); } elapsed = 0.0f; diff --git a/examples/network/network_udp_server.c b/examples/network/network_udp_server.c index 5d5c425e8..f32189c29 100644 --- a/examples/network/network_udp_server.c +++ b/examples/network/network_udp_server.c @@ -76,7 +76,7 @@ int main(void) // if (IsSocketReady(serverResult->socket)) { // bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, msglen); // } - int bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, strlen(pingmsg) + 1); + int bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1); // If we received data, is that data a "Ping!" or a "Pong!"? if (bytesRecv > 0) @@ -93,12 +93,12 @@ int main(void) if (ping) { ping = false; - SocketSend(serverResult->socket, pingmsg, strlen(pingmsg) + 1); + SocketSend(serverResult->socket, pingmsg, (int)strlen(pingmsg) + 1); } else if (pong) { pong = false; - SocketSend(serverResult->socket, pongmsg, strlen(pongmsg) + 1); + SocketSend(serverResult->socket, pongmsg, (int)strlen(pongmsg) + 1); } elapsed = 0.0f; diff --git a/projects/VS2019/examples/network_ping_pong.vcxproj b/projects/VS2019/examples/network_ping_pong.vcxproj index 0a1d5f108..a03a68325 100644 --- a/projects/VS2019/examples/network_ping_pong.vcxproj +++ b/projects/VS2019/examples/network_ping_pong.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_resolve_host.vcxproj b/projects/VS2019/examples/network_resolve_host.vcxproj index a47a8384f..c8888dca1 100644 --- a/projects/VS2019/examples/network_resolve_host.vcxproj +++ b/projects/VS2019/examples/network_resolve_host.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_tcp_client.vcxproj b/projects/VS2019/examples/network_tcp_client.vcxproj index f78214bd2..8ce75f649 100644 --- a/projects/VS2019/examples/network_tcp_client.vcxproj +++ b/projects/VS2019/examples/network_tcp_client.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_tcp_server.vcxproj b/projects/VS2019/examples/network_tcp_server.vcxproj index 88e6d0c4b..329c1cb03 100644 --- a/projects/VS2019/examples/network_tcp_server.vcxproj +++ b/projects/VS2019/examples/network_tcp_server.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_test.vcxproj b/projects/VS2019/examples/network_test.vcxproj index 41591e738..d0db579f8 100644 --- a/projects/VS2019/examples/network_test.vcxproj +++ b/projects/VS2019/examples/network_test.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_udp_client.vcxproj b/projects/VS2019/examples/network_udp_client.vcxproj index 8d87423b1..1672c36d6 100644 --- a/projects/VS2019/examples/network_udp_client.vcxproj +++ b/projects/VS2019/examples/network_udp_client.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/projects/VS2019/examples/network_udp_server.vcxproj b/projects/VS2019/examples/network_udp_server.vcxproj index 400348a0a..fcef9e944 100644 --- a/projects/VS2019/examples/network_udp_server.vcxproj +++ b/projects/VS2019/examples/network_udp_server.vcxproj @@ -210,7 +210,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -228,7 +228,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -245,7 +245,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -266,7 +266,7 @@ Console true $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" @@ -291,7 +291,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -313,7 +313,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -335,7 +335,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ @@ -363,7 +363,7 @@ true true true - raylib.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + raylib.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ diff --git a/src/rnet.h b/src/rnet.h index 1145df01b..7ed29b15b 100644 --- a/src/rnet.h +++ b/src/rnet.h @@ -231,11 +231,15 @@ typedef int socklen_t; //---------------------------------------------------------------------------------- // Boolean type +#ifdef _WIN32 + #include +#else #if defined(__STDC__) && __STDC_VERSION__ >= 199901L #include #elif !defined(__cplusplus) && !defined(bool) typedef enum { false, true } bool; #endif +#endif typedef enum { SOCKET_TCP = 0, // SOCK_STREAM @@ -347,7 +351,7 @@ int GetAddressFamily(AddressInformation address); int GetAddressSocketType(AddressInformation address); int GetAddressProtocol(AddressInformation address); char *GetAddressCanonName(AddressInformation address); -char *GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport); +char *GetAddressHostAndPort(AddressInformation address, char *outhost, unsigned short *outport); // Address Memory API AddressInformation LoadAddress(void); @@ -365,7 +369,7 @@ Socket *SocketAccept(Socket *server, SocketConfig *config); int SocketSend(Socket *sock, const void *datap, int len); int SocketReceive(Socket *sock, void *data, int maxlen); SocketAddressStorage SocketGetPeerAddress(Socket *sock); -char *GetSocketAddressHost(SocketAddressStorage storage); +const char *GetSocketAddressHost(SocketAddressStorage storage); short GetSocketAddressPort(SocketAddressStorage storage); void SocketClose(Socket *sock); @@ -1340,7 +1344,7 @@ bool SocketConnect(SocketConfig *config, SocketResult *result) ip4addr.sin_family = AF_INET; unsigned long hport; hport = strtoul(config->port, NULL, 0); - ip4addr.sin_port = htons(hport); + ip4addr.sin_port = (unsigned short)(hport); // TODO: Changed the code to avoid the usage of inet_pton and inet_ntop replacing them with getnameinfo (that should have a better support on windows). @@ -1376,7 +1380,7 @@ bool SocketConnect(SocketConfig *config, SocketResult *result) ip6addr.sin6_family = AF_INET6; unsigned long hport; hport = strtoul(config->port, NULL, 0); - ip6addr.sin6_port = htons(hport); + ip6addr.sin6_port = htons((unsigned short)hport); //inet_pton(AF_INET6, config->host, &ip6addr.sin6_addr); // TODO. int connect_result = connect(result->socket->channel, (struct sockaddr *)&ip6addr, sizeof(ip6addr)); @@ -1439,7 +1443,7 @@ SocketAddressStorage SocketGetPeerAddress(Socket *sock) } // Return the address-type appropriate host portion of a socket address -char *GetSocketAddressHost(SocketAddressStorage storage) +const char *GetSocketAddressHost(SocketAddressStorage storage) { assert(storage->address.ss_family == AF_INET || storage->address.ss_family == AF_INET6); return SocketAddressToString((struct sockaddr_storage *)storage); @@ -2117,7 +2121,7 @@ char *GetAddressCanonName(AddressInformation address) } // Opaque datatype accessor addrinfo->ai_addr -char *GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport) +char *GetAddressHostAndPort(AddressInformation address, char *outhost, unsigned short *outport) { //char *ip[INET6_ADDRSTRLEN]; char *result = NULL; From 82cdd88ffe6cb9d2f97e34bd0724d791030372bf Mon Sep 17 00:00:00 2001 From: Paul Jurczak Date: Sat, 20 Feb 2021 15:35:43 -0700 Subject: [PATCH 12/51] Fixed DrawLineEx (#1598) * Fixed DrawLineEx Corrected the issue https://github.com/raysan5/raylib/issues/1596 * Removed raymath dependency for DrawLineEx --- src/shapes.c | 47 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/src/shapes.c b/src/shapes.c index fc4bddc02..0f5e4d5c9 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -116,45 +116,18 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color) // Draw a line defining thickness void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color) { - if (startPos.x > endPos.x) + Vector2 delta = {endPos.x-startPos.x, endPos.y-startPos.y}; + float length = sqrtf(delta.x*delta.x + delta.y*delta.y); + + if (length > 0 && thick > 0) { - Vector2 tempPos = startPos; - startPos = endPos; - endPos = tempPos; + float scale = thick/(2*length); + Vector2 radius = {-scale*delta.y, scale*delta.x}; + Vector2 strip[] = {{startPos.x-radius.x, startPos.y-radius.y}, {startPos.x+radius.x, startPos.y+radius.y}, + {endPos.x-radius.x, endPos.y-radius.y}, {endPos.x+radius.x, endPos.y+radius.y}}; + + DrawTriangleStrip(strip, 4, color); } - - float dx = endPos.x - startPos.x; - float dy = endPos.y - startPos.y; - - float d = sqrtf(dx*dx + dy*dy); - float angle = asinf(dy/d); - - rlEnableTexture(GetShapesTexture().id); - - rlPushMatrix(); - rlTranslatef((float)startPos.x, (float)startPos.y, 0.0f); - rlRotatef(RAD2DEG*angle, 0.0f, 0.0f, 1.0f); - rlTranslatef(0, (thick > 1.0f)? -thick/2.0f : -1.0f, 0.0f); - - rlBegin(RL_QUADS); - rlColor4ub(color.r, color.g, color.b, color.a); - rlNormal3f(0.0f, 0.0f, 1.0f); - - rlTexCoord2f(GetShapesTextureRec().x/GetShapesTexture().width, GetShapesTextureRec().y/GetShapesTexture().height); - rlVertex2f(0.0f, 0.0f); - - rlTexCoord2f(GetShapesTextureRec().x/GetShapesTexture().width, (GetShapesTextureRec().y + GetShapesTextureRec().height)/GetShapesTexture().height); - rlVertex2f(0.0f, thick); - - rlTexCoord2f((GetShapesTextureRec().x + GetShapesTextureRec().width)/GetShapesTexture().width, (GetShapesTextureRec().y + GetShapesTextureRec().height)/GetShapesTexture().height); - rlVertex2f(d, thick); - - rlTexCoord2f((GetShapesTextureRec().x + GetShapesTextureRec().width)/GetShapesTexture().width, GetShapesTextureRec().y/GetShapesTexture().height); - rlVertex2f(d, 0.0f); - rlEnd(); - rlPopMatrix(); - - rlDisableTexture(); } // Draw line using cubic-bezier curves in-out From 48a7cd3c8788799505b4fa9f84cb8f5979397c29 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sat, 20 Feb 2021 14:37:32 -0800 Subject: [PATCH 13/51] [Examples] Fix typecast warnings in examples. (#1601) * Fixing typecast warnings generated by visual studio 2019 in examples. * Changes to fixes based on feedback Co-authored-by: Jeffery Myers --- examples/audio/audio_module_playing.c | 12 +++++------ examples/audio/audio_multichannel_sound.c | 2 +- examples/audio/audio_raw_stream.c | 4 ++-- examples/core/core_2d_camera.c | 18 ++++++++-------- examples/core/core_2d_camera_platformer.c | 10 ++++----- examples/core/core_3d_camera_first_person.c | 2 +- examples/core/core_3d_picking.c | 2 +- examples/others/easings.h | 24 ++++++++++----------- examples/others/raudio_standalone.c | 5 ++++- examples/others/rlgl_standalone.c | 14 ++++++------ examples/textures/textures_image_drawing.c | 6 +++--- examples/textures/textures_rectangle.c | 2 +- examples/textures/textures_srcrec_dstrec.c | 6 +++--- src/raymath.h | 2 +- src/rlgl.h | 2 +- 15 files changed, 57 insertions(+), 54 deletions(-) diff --git a/examples/audio/audio_module_playing.c b/examples/audio/audio_module_playing.c index 9a85cbc0e..3c10e0698 100644 --- a/examples/audio/audio_module_playing.c +++ b/examples/audio/audio_module_playing.c @@ -43,9 +43,9 @@ int main(void) for (int i = MAX_CIRCLES - 1; i >= 0; i--) { circles[i].alpha = 0.0f; - circles[i].radius = GetRandomValue(10, 40); - circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius); - circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius); + circles[i].radius = (float)GetRandomValue(10, 40); + circles[i].position.x = (float)GetRandomValue((int)circles[i].radius, (int)(screenWidth - circles[i].radius)); + circles[i].position.y = (float)GetRandomValue((int)circles[i].radius, (int)(screenHeight - circles[i].radius)); circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f; circles[i].color = colors[GetRandomValue(0, 13)]; } @@ -104,9 +104,9 @@ int main(void) if (circles[i].alpha <= 0.0f) { circles[i].alpha = 0.0f; - circles[i].radius = GetRandomValue(10, 40); - circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius); - circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius); + circles[i].radius = (float)GetRandomValue(10, 40); + circles[i].position.x = (float)GetRandomValue((int)circles[i].radius, (int)(screenWidth - circles[i].radius)); + circles[i].position.y = (float)GetRandomValue((int)circles[i].radius, (int)(screenHeight - circles[i].radius)); circles[i].color = colors[GetRandomValue(0, 13)]; circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f; } diff --git a/examples/audio/audio_multichannel_sound.c b/examples/audio/audio_multichannel_sound.c index b9a76f9d7..223680933 100644 --- a/examples/audio/audio_multichannel_sound.c +++ b/examples/audio/audio_multichannel_sound.c @@ -27,7 +27,7 @@ int main(void) Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file - SetSoundVolume(fxWav, 0.2); + SetSoundVolume(fxWav, 0.2f); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- diff --git a/examples/audio/audio_raw_stream.c b/examples/audio/audio_raw_stream.c index 1130eae04..219739b6a 100644 --- a/examples/audio/audio_raw_stream.c +++ b/examples/audio/audio_raw_stream.c @@ -140,8 +140,8 @@ int main(void) // Draw the current buffer state proportionate to the screen for (int i = 0; i < screenWidth; i++) { - position.x = i; - position.y = 250 + 50*data[i*MAX_SAMPLES/screenWidth]/32000; + position.x = (float)i; + position.y = 250 + 50*data[i*MAX_SAMPLES/screenWidth]/32000.0f; DrawPixelV(position, RED); } diff --git a/examples/core/core_2d_camera.c b/examples/core/core_2d_camera.c index d6c85079e..0b4754f7e 100644 --- a/examples/core/core_2d_camera.c +++ b/examples/core/core_2d_camera.c @@ -30,19 +30,19 @@ int main(void) for (int i = 0; i < MAX_BUILDINGS; i++) { - buildings[i].width = GetRandomValue(50, 200); - buildings[i].height = GetRandomValue(100, 800); - buildings[i].y = screenHeight - 130 - buildings[i].height; - buildings[i].x = -6000 + spacing; + buildings[i].width = (float)GetRandomValue(50, 200); + buildings[i].height = (float)GetRandomValue(100, 800); + buildings[i].y = screenHeight - 130.0f - buildings[i].height; + buildings[i].x = -6000.0f + spacing; - spacing += buildings[i].width; + spacing += (int)buildings[i].width; buildColors[i] = (Color){ GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255 }; } Camera2D camera = { 0 }; - camera.target = (Vector2){ player.x + 20, player.y + 20 }; - camera.offset = (Vector2){ screenWidth/2, screenHeight/2 }; + camera.target = (Vector2){ player.x + 20.0f, player.y + 20.0f }; + camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f }; camera.rotation = 0.0f; camera.zoom = 1.0f; @@ -98,8 +98,8 @@ int main(void) DrawRectangleRec(player, RED); - DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, GREEN); - DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, GREEN); + DrawLine((int)camera.target.x, -screenHeight*10, (int)camera.target.x, screenHeight*10, GREEN); + DrawLine(-screenWidth*10, (int)camera.target.y, screenWidth*10, (int)camera.target.y, GREEN); EndMode2D(); diff --git a/examples/core/core_2d_camera_platformer.c b/examples/core/core_2d_camera_platformer.c index 645c317f1..db8c9f452 100644 --- a/examples/core/core_2d_camera_platformer.c +++ b/examples/core/core_2d_camera_platformer.c @@ -65,7 +65,7 @@ int main(void) Camera2D camera = { 0 }; camera.target = player.position; - camera.offset = (Vector2){ screenWidth/2, screenHeight/2 }; + camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f }; camera.rotation = 0.0f; camera.zoom = 1.0f; @@ -191,14 +191,14 @@ void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float d void UpdateCameraCenter(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height) { - camera->offset = (Vector2){ width/2, height/2 }; + camera->offset = (Vector2){ width/2.0f, height/2.0f }; camera->target = player->position; } void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height) { camera->target = player->position; - camera->offset = (Vector2){ width/2, height/2 }; + camera->offset = (Vector2){ width/2.0f, height/2.0f }; float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000; for (int i = 0; i < envItemsLength; i++) @@ -225,7 +225,7 @@ void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *e static float minEffectLength = 10; static float fractionSpeed = 0.8f; - camera->offset = (Vector2){ width/2, height/2 }; + camera->offset = (Vector2){ width/2.0f, height/2.0f }; Vector2 diff = Vector2Subtract(player->position, camera->target); float length = Vector2Length(diff); @@ -242,7 +242,7 @@ void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *env static int eveningOut = false; static float evenOutTarget; - camera->offset = (Vector2){ width/2, height/2 }; + camera->offset = (Vector2){ width/2.0f, height/2.0f }; camera->target.x = player->position.x; if (eveningOut) diff --git a/examples/core/core_3d_camera_first_person.c b/examples/core/core_3d_camera_first_person.c index 9225991a0..3377aeaf5 100644 --- a/examples/core/core_3d_camera_first_person.c +++ b/examples/core/core_3d_camera_first_person.c @@ -38,7 +38,7 @@ int main(void) for (int i = 0; i < MAX_COLUMNS; i++) { heights[i] = (float)GetRandomValue(1, 12); - positions[i] = (Vector3){ GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) }; + positions[i] = (Vector3){ (float)GetRandomValue(-15, 15), heights[i]/2.0f, (float)GetRandomValue(-15, 15) }; colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 }; } diff --git a/examples/core/core_3d_picking.c b/examples/core/core_3d_picking.c index baf35036e..01fe2b550 100644 --- a/examples/core/core_3d_picking.c +++ b/examples/core/core_3d_picking.c @@ -90,7 +90,7 @@ int main(void) DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); - if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); + if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN); DrawFPS(10, 10); diff --git a/examples/others/easings.h b/examples/others/easings.h index f6c384b00..216178260 100644 --- a/examples/others/easings.h +++ b/examples/others/easings.h @@ -112,12 +112,12 @@ EASEDEF float EaseSineOut(float t, float b, float c, float d) { return (c*sinf(t EASEDEF float EaseSineInOut(float t, float b, float c, float d) { return (-c/2.0f*(cosf(PI*t/d) - 1.0f) + b); } // Circular Easing functions -EASEDEF float EaseCircIn(float t, float b, float c, float d) { t /= d; return (-c*(sqrt(1.0f - t*t) - 1.0f) + b); } -EASEDEF float EaseCircOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*sqrt(1.0f - t*t) + b); } +EASEDEF float EaseCircIn(float t, float b, float c, float d) { t /= d; return (-c*(sqrtf(1.0f - t*t) - 1.0f) + b); } +EASEDEF float EaseCircOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*sqrtf(1.0f - t*t) + b); } EASEDEF float EaseCircInOut(float t, float b, float c, float d) { - if ((t/=d/2.0f) < 1.0f) return (-c/2.0f*(sqrt(1.0f - t*t) - 1.0f) + b); - t -= 2.0f; return (c/2.0f*(sqrt(1.0f - t*t) + 1.0f) + b); + if ((t/=d/2.0f) < 1.0f) return (-c/2.0f*(sqrtf(1.0f - t*t) - 1.0f) + b); + t -= 2.0f; return (c/2.0f*(sqrtf(1.0f - t*t) + 1.0f) + b); } // Cubic Easing functions @@ -139,15 +139,15 @@ EASEDEF float EaseQuadInOut(float t, float b, float c, float d) } // Exponential Easing functions -EASEDEF float EaseExpoIn(float t, float b, float c, float d) { return (t == 0.0f) ? b : (c*pow(2.0f, 10.0f*(t/d - 1.0f)) + b); } -EASEDEF float EaseExpoOut(float t, float b, float c, float d) { return (t == d) ? (b + c) : (c*(-pow(2.0f, -10.0f*t/d) + 1.0f) + b); } +EASEDEF float EaseExpoIn(float t, float b, float c, float d) { return (t == 0.0f) ? b : (c * powf(2.0f, 10.0f*(t/d - 1.0f)) + b); } +EASEDEF float EaseExpoOut(float t, float b, float c, float d) { return (t == d) ? (b + c) : (c * (-powf(2.0f, -10.0f*t/d) + 1.0f) + b); } EASEDEF float EaseExpoInOut(float t, float b, float c, float d) { if (t == 0.0f) return b; if (t == d) return (b + c); - if ((t/=d/2.0f) < 1.0f) return (c/2.0f*pow(2.0f, 10.0f*(t - 1.0f)) + b); + if ((t/=d/2.0f) < 1.0f) return (c/2.0f* powf(2.0f, 10.0f*(t - 1.0f)) + b); - return (c/2.0f*(-pow(2.0f, -10.0f*(t - 1.0f)) + 2.0f) + b); + return (c/2.0f*(-powf(2.0f, -10.0f*(t - 1.0f)) + 2.0f) + b); } // Back Easing functions @@ -219,7 +219,7 @@ EASEDEF float EaseElasticIn(float t, float b, float c, float d) float p = d*0.3f; float a = c; float s = p/4.0f; - float postFix = a*pow(2.0f, 10.0f*(t-=1.0f)); + float postFix = a*powf(2.0f, 10.0f*(t-=1.0f)); return (-(postFix*sinf((t*d-s)*(2.0f*PI)/p )) + b); } @@ -233,7 +233,7 @@ EASEDEF float EaseElasticOut(float t, float b, float c, float d) float a = c; float s = p/4.0f; - return (a*pow(2.0f,-10.0f*t)*sinf((t*d-s)*(2.0f*PI)/p) + c + b); + return (a*powf(2.0f,-10.0f*t)*sinf((t*d-s)*(2.0f*PI)/p) + c + b); } EASEDEF float EaseElasticInOut(float t, float b, float c, float d) @@ -247,11 +247,11 @@ EASEDEF float EaseElasticInOut(float t, float b, float c, float d) if (t < 1.0f) { - float postFix = a*pow(2.0f, 10.0f*(t-=1.0f)); + float postFix = a*powf(2.0f, 10.0f*(t-=1.0f)); return -0.5f*(postFix*sinf((t*d-s)*(2.0f*PI)/p)) + b; } - float postFix = a*pow(2.0f, -10.0f*(t-=1.0f)); + float postFix = a*powf(2.0f, -10.0f*(t-=1.0f)); return (postFix*sinf((t*d-s)*(2.0f*PI)/p)*0.5f + c + b); } diff --git a/examples/others/raudio_standalone.c b/examples/others/raudio_standalone.c index 224286d36..42a336ecb 100644 --- a/examples/others/raudio_standalone.c +++ b/examples/others/raudio_standalone.c @@ -61,9 +61,12 @@ //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- -#if !defined(_WIN32) +#if !defined(_MSC_VER) static int kbhit(void); // Check if a key has been pressed static char getch(); // Get pressed character +#else +#define kbhit _kbhit +#define getch _getch #endif //------------------------------------------------------------------------------------ diff --git a/examples/others/rlgl_standalone.c b/examples/others/rlgl_standalone.c index 9aea2b478..b1e2e735e 100644 --- a/examples/others/rlgl_standalone.c +++ b/examples/others/rlgl_standalone.c @@ -57,7 +57,7 @@ #define GLFW_INCLUDE_ES2 #endif -#include // Windows/Context and inputs management +#include "GLFW/glfw3.h" // Windows/Context and inputs management #include // Required for: printf() @@ -246,13 +246,13 @@ static void DrawRectangleV(Vector2 position, Vector2 size, Color color) rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2i(position.x, position.y); - rlVertex2i(position.x, position.y + size.y); - rlVertex2i(position.x + size.x, position.y + size.y); + rlVertex2f(position.x, position.y); + rlVertex2f(position.x, position.y + size.y); + rlVertex2f(position.x + size.x, position.y + size.y); - rlVertex2i(position.x, position.y); - rlVertex2i(position.x + size.x, position.y + size.y); - rlVertex2i(position.x + size.x, position.y); + rlVertex2f(position.x, position.y); + rlVertex2f(position.x + size.x, position.y + size.y); + rlVertex2f(position.x + size.x, position.y); rlEnd(); } diff --git a/examples/textures/textures_image_drawing.c b/examples/textures/textures_image_drawing.c index 6e794582d..ea3cb319f 100644 --- a/examples/textures/textures_image_drawing.c +++ b/examples/textures/textures_image_drawing.c @@ -32,8 +32,8 @@ int main(void) Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) // Draw one image over the other with a scaling of 1.5f - ImageDraw(&parrots, cat, (Rectangle){ 0, 0, cat.width, cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f }, WHITE); - ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image + ImageDraw(&parrots, cat, (Rectangle){ 0, 0, (float)cat.width, (float)cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f }, WHITE); + ImageCrop(&parrots, (Rectangle){ 0, 50, (float)parrots.width, (float)parrots.height - 100 }); // Crop resulting image // Draw on the image with a few image draw methods ImageDrawPixel(&parrots, 10, 10, RAYWHITE); @@ -46,7 +46,7 @@ int main(void) Font font = LoadFont("resources/custom_jupiter_crash.png"); // Draw over image using custom font - ImageDrawTextEx(&parrots, font, "PARROTS & CAT", (Vector2){ 300, 230 }, font.baseSize, -2, WHITE); + ImageDrawTextEx(&parrots, font, "PARROTS & CAT", (Vector2){ 300, 230 }, (float)font.baseSize, -2, WHITE); UnloadFont(font); // Unload custom spritefont (already drawn used on image) diff --git a/examples/textures/textures_rectangle.c b/examples/textures/textures_rectangle.c index 1665917e5..f0d5105ba 100644 --- a/examples/textures/textures_rectangle.c +++ b/examples/textures/textures_rectangle.c @@ -68,7 +68,7 @@ int main(void) DrawTexture(scarfy, 15, 40, WHITE); DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); - DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); + DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); DrawText(TextFormat("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); diff --git a/examples/textures/textures_srcrec_dstrec.c b/examples/textures/textures_srcrec_dstrec.c index e86b729d6..3fdb689cc 100644 --- a/examples/textures/textures_srcrec_dstrec.c +++ b/examples/textures/textures_srcrec_dstrec.c @@ -28,13 +28,13 @@ int main(void) int frameHeight = scarfy.height; // Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 0.0f, 0.0f, frameWidth, frameHeight }; + Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; // Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; + Rectangle destRec = { screenWidth/2.0f, screenHeight/2.0f, frameWidth*2.0f, frameHeight*2.0f }; // Origin of the texture (rotation/scale point), it's relative to destination rectangle size - Vector2 origin = { frameWidth, frameHeight }; + Vector2 origin = { (float)frameWidth, (float)frameHeight }; int rotation = 0; diff --git a/src/raymath.h b/src/raymath.h index c9848a7fb..63fc96968 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -75,7 +75,7 @@ // Defines and Macros //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #ifndef DEG2RAD diff --git a/src/rlgl.h b/src/rlgl.h index ab23b3abc..3bd79a363 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -4922,7 +4922,7 @@ char *LoadFileText(const char *fileName) if (size > 0) { text = (char *)RL_MALLOC((size + 1)*sizeof(char)); - int count = fread(text, sizeof(char), size, textFile); + int count = (int)fread(text, sizeof(char), size, textFile); // WARNING: \r\n is converted to \n on reading, so, // read bytes count gets reduced by the number of lines From d84a0157253c25860649ab821b919d7633bd64d8 Mon Sep 17 00:00:00 2001 From: RedCubeDev <61469501+RedCubeDev-ByteSpace@users.noreply.github.com> Date: Sun, 21 Feb 2021 10:44:41 +0100 Subject: [PATCH 14/51] Added ReCT Binding (Relib) to the list (#1604) hey! Ive made a Raylib Binding for my Programming language ReCT! Its still a fairly small language (~30 users) but it would be really cool to be featured here, tho I'd completely understand if only relevant languages are allowed on the list --- BINDINGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BINDINGS.md b/BINDINGS.md index 1fdec5672..1be25a978 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -90,6 +90,7 @@ Here it is a list with the ones I'm aware of: | raylib-beef | 3.0 | [Beef](https://www.beeflang.org/) | https://github.com/M0n7y5/raylib-beef | | raylib-never | 3.0 | [Never](https://github.com/never-lang/never) | https://github.com/never-lang/raylib-never | | raylib.cbl | 2.0 | [COBOL](https://en.wikipedia.org/wiki/COBOL) | *[code examples](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)* | +| Relib | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | https://github.com/RedCubeDev-ByteSpace/Relib | Missing some language? Feel free to create a new binding! :) From 34f5532fad68aed9c7df5f11ac76ee5e7d55e9e0 Mon Sep 17 00:00:00 2001 From: Airbus5717 <55999379+Airbus5717@users.noreply.github.com> Date: Sun, 21 Feb 2021 12:45:18 +0300 Subject: [PATCH 15/51] Update BINDINGS.md (#1605) --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 1be25a978..578da3134 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -20,7 +20,7 @@ Here it is a list with the ones I'm aware of: | raylib-goplus | 2.6-dev | [Go](https://golang.org/) | https://github.com/Lachee/raylib-goplus | | ray-go | 2.6-dev | [Go](https://golang.org/) | https://github.com/hecate-tech/ray-go | | go-raylib | 3.5 | [Go](https://golang.org/) | https://github.com/chunqian/go-raylib | -| raylib-rs | 3.0 | [Rust](https://www.rust-lang.org/) | https://github.com/deltaphc/raylib-rs | +| raylib-rs | 3.5 | [Rust](https://www.rust-lang.org/) | https://github.com/deltaphc/raylib-rs | | raylib-lua | 1.7 | [Lua](http://www.lua.org/) | https://github.com/raysan5/raylib-lua | | raylib-lua-ffi | 2.0 | [Lua](http://www.lua.org/) | https://github.com/raysan5/raylib/issues/693 | | raylib-lua-sol | 2.5 | [Lua](http://www.lua.org/) | https://github.com/RobLoach/raylib-lua-sol | From ef8318f5e322aecc8dc4f1f345bada0e2971d731 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 21 Feb 2021 12:09:52 +0100 Subject: [PATCH 16/51] [models] Move vboId ALLOC/FREE to rlgl module #1603 Actually, it seems more logical that rlgl takes care of OpenGL data than the models module... Also, models module loaded vertex data is unloaded by models module. --- src/config.h | 1 + src/models.c | 88 ++++++++++++++++++---------------------------------- src/rlgl.h | 38 ++++++++++------------- 3 files changed, 48 insertions(+), 79 deletions(-) diff --git a/src/config.h b/src/config.h index f73804223..71908b0c0 100644 --- a/src/config.h +++ b/src/config.h @@ -92,6 +92,7 @@ #define DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture) #define MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack +#define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh #define MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported #define MAX_MATERIAL_MAPS 12 // Maximum number of shader maps supported diff --git a/src/models.c b/src/models.c index f4c6a9c97..5c54902a9 100644 --- a/src/models.c +++ b/src/models.c @@ -92,9 +92,7 @@ //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#ifndef DEFAULT_MESH_VERTEX_BUFFERS - #define DEFAULT_MESH_VERTEX_BUFFERS 7 // Number of vertex buffers (VBO) per mesh -#endif +// ... //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -860,8 +858,21 @@ void UploadMesh(Mesh *mesh) // Unload mesh from memory (RAM and/or VRAM) void UnloadMesh(Mesh mesh) { + // Unload rlgl mesh vboId data rlUnloadMesh(mesh); - RL_FREE(mesh.vboId); + + RL_FREE(mesh.vertices); + RL_FREE(mesh.texcoords); + RL_FREE(mesh.normals); + RL_FREE(mesh.colors); + RL_FREE(mesh.tangents); + RL_FREE(mesh.texcoords2); + RL_FREE(mesh.indices); + + RL_FREE(mesh.animVertices); + RL_FREE(mesh.animNormals); + RL_FREE(mesh.boneWeights); + RL_FREE(mesh.boneIds); } // Export mesh data to file @@ -1128,8 +1139,6 @@ Mesh GenMeshPoly(int sides, float radius) if (sides < 3) return mesh; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - int vertexCount = sides*3; // Vertices definition @@ -1186,6 +1195,7 @@ Mesh GenMeshPoly(int sides, float radius) RL_FREE(texcoords); // Upload vertex data to GPU (static mesh) + // NOTE: mesh.vboId array is allocated inside rlLoadMesh() rlLoadMesh(&mesh, false); return mesh; @@ -1195,7 +1205,6 @@ Mesh GenMeshPoly(int sides, float radius) Mesh GenMeshPlane(float width, float length, int resX, int resZ) { Mesh mesh = { 0 }; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); #define CUSTOM_MESH_GEN_PLANE #if defined(CUSTOM_MESH_GEN_PLANE) @@ -1329,7 +1338,6 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) Mesh GenMeshCube(float width, float height, float length) { Mesh mesh = { 0 }; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); #define CUSTOM_MESH_GEN_CUBE #if defined(CUSTOM_MESH_GEN_CUBE) @@ -1498,8 +1506,6 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) if ((rings >= 3) && (slices >= 3)) { - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings); par_shapes_scale(sphere, radius, radius, radius); // NOTE: Soft normals are computed internally @@ -1544,8 +1550,6 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices) { if (radius < 0.0f) radius = 0.0f; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings); par_shapes_scale(sphere, radius, radius, radius); // NOTE: Soft normals are computed internally @@ -1588,8 +1592,6 @@ Mesh GenMeshCylinder(float radius, float height, int slices) if (slices >= 3) { - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - // Instance a cylinder that sits on the Z=0 plane using the given tessellation // levels across the UV domain. Think of "slices" like a number of pizza // slices, and "stacks" like a number of stacked rings. @@ -1653,8 +1655,6 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides) if ((sides >= 3) && (radSeg >= 3)) { - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - if (radius > 1.0f) radius = 1.0f; else if (radius < 0.1f) radius = 0.1f; @@ -1701,8 +1701,6 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides) if ((sides >= 3) && (radSeg >= 3)) { - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - if (radius > 3.0f) radius = 3.0f; else if (radius < 0.5f) radius = 0.5f; @@ -1747,7 +1745,6 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size) #define GRAY_VALUE(c) ((c.r+c.g+c.b)/3) Mesh mesh = { 0 }; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); int mapX = heightmap.width; int mapZ = heightmap.height; @@ -1883,7 +1880,6 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a)) Mesh mesh = { 0 }; - mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); Color *pixels = LoadImageColors(cubicmap); @@ -2842,7 +2838,6 @@ static Model LoadOBJ(const char *fileName) model.meshes[mi].vertices = (float *)RL_CALLOC(model.meshes[mi].vertexCount*3, sizeof(float)); model.meshes[mi].texcoords = (float *)RL_CALLOC(model.meshes[mi].vertexCount*2, sizeof(float)); model.meshes[mi].normals = (float *)RL_CALLOC(model.meshes[mi].vertexCount*3, sizeof(float)); - model.meshes[mi].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); model.meshMaterial[mi] = mi; } @@ -3108,8 +3103,6 @@ static Model LoadIQM(const char *fileName) // NOTE: Animated vertex should be re-uploaded to GPU (if not using GPU skinning) model.meshes[i].animVertices = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float)); model.meshes[i].animNormals = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float)); - - model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); } // Triangles data processing @@ -3726,10 +3719,7 @@ static Model LoadGLTF(const char *fileName) model.boneCount = (int)data->nodes_count; model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo)); model.bindPose = RL_CALLOC(model.boneCount, sizeof(Transform)); - - for (int i = 0; i < model.meshCount; i++) - model.meshes[i].vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); - + for (unsigned int j = 0; j < data->nodes_count; j++) { strcpy(model.bones[j].name, data->nodes[j].name == 0 ? "ANIMJOINT" : data->nodes[j].name); @@ -3738,43 +3728,25 @@ static Model LoadGLTF(const char *fileName) for (unsigned int i = 0; i < data->nodes_count; i++) { - if (data->nodes[i].has_translation) - { - memcpy(&model.bindPose[i].translation, data->nodes[i].translation, 3 * sizeof(float)); - } - else - { - model.bindPose[i].translation = Vector3Zero(); - } - - if (data->nodes[i].has_rotation) - { - memcpy(&model.bindPose[i].rotation, data->nodes[i].rotation, 4 * sizeof(float)); - } - else - { - model.bindPose[i].rotation = QuaternionIdentity(); - } + if (data->nodes[i].has_translation) memcpy(&model.bindPose[i].translation, data->nodes[i].translation, 3 * sizeof(float)); + else model.bindPose[i].translation = Vector3Zero(); + + if (data->nodes[i].has_rotation) memcpy(&model.bindPose[i].rotation, data->nodes[i].rotation, 4 * sizeof(float)); + else model.bindPose[i].rotation = QuaternionIdentity(); + model.bindPose[i].rotation = QuaternionNormalize(model.bindPose[i].rotation); - if (data->nodes[i].has_scale) - { - memcpy(&model.bindPose[i].scale, data->nodes[i].scale, 3 * sizeof(float)); - } - else - { - model.bindPose[i].scale = Vector3One(); - } + if (data->nodes[i].has_scale) memcpy(&model.bindPose[i].scale, data->nodes[i].scale, 3 * sizeof(float)); + else model.bindPose[i].scale = Vector3One(); } for (int i = 0; i < model.boneCount; i++) { - Transform* currentTransform = model.bindPose + i; - BoneInfo* currentBone = model.bones + i; + Transform *currentTransform = model.bindPose + i; + BoneInfo *currentBone = model.bones + i; int root = currentBone->parent; - if (root >= model.boneCount) - root = 0; - Transform* parentTransform = model.bindPose + root; + if (root >= model.boneCount) root = 0; + Transform *parentTransform = model.bindPose + root; if (currentBone->parent >= 0) { @@ -3791,7 +3763,7 @@ static Model LoadGLTF(const char *fileName) Color tint = (Color){ 255, 255, 255, 255 }; const char *texPath = GetDirectoryPath(fileName); - //Ensure material follows raylib support for PBR (metallic/roughness flow) + // Ensure material follows raylib support for PBR (metallic/roughness flow) if (data->materials[i].has_pbr_metallic_roughness) { tint.r = (unsigned char)(data->materials[i].pbr_metallic_roughness.base_color_factor[0] * 255); diff --git a/src/rlgl.h b/src/rlgl.h index 3bd79a363..a543c40f8 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -158,6 +158,11 @@ #define MAX_MATRIX_STACK_SIZE 32 // Maximum size of Matrix stack #endif +// Vertex buffers id limit +#ifndef MAX_MESH_VERTEX_BUFFERS + #define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh +#endif + // Shader and material limits #ifndef MAX_SHADER_LOCATIONS #define MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported @@ -2420,9 +2425,9 @@ void rlGenerateMipmaps(Texture2D *texture) if (texture->format == UNCOMPRESSED_R8G8B8A8) { // Retrieve texture data from VRAM - void *data = rlReadTexturePixels(*texture); + void *texData = rlReadTexturePixels(*texture); - // NOTE: data size is reallocated to fit mipmaps data + // NOTE: Texture data size is reallocated to fit mipmaps data // NOTE: CPU mipmap generation only supports RGBA 32bit data int mipmapCount = GenerateMipmaps(data, texture->width, texture->height); @@ -2435,7 +2440,7 @@ void rlGenerateMipmaps(Texture2D *texture) // Load the mipmaps for (int level = 1; level < mipmapCount; level++) { - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, mipWidth, mipHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data + offset); + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, mipWidth, mipHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)texData + offset); size = mipWidth*mipHeight*4; offset += size; @@ -2445,7 +2450,7 @@ void rlGenerateMipmaps(Texture2D *texture) } texture->mipmaps = mipmapCount + 1; - RL_FREE(data); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data + RL_FREE(texData); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Mipmaps generated manually on CPU side, total: %i", texture->id, texture->mipmaps); } @@ -2481,6 +2486,8 @@ void rlLoadMesh(Mesh *mesh, bool dynamic) TRACELOG(LOG_WARNING, "VAO: [ID %i] Trying to re-load an already loaded mesh", mesh->vaoId); return; } + + mesh->vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); mesh->vaoId = 0; // Vertex Array Object mesh->vboId[0] = 0; // Vertex positions VBO @@ -2952,9 +2959,9 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c glUniformMatrix4fv(material.shader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(MatrixMultiply(MatrixMultiply(RLGL.State.transform, RLGL.State.modelview), RLGL.State.projection))); - float16* instances = RL_MALLOC(count*sizeof(float16)); + float16* instanceTransforms = RL_MALLOC(count*sizeof(float16)); - for (int i = 0; i < count; i++) instances[i] = MatrixToFloatV(transforms[i]); + for (int i = 0; i < count; i++) instanceTransforms[i] = MatrixToFloatV(transforms[i]); // This could alternatively use a static VBO and either glMapBuffer or glBufferSubData. // It isn't clear which would be reliably faster in all cases and on all platforms, and @@ -2963,7 +2970,7 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c unsigned int instancesB = 0; glGenBuffers(1, &instancesB); glBindBuffer(GL_ARRAY_BUFFER, instancesB); - glBufferData(GL_ARRAY_BUFFER, count*sizeof(float16), instances, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, count*sizeof(float16), instanceTransforms, GL_STATIC_DRAW); // Instances are put in LOC_MATRIX_MODEL attribute location with space for 4x Vector4, eg: // layout (location = 12) in mat4 instance; @@ -2983,7 +2990,7 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c else glDrawArraysInstanced(GL_TRIANGLES, 0, mesh.vertexCount, count); glDeleteBuffers(1, &instancesB); - RL_FREE(instances); + RL_FREE(instanceTransforms); // Unbind all binded texture maps for (int i = 0; i < MAX_MATERIAL_MAPS; i++) @@ -3007,19 +3014,6 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c // Unload mesh data from CPU and GPU void rlUnloadMesh(Mesh mesh) { - RL_FREE(mesh.vertices); - RL_FREE(mesh.texcoords); - RL_FREE(mesh.normals); - RL_FREE(mesh.colors); - RL_FREE(mesh.tangents); - RL_FREE(mesh.texcoords2); - RL_FREE(mesh.indices); - - RL_FREE(mesh.animVertices); - RL_FREE(mesh.animNormals); - RL_FREE(mesh.boneWeights); - RL_FREE(mesh.boneIds); - #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) for (int i = 0; i < 7; i++) glDeleteBuffers(1, &mesh.vboId[i]); // DEFAULT_MESH_VERTEX_BUFFERS (model.c) if (RLGL.ExtSupported.vao) @@ -3030,6 +3024,8 @@ void rlUnloadMesh(Mesh mesh) } else TRACELOG(LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)"); #endif + + RL_FREE(mesh.vboId); } // Read screen pixel data (color buffer) From 478f4de7ae99d55495228ad64d3803fec3254cd1 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 21 Feb 2021 12:31:50 +0100 Subject: [PATCH 17/51] Update models_material_pbr.c #1571 --- examples/models/models_material_pbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index 0104d3922..33a1af573 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -179,7 +179,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) // Generate cubemap from panorama texture //-------------------------------------------------------------------------------------------------------- - Texture2D panorama = LoadTexture("resources/dresden_square.hdr"); + Texture2D panorama = LoadTexture("resources/dresden_square_2k.hdr"); // Load equirectangular to cubemap shader #if defined(PLATFORM_DESKTOP) Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs"); From 209445ccde2c1e984c0787b3d1b24fc3bf62a427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20=22NeZv=C4=93rs=22=20Aldi=C5=86=C5=A1?= Date: Mon, 22 Feb 2021 20:45:52 +0200 Subject: [PATCH 18/51] LoadMusicStreamFromMemory (#1606) * define SUPPORT_FILEFORMAT_MOD in config.h * RLAPI LoadModuleFromData() definition in raylib.h * LoadModuleFromData() definition in raudio.h * LoadModuleFromData implementation in raudio.c * Rename API to LoadMusicStreamFromMemory & default unload. * raudio.c tabs to spaces * Styling curly bracket and removing dev debugging TRACELOG Co-authored-by: nezvers --- src/config.h | 2 +- src/raudio.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/raudio.h | 1 + src/raylib.h | 1 + 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 71908b0c0..ce943901d 100644 --- a/src/config.h +++ b/src/config.h @@ -187,7 +187,7 @@ #define SUPPORT_FILEFORMAT_WAV 1 #define SUPPORT_FILEFORMAT_OGG 1 #define SUPPORT_FILEFORMAT_XM 1 -//#define SUPPORT_FILEFORMAT_MOD 1 +#define SUPPORT_FILEFORMAT_MOD 1 #define SUPPORT_FILEFORMAT_MP3 1 //#define SUPPORT_FILEFORMAT_FLAC 1 diff --git a/src/raudio.c b/src/raudio.c index 6a122720d..0a0474e1a 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1297,6 +1297,103 @@ Music LoadMusicStream(const char *fileName) return music; } +// extension including period ".mod" +Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int dataSize) +{ + Music music = { 0 }; + bool musicLoaded = false; + + char fileExtLower[16] = { 0 }; + strcpy(fileExtLower, TextToLower(fileType)); + + if (false) { } +#if defined(SUPPORT_FILEFORMAT_XM) + if (TextIsEqual(fileExtLower, ".xm")) + { + jar_xm_context_t *ctxXm = NULL; + int result = jar_xm_create_context_safe(&ctxXm, data, dataSize, 48000); + if (result == 0) // XM AUDIO.System.context created successfully + { + music.ctxType = MUSIC_MODULE_XM; + jar_xm_set_max_loop_count(ctxXm, 0); // Set infinite number of loops + + // NOTE: Only stereo is supported for XM + music.stream = InitAudioStream(48000, 16, 2); + music.sampleCount = (unsigned int)jar_xm_get_remaining_samples(ctxXm)*2; // 2 channels + music.looping = true; // Looping enabled by default + jar_xm_reset(ctxXm); // make sure we start at the beginning of the song + + music.ctxData = ctxXm; + musicLoaded = true; + } + } +#endif +#if defined(SUPPORT_FILEFORMAT_MOD) + else if (TextIsEqual(fileExtLower, ".mod")) + { + jar_mod_context_t *ctxMod = RL_MALLOC(sizeof(jar_mod_context_t)); + int result = 0; + + jar_mod_init(ctxMod); + + // copy data to allocated memory for default UnloadMusicStream + unsigned char *newData = RL_MALLOC(dataSize); + int it = dataSize / sizeof(unsigned char); + for (int i = 0; i < it; i++){ + newData[i] = data[i]; + } + + // Memory loaded version for jar_mod_load_file() + if (dataSize && dataSize < 32*1024*1024) + { + ctxMod->modfilesize = dataSize; + ctxMod->modfile = newData; + if(jar_mod_load(ctxMod, (void*)ctxMod->modfile, dataSize)) result = dataSize; + } + + if (result > 0) + { + music.ctxType = MUSIC_MODULE_MOD; + + // NOTE: Only stereo is supported for MOD + music.stream = InitAudioStream(48000, 16, 2); + music.sampleCount = (unsigned int)jar_mod_max_samples(ctxMod)*2; // 2 channels + music.looping = true; // Looping enabled by default + musicLoaded = true; + + music.ctxData = ctxMod; + musicLoaded = true; + } + } +#endif + else TRACELOG(LOG_WARNING, "STREAM: [%s] Fileformat not supported", fileType); + + if (!musicLoaded) + { + if (false) { } + #if defined(SUPPORT_FILEFORMAT_XM) + else if (music.ctxType == MUSIC_MODULE_XM) jar_xm_free_context((jar_xm_context_t *)music.ctxData); + #endif + #if defined(SUPPORT_FILEFORMAT_MOD) + else if (music.ctxType == MUSIC_MODULE_MOD) { jar_mod_unload((jar_mod_context_t *)music.ctxData); RL_FREE(music.ctxData); } + #endif + + music.ctxData = NULL; + TRACELOG(LOG_WARNING, "FILEIO: [%s] Music memory could not be opened", fileType); + } + else + { + // Show some music stream info + TRACELOG(LOG_INFO, "FILEIO: [%s] Music memory successfully loaded:", fileType); + TRACELOG(LOG_INFO, " > Total samples: %i", music.sampleCount); + TRACELOG(LOG_INFO, " > Sample rate: %i Hz", music.stream.sampleRate); + TRACELOG(LOG_INFO, " > Sample size: %i bits", music.stream.sampleSize); + TRACELOG(LOG_INFO, " > Channels: %i (%s)", music.stream.channels, (music.stream.channels == 1)? "Mono" : (music.stream.channels == 2)? "Stereo" : "Multi"); + } + + return music; +} + // Unload music stream void UnloadMusicStream(Music music) { diff --git a/src/raudio.h b/src/raudio.h index 8178deec8..cf8b767a0 100644 --- a/src/raudio.h +++ b/src/raudio.h @@ -164,6 +164,7 @@ float *GetWaveData(Wave wave); // Get samples d // Music management functions Music LoadMusicStream(const char *fileName); // Load music stream from file +Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int dataSize); // Load module music from data void UnloadMusicStream(Music music); // Unload music stream void PlayMusicStream(Music music); // Start music playing void UpdateMusicStream(Music music); // Updates buffers for music streaming diff --git a/src/raylib.h b/src/raylib.h index 15df914b0..2bd62ae19 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1495,6 +1495,7 @@ RLAPI void UnloadWaveSamples(float *samples); // Unload // Music management functions RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int dataSize); // Load module music from data RLAPI void UnloadMusicStream(Music music); // Unload music stream RLAPI void PlayMusicStream(Music music); // Start music playing RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming From 0cb748f30b463c75254855ab67ec4b7350a47117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20=22NeZv=C4=93rs=22=20Aldi=C5=86=C5=A1?= Date: Wed, 24 Feb 2021 10:22:21 +0200 Subject: [PATCH 19/51] LoadMusicStreamFromMemory wav mp3 flac support (#1609) --- src/raudio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/src/raudio.c b/src/raudio.c index 0a0474e1a..9b135dc19 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1307,8 +1307,65 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d strcpy(fileExtLower, TextToLower(fileType)); if (false) { } +#if defined(SUPPORT_FILEFORMAT_WAV) + else if (TextIsEqual(fileExtLower, ".wav")) + { + drwav *ctxWav = RL_CALLOC(1, sizeof(drwav)); + + bool success = drwav_init_memory(ctxWav, (const void*)data, dataSize, NULL); + + music.ctxType = MUSIC_AUDIO_WAV; + music.ctxData = ctxWav; + + if (success) + { + int sampleSize = ctxWav->bitsPerSample; + if (ctxWav->bitsPerSample == 24) sampleSize = 16; // Forcing conversion to s16 on UpdateMusicStream() + + music.stream = InitAudioStream(ctxWav->sampleRate, sampleSize, ctxWav->channels); + music.sampleCount = (unsigned int)ctxWav->totalPCMFrameCount*ctxWav->channels; + music.looping = true; // Looping enabled by default + musicLoaded = true; + } + } +#endif +#if defined(SUPPORT_FILEFORMAT_FLAC) + else if (TextIsEqual(fileExtLower, ".flac")) + { + music.ctxType = MUSIC_AUDIO_FLAC; + music.ctxData = drflac_open_memory((const void*)data, dataSize, NULL); + + if (music.ctxData != NULL) + { + drflac *ctxFlac = (drflac *)music.ctxData; + + music.stream = InitAudioStream(ctxFlac->sampleRate, ctxFlac->bitsPerSample, ctxFlac->channels); + music.sampleCount = (unsigned int)ctxFlac->totalPCMFrameCount*ctxFlac->channels; + music.looping = true; // Looping enabled by default + musicLoaded = true; + } + } +#endif +#if defined(SUPPORT_FILEFORMAT_MP3) + else if (TextIsEqual(fileExtLower, ".mp3")) + { + drmp3 *ctxMp3 = RL_CALLOC(1, sizeof(drmp3)); + int success = drmp3_init_memory(ctxMp3, (const void*)data, dataSize, NULL); + + music.ctxType = MUSIC_AUDIO_MP3; + music.ctxData = ctxMp3; + + if (success) + { + music.stream = InitAudioStream(ctxMp3->sampleRate, 32, ctxMp3->channels); + music.sampleCount = (unsigned int)drmp3_get_pcm_frame_count(ctxMp3)*ctxMp3->channels; + music.looping = true; // Looping enabled by default + musicLoaded = true; + } + } +#endif #if defined(SUPPORT_FILEFORMAT_XM) - if (TextIsEqual(fileExtLower, ".xm")) + else if (TextIsEqual(fileExtLower, ".xm")) { jar_xm_context_t *ctxXm = NULL; int result = jar_xm_create_context_safe(&ctxXm, data, dataSize, 48000); @@ -1371,7 +1428,16 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d if (!musicLoaded) { if (false) { } - #if defined(SUPPORT_FILEFORMAT_XM) + #if defined(SUPPORT_FILEFORMAT_WAV) + else if (music.ctxType == MUSIC_AUDIO_WAV) drwav_uninit((drwav *)music.ctxData); + #endif + #if defined(SUPPORT_FILEFORMAT_FLAC) + else if (music.ctxType == MUSIC_AUDIO_FLAC) drflac_free((drflac *)music.ctxData, NULL); + #endif + #if defined(SUPPORT_FILEFORMAT_MP3) + else if (music.ctxType == MUSIC_AUDIO_MP3) { drmp3_uninit((drmp3 *)music.ctxData); RL_FREE(music.ctxData); } + #endif + #if defined(SUPPORT_FILEFORMAT_XM) else if (music.ctxType == MUSIC_MODULE_XM) jar_xm_free_context((jar_xm_context_t *)music.ctxData); #endif #if defined(SUPPORT_FILEFORMAT_MOD) From 84ab4ce00706723a88e7b47666bccf7375984af8 Mon Sep 17 00:00:00 2001 From: Chris Sinclair Date: Wed, 24 Feb 2021 08:25:20 +0000 Subject: [PATCH 20/51] Patch up GLTF Skeleton loading (#1610) * Add support for u8 bone indicies when loading glTF * Fix segfault for glTF animations not keyframed at 0 When loading glTF animations we lerp between keyframes, and previously assume that if the frame we are considering has a later keyframe, there must be a previous keyframe. This is not true if the animation's first keyframe is some time into the animation. In this case we now effectively clamp to that first keyframe for any time prior to it. * Respect parent bones tranform when loading glTF animations We previously assumed that when loading glTF animations, the bones were ordered with those higher up the skeleton tree (i.e. closer to the root) came first in the list of nodes. This may not be true, so now we repeatedly loop, preparing each level of the skeleton tree one after the other, starting at the root level. This ensures that any parent transforms are applied before transforming any child bones. We also ensure that we have forced the loading of animation data before attempting to interpolate to generate the animation frames for use later, without this no animations are applied. Finally we remove the check that assumed the first node in the nodes list is the root, and use an invalid index value as the sentinal value for when a node has no parent. Previously this was 0, which made distinguishing between root nodes and children of the first node impossible. --- src/models.c | 105 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/src/models.c b/src/models.c index 5c54902a9..b92228556 100644 --- a/src/models.c +++ b/src/models.c @@ -3719,11 +3719,11 @@ static Model LoadGLTF(const char *fileName) model.boneCount = (int)data->nodes_count; model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo)); model.bindPose = RL_CALLOC(model.boneCount, sizeof(Transform)); - + for (unsigned int j = 0; j < data->nodes_count; j++) { strcpy(model.bones[j].name, data->nodes[j].name == 0 ? "ANIMJOINT" : data->nodes[j].name); - model.bones[j].parent = (int)((j != 0 && data->nodes[j].parent != NULL) ? data->nodes[j].parent - data->nodes : 0); + model.bones[j].parent = (data->nodes[j].parent != NULL) ? data->nodes[j].parent - data->nodes : -1; } for (unsigned int i = 0; i < data->nodes_count; i++) @@ -3739,22 +3739,41 @@ static Model LoadGLTF(const char *fileName) if (data->nodes[i].has_scale) memcpy(&model.bindPose[i].scale, data->nodes[i].scale, 3 * sizeof(float)); else model.bindPose[i].scale = Vector3One(); } - - for (int i = 0; i < model.boneCount; i++) + { - Transform *currentTransform = model.bindPose + i; - BoneInfo *currentBone = model.bones + i; - int root = currentBone->parent; - if (root >= model.boneCount) root = 0; - Transform *parentTransform = model.bindPose + root; - - if (currentBone->parent >= 0) - { - currentTransform->rotation = QuaternionMultiply(parentTransform->rotation, currentTransform->rotation); - currentTransform->translation = Vector3RotateByQuaternion(currentTransform->translation, parentTransform->rotation); - currentTransform->translation = Vector3Add(currentTransform->translation, parentTransform->translation); - currentTransform->scale = Vector3Multiply(parentTransform->scale, parentTransform->scale); + bool* completedBones = RL_CALLOC(model.boneCount, sizeof(bool)); + int numberCompletedBones = 0; + + while (numberCompletedBones < model.boneCount) { + for (int i = 0; i < model.boneCount; i++) + { + if (completedBones[i]) continue; + + if (model.bones[i].parent < 0) { + completedBones[i] = true; + numberCompletedBones++; + continue; + } + + if (!completedBones[model.bones[i].parent]) continue; + + Transform* currentTransform = &model.bindPose[i]; + BoneInfo* currentBone = &model.bones[i]; + int root = currentBone->parent; + if (root >= model.boneCount) + root = 0; + Transform* parentTransform = &model.bindPose[root]; + + currentTransform->rotation = QuaternionMultiply(parentTransform->rotation, currentTransform->rotation); + currentTransform->translation = Vector3RotateByQuaternion(currentTransform->translation, parentTransform->rotation); + currentTransform->translation = Vector3Add(currentTransform->translation, parentTransform->translation); + currentTransform->scale = Vector3Multiply(parentTransform->scale, parentTransform->scale); + completedBones[i] = true; + numberCompletedBones++; + } } + + RL_FREE(completedBones); } for (int i = 0; i < model.materialCount - 1; i++) @@ -3879,7 +3898,28 @@ static Model LoadGLTF(const char *fileName) short* bones = RL_MALLOC(sizeof(short) * acc->count * 4); LOAD_ACCESSOR(short, 4, acc, bones); - for (unsigned int a = 0; a < acc->count * 4; a ++) + for (unsigned int a = 0; a < acc->count * 4; a++) + { + cgltf_node* skinJoint = data->skins->joints[bones[a]]; + + for (unsigned int k = 0; k < data->nodes_count; k++) + { + if (&(data->nodes[k]) == skinJoint) + { + model.meshes[primitiveIndex].boneIds[a] = k; + break; + } + } + } + RL_FREE(bones); + } + else if (acc->component_type == cgltf_component_type_r_8u) + { + model.meshes[primitiveIndex].boneIds = RL_MALLOC(sizeof(int) * acc->count * 4); + unsigned char* bones = RL_MALLOC(sizeof(unsigned char) * acc->count * 4); + + LOAD_ACCESSOR(unsigned char, 4, acc, bones); + for (unsigned int a = 0; a < acc->count * 4; a++) { cgltf_node* skinJoint = data->skins->joints[bones[a]]; @@ -4009,6 +4049,9 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo { TRACELOG(LOG_INFO, "MODEL: [%s] glTF animations (%s) count: %i", fileName, (data->file_type == 2)? "glb" : "gltf", data->animations_count); + + result = cgltf_load_buffers(&options, data, fileName); + if (result != cgltf_result_success) TRACELOG(LOG_WARNING, "MODEL: [%s] unable to load glTF animations data", fileName); animations = RL_MALLOC(data->animations_count*sizeof(ModelAnimation)); @@ -4054,7 +4097,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo for (unsigned int j = 0; j < data->nodes_count; j++) { strcpy(output->bones[j].name, data->nodes[j].name == 0 ? "ANIMJOINT" : data->nodes[j].name); - output->bones[j].parent = j != 0 ? (int)(data->nodes[j].parent - data->nodes) : 0; + output->bones[j].parent = (data->nodes[j].parent != NULL) ? (int)(data->nodes[j].parent - data->nodes) : -1; } // Allocate data for frames @@ -4099,11 +4142,11 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo if (frameTime < inputFrameTime) { shouldSkipFurtherTransformation = false; - outputMin = j - 1; + outputMin = (j == 0) ? 0 : j - 1; outputMax = j; float previousInputTime = 0.0f; - if (GltfReadFloat(sampler->input, j - 1, (float*)&previousInputTime, 1)) + if (GltfReadFloat(sampler->input, outputMin, (float*)&previousInputTime, 1)) { lerpPercent = (frameTime - previousInputTime) / (inputFrameTime - previousInputTime); } @@ -4163,16 +4206,32 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo // Build frameposes for (int frame = 0; frame < output->frameCount; frame++) { - for (int i = 0; i < output->boneCount; i++) - { - if (output->bones[i].parent >= 0) + bool* completedBones = RL_CALLOC(output->boneCount, sizeof(bool)); + int numberCompletedBones = 0; + + while (numberCompletedBones < output->boneCount) { + for (int i = 0; i < output->boneCount; i++) { + if (completedBones[i]) continue; + + if (output->bones[i].parent < 0) { + completedBones[i] = true; + numberCompletedBones++; + continue; + } + + if (!completedBones[output->bones[i].parent]) continue; + output->framePoses[frame][i].rotation = QuaternionMultiply(output->framePoses[frame][output->bones[i].parent].rotation, output->framePoses[frame][i].rotation); output->framePoses[frame][i].translation = Vector3RotateByQuaternion(output->framePoses[frame][i].translation, output->framePoses[frame][output->bones[i].parent].rotation); output->framePoses[frame][i].translation = Vector3Add(output->framePoses[frame][i].translation, output->framePoses[frame][output->bones[i].parent].translation); output->framePoses[frame][i].scale = Vector3Multiply(output->framePoses[frame][i].scale, output->framePoses[frame][output->bones[i].parent].scale); + completedBones[i] = true; + numberCompletedBones++; } } + + RL_FREE(completedBones); } } From 24839c7cfbf253c340a157acc8836a0f74a81376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20=22NeZv=C4=93rs=22=20Aldi=C5=86=C5=A1?= Date: Wed, 24 Feb 2021 13:23:39 +0200 Subject: [PATCH 21/51] jar_xm_create_context_safe requesting const char* (#1611) Fixing compiler warning for passing (unsigned char*) to (const char*) --- src/raudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 9b135dc19..a01340264 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1368,7 +1368,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d else if (TextIsEqual(fileExtLower, ".xm")) { jar_xm_context_t *ctxXm = NULL; - int result = jar_xm_create_context_safe(&ctxXm, data, dataSize, 48000); + int result = jar_xm_create_context_safe(&ctxXm, (const char*)data, dataSize, 48000); if (result == 0) // XM AUDIO.System.context created successfully { music.ctxType = MUSIC_MODULE_XM; From ead339fa96435a0d558224f6f432d013bb68e2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20=22NeZv=C4=93rs=22=20Aldi=C5=86=C5=A1?= Date: Thu, 25 Feb 2021 12:55:08 +0200 Subject: [PATCH 22/51] LoadMusicStreamFromMemory OGG support (#1613) --- src/raudio.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/raudio.c b/src/raudio.c index a01340264..7fc847fe3 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1364,6 +1364,28 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d } } #endif +#if defined(SUPPORT_FILEFORMAT_OGG) + else if (TextIsEqual(fileExtLower, ".ogg")) + { + // Open ogg audio stream + music.ctxType = MUSIC_AUDIO_OGG; + //music.ctxData = stb_vorbis_open_filename(fileName, NULL, NULL); + music.ctxData = stb_vorbis_open_memory((const unsigned char*)data, dataSize, NULL, NULL); + + if (music.ctxData != NULL) + { + stb_vorbis_info info = stb_vorbis_get_info((stb_vorbis *)music.ctxData); // Get Ogg file info + + // OGG bit rate defaults to 16 bit, it's enough for compressed format + music.stream = InitAudioStream(info.sample_rate, 16, info.channels); + + // WARNING: It seems this function returns length in frames, not samples, so we multiply by channels + music.sampleCount = (unsigned int)stb_vorbis_stream_length_in_samples((stb_vorbis *)music.ctxData)*info.channels; + music.looping = true; // Looping enabled by default + musicLoaded = true; + } + } +#endif #if defined(SUPPORT_FILEFORMAT_XM) else if (TextIsEqual(fileExtLower, ".xm")) { @@ -1436,6 +1458,9 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d #endif #if defined(SUPPORT_FILEFORMAT_MP3) else if (music.ctxType == MUSIC_AUDIO_MP3) { drmp3_uninit((drmp3 *)music.ctxData); RL_FREE(music.ctxData); } + #endif + #if defined(SUPPORT_FILEFORMAT_OGG) + else if (music.ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close((stb_vorbis *)music.ctxData); #endif #if defined(SUPPORT_FILEFORMAT_XM) else if (music.ctxType == MUSIC_MODULE_XM) jar_xm_free_context((jar_xm_context_t *)music.ctxData); From 4e1c7a9f4652038a29123cfb0aae44e2e4bae14b Mon Sep 17 00:00:00 2001 From: Rabia Alhaffar Date: Thu, 25 Feb 2021 19:26:29 +0200 Subject: [PATCH 23/51] Added raylib-v7 and done edit as comparing between JavaScript bindings... (#1614) --- BINDINGS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 578da3134..2bf35d1cb 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -53,7 +53,8 @@ Here it is a list with the ones I'm aware of: | clj-raylib | 3.0 | [Clojure](https://clojure.org/) | https://github.com/lsevero/clj-raylib | | node-raylib | 3.5 | [Node.js](https://nodejs.org/en/) | https://github.com/RobLoach/node-raylib | | QuickJS-raylib | 3.0 | [QuickJS](https://bellard.org/quickjs/) | https://github.com/sntg-p/QuickJS-raylib | -| raylib-duktape | 2.6 | [JavaScript](https://en.wikipedia.org/wiki/JavaScript) | https://github.com/RobLoach/raylib-duktape | +| raylib-duktape | 2.6 | [JavaScript (Duktape)](https://en.wikipedia.org/wiki/JavaScript) | https://github.com/RobLoach/raylib-duktape | +| raylib-v7 | 3.5 | [JavaScript (v7)](https://en.wikipedia.org/wiki/JavaScript) | https://github.com/Rabios/raylib-v7 | | raylib-chaiscript | 2.6 | [ChaiScript](http://chaiscript.com/) | https://github.com/RobLoach/raylib-chaiscript | | raylib-squirrel | 2.5 | [Squirrel](http://www.squirrel-lang.org/) | https://github.com/RobLoach/raylib-squirrel | | racket-raylib-2d | 2.5 | [Racket](https://racket-lang.org/) | https://github.com/arvyy/racket-raylib-2d | From 58e4efbba857c8625f60a7d816fc2f7cfd36e124 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 26 Feb 2021 13:40:43 +0100 Subject: [PATCH 24/51] Review bug on OpenGL 1.1 --- src/rlgl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index a543c40f8..7d21a9022 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -2429,7 +2429,7 @@ void rlGenerateMipmaps(Texture2D *texture) // NOTE: Texture data size is reallocated to fit mipmaps data // NOTE: CPU mipmap generation only supports RGBA 32bit data - int mipmapCount = GenerateMipmaps(data, texture->width, texture->height); + int mipmapCount = GenerateMipmaps(texData, texture->width, texture->height); int size = texture->width*texture->height*4; int offset = size; From b64fe4dfed21c1039be32182a168c61a54057008 Mon Sep 17 00:00:00 2001 From: Rabia Alhaffar Date: Fri, 26 Feb 2021 16:54:24 +0200 Subject: [PATCH 25/51] Readded survived copy of Harbour bindings! (#1616) --- BINDINGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BINDINGS.md b/BINDINGS.md index 2bf35d1cb..56344b100 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -92,6 +92,7 @@ Here it is a list with the ones I'm aware of: | raylib-never | 3.0 | [Never](https://github.com/never-lang/never) | https://github.com/never-lang/raylib-never | | raylib.cbl | 2.0 | [COBOL](https://en.wikipedia.org/wiki/COBOL) | *[code examples](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)* | | Relib | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | https://github.com/RedCubeDev-ByteSpace/Relib | +| Harbour | 3.5 | [Harbour](https://harbour.github.io) | https://github.com/MarcosLeonardoMendezGerencir/hb-raylib | Missing some language? Feel free to create a new binding! :) From 0f10c44578c4500b770589e34cd8404bee4e8cba Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sun, 28 Feb 2021 14:31:25 -0800 Subject: [PATCH 26/51] Fixes gl state after HDR texture functions. (#1621) Updates skybox demo to show how to do both HDR and non HDR skyboxes Co-authored-by: Jeffery Myers --- examples/models/models_skybox.c | 71 +++++++++++++----- .../resources/shaders/glsl100/skybox.fs | 9 ++- .../resources/shaders/glsl330/skybox.fs | 9 ++- examples/models/resources/skybox.png | Bin 0 -> 10992 bytes src/rlgl.h | 6 +- 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 examples/models/resources/skybox.png diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index f80fbf7a6..ad9c46c22 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -10,6 +10,9 @@ ********************************************************************************************/ #include "raylib.h" +#include "rlgl.h" + +bool useHDR = false; int main(void) { @@ -35,7 +38,8 @@ int main(void) skybox.materials[0].shader = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/skybox.fs"); #endif SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT); - SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ 1 }, UNIFORM_INT); + SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "doGamma"), (int[1]) { useHDR ? 1 : 0 }, UNIFORM_INT); + SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ useHDR ? 1 : 0 }, UNIFORM_INT); // Load cubemap shader and setup required shader locations #if defined(PLATFORM_DESKTOP) @@ -45,18 +49,29 @@ int main(void) #endif SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); - // Load HDR panorama (sphere) texture - char panoFileName[256] = { 0 }; - TextCopy(panoFileName, "resources/dresden_square_2k.hdr"); - Texture2D panorama = LoadTexture(panoFileName); + char skyboxFileName[256] = { 0 }; - // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture - // NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping - // NOTE 2: It seems on some Android devices WebGL, fbo does not properly support a FLOAT-based attachment, - // despite texture can be successfully created.. so using UNCOMPRESSED_R8G8B8A8 instead of UNCOMPRESSED_R32G32B32A32 - skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, UNCOMPRESSED_R8G8B8A8); + if (useHDR) + { + TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr"); - UnloadTexture(panorama); // Texture not required anymore, cubemap already generated + // Load HDR panorama (sphere) texture + Texture2D panorama = panorama = LoadTexture(skyboxFileName); + + // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture + // NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping + // NOTE 2: It seems on some Android devices WebGL, fbo does not properly support a FLOAT-based attachment, + // despite texture can be successfully created.. so using UNCOMPRESSED_R8G8B8A8 instead of UNCOMPRESSED_R32G32B32A32 + skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, UNCOMPRESSED_R8G8B8A8); + + UnloadTexture(panorama); // Texture not required anymore, cubemap already generated + } + else + { + Image img = LoadImage("resources/skybox.png"); + skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_AUTO_DETECT); + UnloadImage(img); + } SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode @@ -82,12 +97,22 @@ int main(void) { // Unload current cubemap texture and load new one UnloadTexture(skybox.materials[0].maps[MAP_CUBEMAP].texture); - panorama = LoadTexture(droppedFiles[0]); - TextCopy(panoFileName, droppedFiles[0]); - - // Generate cubemap from panorama texture - skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, UNCOMPRESSED_R8G8B8A8); - UnloadTexture(panorama); + if (useHDR) + { + Texture2D panorama = LoadTexture(droppedFiles[0]); + + // Generate cubemap from panorama texture + skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, UNCOMPRESSED_R8G8B8A8); + UnloadTexture(panorama); + } + else + { + Image img = LoadImage(droppedFiles[0]); + skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_AUTO_DETECT); + UnloadImage(img); + } + + TextCopy(skyboxFileName, droppedFiles[0]); } } @@ -102,11 +127,19 @@ int main(void) ClearBackground(RAYWHITE); BeginMode3D(camera); - DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); + rlDisableBackfaceCulling(); + rlDisableDepthMask(); + DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); + rlEnableBackfaceCulling(); + rlEnableDepthMask(); DrawGrid(10, 1.0f); EndMode3D(); - DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(panoFileName)), 10, GetScreenHeight() - 20, 10, BLACK); + if (useHDR) + DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK); + else + DrawText(TextFormat(": %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK); + DrawFPS(10, 10); EndDrawing(); diff --git a/examples/models/resources/shaders/glsl100/skybox.fs b/examples/models/resources/shaders/glsl100/skybox.fs index 1269a96d9..4aa4ec9c0 100644 --- a/examples/models/resources/shaders/glsl100/skybox.fs +++ b/examples/models/resources/shaders/glsl100/skybox.fs @@ -8,6 +8,7 @@ varying vec3 fragPosition; // Input uniform values uniform samplerCube environmentMap; uniform bool vflipped; +uniform bool doGamma; void main() { @@ -19,9 +20,11 @@ void main() vec3 color = vec3(texelColor.x, texelColor.y, texelColor.z); - // Apply gamma correction - color = color/(color + vec3(1.0)); - color = pow(color, vec3(1.0/2.2)); + if (doGamma)// Apply gamma correction + { + color = color/(color + vec3(1.0)); + color = pow(color, vec3(1.0/2.2)); + } // Calculate final fragment color gl_FragColor = vec4(color, 1.0); diff --git a/examples/models/resources/shaders/glsl330/skybox.fs b/examples/models/resources/shaders/glsl330/skybox.fs index dd8078e09..800c1c6fc 100644 --- a/examples/models/resources/shaders/glsl330/skybox.fs +++ b/examples/models/resources/shaders/glsl330/skybox.fs @@ -16,6 +16,7 @@ in vec3 fragPosition; // Input uniform values uniform samplerCube environmentMap; uniform bool vflipped; +uniform bool doGamma; // Output fragment color out vec4 finalColor; @@ -28,9 +29,11 @@ void main() if (vflipped) color = texture(environmentMap, vec3(fragPosition.x, -fragPosition.y, fragPosition.z)).rgb; else color = texture(environmentMap, fragPosition).rgb; - // Apply gamma correction - color = color/(color + vec3(1.0)); - color = pow(color, vec3(1.0/2.2)); + if (doGamma)// Apply gamma correction + { + color = color/(color + vec3(1.0)); + color = pow(color, vec3(1.0/2.2)); + } // Calculate final fragment color finalColor = vec4(color, 1.0); diff --git a/examples/models/resources/skybox.png b/examples/models/resources/skybox.png new file mode 100644 index 0000000000000000000000000000000000000000..36a79b2de5bee79b932730011d25e1e5f6209d48 GIT binary patch literal 10992 zcmeAS@N?(olHy`uVBq!ia0y~y;9y{2U}NB5W?*2r>J|~tz`(#*9OUlAuNSs54@&IkB}xZeEw|K^u}55E1o@#WvGum5j<{eS1{|GQuR-~IOg z-najkKK;A!>EG#(|4x4RcliCk6CeJa`}FVf=YQ9~{JZn@->t9zj=cYO?ESy9AOBtb z{O|s^|5rZ$JOAn5sSp3|e*Jg*>%VKC|6Tm_@4>hK_rCtS{ORABkN<9c`FHT$-%}s| z9ew}r(7V3}-~Ku9?(hD0fA_!ryYKDay>I{SdHZ+Io4>o?{N45D@6I=WcfS6!&KU-h@+4Abo=2w3{qXWyGY>!1H#|Kj(?m%sO_NpdqV zFmM)lL>4nJ@ErnSMo|r~1_lPrRh}-6Ar*0N?^eb~KcCr<`$E1qFwi2WviNQU9U5afvc zX9>Ak&r!_aF#T`40Xsv<(Bo`4YR?=xWFr8QY;r#8J4~fV1VsPQrf!-QC_KCAHr52R z;plNBKiz)FSWxnQ@?-z^{~tWLeBQ49LqW|1=k!0t3IA^jexBbfE6Wgn$J$P|c>klz z{&GF`pFdt~Hb3_NNrJ@xm>czF2mU-y5@$bfxVrz?mi6CXyg7KBUp{_^lb_wsq(7nG z=6^ij@i+bUnR>Tv^$aqy{TuH+dy*wDx0{8p`Q!Pnzv;Wr)Q4@WWw6=tBX~Z4;jfcF zc-|O3o-g_PyxGkEXL7zXRP6Bjd-uuakDfQekJ(#)oB!7E|IM4P7z^INlC_q9cJGJD z8}-NY<$s^QHsk-FoR16{@`|xk`bq)USymgN8!^s)6W z`}JPbpJ#7TL@?ydN3 zB-G#cey4eczQq5YTxEtBhTLcN>6hgh;&UE+w_pE#rg+B;`^WP)>#{U(FF5-rJ@*&$ zgOr|ZrseZwioW&KpW7zDpx0pbdH&Xu{0(Pq8NOJlzhj?e{&@b@m&^xPFQonZZ1$D$ z!_gU6Li&zhPn_0Me@~5{LEK^X&+~V#uphXk&#>{#%^yx@CVo7B`w8O%rVQi%GiU!` zxbZ^SVg2`tnw58}empQ;A6D4;@%)`D5c!?6UoljCe*ZDy6T_bR|0Un;*{W*39afID z|N2^Uy~O{z89HD;>{nlA!LaW~$|3iql?4uetj^jd+(pun#cBsKi>X7d(;2$8TG#ze$;Gw zUK{c3;_~@5`@Vjwvf1}Tbbc@YbBX`ozoq~AR&V?5KiB8~ao-tkTzGAF|K{S&Yxl(* zx#&B+`b+ET-v7OOCHMc0@BX|0(4YG&b7{s_x=CAyR61!-@;B?$@uqD%jJ9Rg_Hige{=fB+y7Q?{--|s z@Arw}M@G8+|H|_p&HnxEKPJBW+Rq=(vd8KV&g;4VZ~ei4@oE3WMfe+LzZbaK_;~r_ z-LuZUwf}G{sP$a?$M`MsAn$GXKYiwZ*S*XMdgTnf%j5grXKS55Ccew@tvzGU|4Dx( z_W#{){kwkV&-hE$3~8bb_h(x$z3CdEHk5KJWK@!Vn?mVr_Wx zu7kVyyx*0k(Um@@@+AMCeP&(vyPo~qf2(Kpn~yMVc>TO#$Gu~ZU*FuTeg5yBNte|h zub0<(y#Hv<@%;bxQ~vI6{CR&-0YlA!TBX}tZnD*sJwN^D=ntOuQ$O-eFMquKpFjD3 ze#*b?MGS9FvDM2ye%WnWce!*@_2OrTf8?8=2PsJWpP%?|dojbC6VK*Ne)&SL{NJC1 zWBjZ)86L+cO?$lkzx;uJ_mBOVUcm6?#BS{eFZVt+Jmh}-`?Nn@C;0h4+gMir`*q&V zR_^_d)t58twNsDx)OSYq-T!z0z`uHp&+(5g@Ha%ylc+o{xA))l`m(3eHASc2r`zqn zRHZ-f?~BFS?{_sf*C|Z+sBe7y(eU%x2%$ZaXRY*#}Pk z5Mn?1WBSbdKkWZi?Agev*O1Cr_5W=BO38EelNk-}%QM}5lT-8Fe#RG5-Q(9SJdW+Z z@F^Z9;teZfleWBaeXIW~VM`vbRc z^~q=ISN=R}|H=43bj-|?zx)5+Si)?_&{MzjW^esu#s^Fh?;5_}{}XPo|7X4dL)ssW z3%6tHZa#bdc(1VKuZx!#o11-mBVzvJ#m{c@ce1g+J*M{>|9hHd{?C`KfjeO*^S%1d z@dy7r+rN>)BIUU_y*2tV_>1Wt`>}4)U&-eKCuP$!c-;ngD+_3p$z7|6a zLwTXW@BDw|M(scIRT$>Id;Hj5-^#ZB@zHI@-;OaeW+Wy|J{~UjO-Shp8 z3^%_2xxGU{J$e`( zZ)@`ZWbNNiZ}Yq0If$K&2=6>?`EpBOtA25G>cXg%FziU}N_3mnN|4%VKV7f7} z^3DFA?@t~19B;@Fw`%WQ%j(L*pXSzCANzdk^v8RldnM}gS&!{^p4?Y|l%as}&4qX0 z@Bb;!y!3Ou1cSVoc+R!nkF_tkeoUxth^wADP21>S?5v_c+Ms}*UbgT5v;D!r=jyjI z?D+7*`Pq{vhm;-TdcLoHQ{-^((2w-2zaQ6&G3YhSymjv1?Ef)q?f*|@deCfddi&F} zx;gpxZSB4{$Ly)eOZ>BW>$e}_Tnyp|a&nXZpRM0_ZQg$^#sZUnHpX8*tzNu&H_!jA z=F`s$9kWk<-B&-Ap@8wsjW56R{}pe0_a~f_fuCXK#{9fLj2F55?*FxVq1#h`?3(O< zEyf2-Gd8~be*e$&oV!2Q3otN!D45$TdH>K4{_8hEk`^)AZ}$I`->^B9>435W|MizM zKI-=TFPOVdh(WL6@YX~BX8&ijj#XsX7yI0fEiLcmdM3&Liq(5;7-AUObAGO8n)P3? zy2hDdk4@E|Cx6cM>n7yK)XOjU=sxEzs14E~UB{O2PcZ#D>w$~i#aG2YW}NxM^!R;6 zNj=YBC2@!2roZ$5DfWxS*Z$7CqyD^KzV7RXGtGA1J^Ro8+di}Y_M=miZRYkzE7jTL z-8c9r_4|I>zg%wN{M|APS8n__`rMUapW8VbEEq4O{l9%?zc0fP&IU8Ep-c*X3|nrF8cEl% z-1cMpM>b!~2ozI)%sUG+;&lJj?s1%q5w+Wn?ojn&U@!s2E5n5?KTcLOt3e|;_oMKo zf5~@*zP$P&pU>#X#IP#vFT278RR#rbMu(XU4LXbrsZ0!;SQw^oGMo@%2vB2K;LYGL zgMpzzfsuj1k%@t!iG_iIMYoP8`MHy3iVzyz?kA5{lPLB>b!1+ShHYX?XNC`c|mn(lB_{}{xXAOTPqEjYTq zVO4xzG?}J9E3k)qFH(!Xsa7Kl7?O>%2y|04O!U0&mL? z+kmgTNp~juf>+;3cV@rCRe4;_gt;o}59f+sk9V+w6D`7-#sOcKlkQCM1+UJN?o8_i zuk?x4wdIF)z}LG_=j#6BUh(TSlml}+EHQ!74vsjG4)_{Rtc5V+EZ+(8QX- zyZ=g|op7#8mKM*aBiQB!V?_GH`(OE${^uL8C^DhQ(;QP-7U)BP^rk z#cYPrvQwC0v>q9)Q%4&Iz6@JN8%hmkjH8W%(Z&J8t Date: Mon, 1 Mar 2021 23:39:08 +0100 Subject: [PATCH 27/51] REVIEWED: CheckCollisionLines() --- src/shapes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shapes.c b/src/shapes.c index 0f5e4d5c9..343625dfd 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -1477,7 +1477,7 @@ bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, if (div == 0.0f) return false; // WARNING: This check could not work due to float precision rounding issues... - const float xi = ((startPos2.x - startPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div; + const float xi = ((startPos2.x - endPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div; const float yi = ((startPos2.y - endPos2.y)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.y - endPos1.y)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div; if (xi < fminf(startPos1.x, endPos1.x) || xi > fmaxf(startPos1.x, endPos1.x)) return false; From 5902cc6d9b95b08a4dd96461beb2afbb241a23ce Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 1 Mar 2021 23:51:32 +0100 Subject: [PATCH 28/51] REVIEWED: GetScreen*() #1570 Now GetScreenWidth() and GetScreenHeight() return the current fbo width and height. --- src/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core.c b/src/core.c index 60620085e..78a21cc5a 100644 --- a/src/core.c +++ b/src/core.c @@ -1429,13 +1429,13 @@ void SetWindowSize(int width, int height) // Get current screen width int GetScreenWidth(void) { - return CORE.Window.screen.width; + return CORE.Window.currentFbo.width; } // Get current screen height int GetScreenHeight(void) { - return CORE.Window.screen.height; + return CORE.Window.currentFbo.height; } // Get native window handle @@ -1987,9 +1987,9 @@ void EndTextureMode(void) // Set viewport to default framebuffer size SetupViewport(CORE.Window.render.width, CORE.Window.render.height); - // Reset current screen size - CORE.Window.currentFbo.width = GetScreenWidth(); - CORE.Window.currentFbo.height = GetScreenHeight(); + // Reset current fbo to screen size + CORE.Window.currentFbo.width = CORE.Window.screen.width; + CORE.Window.currentFbo.height = CORE.Window.screen.height; } // Begin scissor mode (define screen area for following drawing) From 4e6253b54686a2c353a3256947a596f3a3c9bcd0 Mon Sep 17 00:00:00 2001 From: masterex1000 Date: Mon, 1 Mar 2021 16:29:48 -0700 Subject: [PATCH 29/51] Add check to flip quaternion (#1624) --- src/raymath.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/raymath.h b/src/raymath.h index 63fc96968..fd9b620ab 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1271,6 +1271,11 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; + if (cosHalfTheta < 0) { + q2.x = -q2.x; q2.y = -q2.y; q2.z = -q2.z; q2.w = -q2.w; + cosHalfTheta = -cosHalfTheta; + } + if (fabs(cosHalfTheta) >= 1.0f) result = q1; else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount); else From 742206c1f27dc987d3bf2ca09e5e72db8b6840f8 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 00:31:04 +0100 Subject: [PATCH 30/51] Review formatting --- src/raymath.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/raymath.h b/src/raymath.h index fd9b620ab..c1c20c669 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1271,7 +1271,8 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; - if (cosHalfTheta < 0) { + if (cosHalfTheta < 0) + { q2.x = -q2.x; q2.y = -q2.y; q2.z = -q2.z; q2.w = -q2.w; cosHalfTheta = -cosHalfTheta; } From 2ff5fa73e9a4745aa1cc37a4e5be05c841778200 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 00:34:10 +0100 Subject: [PATCH 31/51] REVIEWED: rlUnloadMesh() #1615 --- src/models.c | 2 +- src/rlgl.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/models.c b/src/models.c index b92228556..b3cd625ea 100644 --- a/src/models.c +++ b/src/models.c @@ -859,7 +859,7 @@ void UploadMesh(Mesh *mesh) void UnloadMesh(Mesh mesh) { // Unload rlgl mesh vboId data - rlUnloadMesh(mesh); + rlUnloadMesh(&mesh); RL_FREE(mesh.vertices); RL_FREE(mesh.texcoords); diff --git a/src/rlgl.h b/src/rlgl.h index 26fd4b054..20b42cf80 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -575,7 +575,7 @@ RLAPI void rlUpdateMesh(Mesh mesh, int buffer, int count); // Upd RLAPI void rlUpdateMeshAt(Mesh mesh, int buffer, int count, int index); // Update vertex or index data on GPU, at index RLAPI void rlDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform RLAPI void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int count); // Draw a 3d mesh with material and transform -RLAPI void rlUnloadMesh(Mesh mesh); // Unload mesh data from CPU and GPU +RLAPI void rlUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU // NOTE: There is a set of shader related functions that are available to end user, // to avoid creating function wrappers through core module, they have been directly declared in raylib.h @@ -3012,20 +3012,21 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c } // Unload mesh data from CPU and GPU -void rlUnloadMesh(Mesh mesh) +void rlUnloadMesh(Mesh *mesh) { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - for (int i = 0; i < 7; i++) glDeleteBuffers(1, &mesh.vboId[i]); // DEFAULT_MESH_VERTEX_BUFFERS (model.c) + for (int i = 0; i < 7; i++) glDeleteBuffers(1, mesh->vboId[i]); // DEFAULT_MESH_VERTEX_BUFFERS (model.c) if (RLGL.ExtSupported.vao) { glBindVertexArray(0); - glDeleteVertexArrays(1, &mesh.vaoId); + glDeleteVertexArrays(1, mesh->vaoId); TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", mesh.vaoId); } else TRACELOG(LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)"); #endif - RL_FREE(mesh.vboId); + RL_FREE(mesh->vboId); + mesh->vboId = NULL; } // Read screen pixel data (color buffer) From bcc4418ff05fa0e06c1a539bcbbc3a5c62b3751a Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 01:07:08 +0100 Subject: [PATCH 32/51] REVIEWED: GetFileExtension() to include the dot #1523 --- src/core.c | 4 ++-- src/raudio.c | 8 ++++---- src/raylib.h | 2 +- src/text.c | 6 +++--- src/textures.c | 18 +++++++++--------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core.c b/src/core.c index 78a21cc5a..d55bcf3db 100644 --- a/src/core.c +++ b/src/core.c @@ -2351,14 +2351,14 @@ bool DirectoryExists(const char *dirPath) return result; } -// Get pointer to extension for a filename string +// Get pointer to extension for a filename string (includes the dot: .png) const char *GetFileExtension(const char *fileName) { const char *dot = strrchr(fileName, '.'); if (!dot || dot == fileName) return NULL; - return (dot + 1); + return dot; } // String pointer reverse break: returns right-most occurrence of charset in s diff --git a/src/raudio.c b/src/raudio.c index 7fc847fe3..050b37de9 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -732,16 +732,16 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int if (false) { } #if defined(SUPPORT_FILEFORMAT_WAV) - else if (TextIsEqual(fileExtLower, "wav")) wave = LoadWAV(fileData, dataSize); + else if (TextIsEqual(fileExtLower, ".wav")) wave = LoadWAV(fileData, dataSize); #endif #if defined(SUPPORT_FILEFORMAT_OGG) - else if (TextIsEqual(fileExtLower, "ogg")) wave = LoadOGG(fileData, dataSize); + else if (TextIsEqual(fileExtLower, ".ogg")) wave = LoadOGG(fileData, dataSize); #endif #if defined(SUPPORT_FILEFORMAT_FLAC) - else if (TextIsEqual(fileExtLower, "flac")) wave = LoadFLAC(fileData, dataSize); + else if (TextIsEqual(fileExtLower, ".flac")) wave = LoadFLAC(fileData, dataSize); #endif #if defined(SUPPORT_FILEFORMAT_MP3) - else if (TextIsEqual(fileExtLower, "mp3")) wave = LoadMP3(fileData, dataSize); + else if (TextIsEqual(fileExtLower, ".mp3")) wave = LoadMP3(fileData, dataSize); #endif else TRACELOG(LOG_WARNING, "WAVE: File format not supported"); diff --git a/src/raylib.h b/src/raylib.h index 2bd62ae19..21597738f 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -998,7 +998,7 @@ RLAPI bool SaveFileText(const char *fileName, char *text); // Save text d RLAPI bool FileExists(const char *fileName); // Check if file exists RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension (including point: .png, .wav) -RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (including point: ".png") +RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: ".png") RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string) RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string) diff --git a/src/text.c b/src/text.c index 5c10dd439..e0b0b324d 100644 --- a/src/text.c +++ b/src/text.c @@ -479,7 +479,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) return font; } -// Load font from memory buffer, fileType refers to extension: i.e. "ttf" +// Load font from memory buffer, fileType refers to extension: i.e. ".ttf" Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount) { Font font = { 0 }; @@ -488,8 +488,8 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int strcpy(fileExtLower, TextToLower(fileType)); #if defined(SUPPORT_FILEFORMAT_TTF) - if (TextIsEqual(fileExtLower, "ttf") || - TextIsEqual(fileExtLower, "otf")) + if (TextIsEqual(fileExtLower, ".ttf") || + TextIsEqual(fileExtLower, ".otf")) { font.baseSize = fontSize; font.charsCount = (charsCount > 0)? charsCount : 95; diff --git a/src/textures.c b/src/textures.c index 32d995244..7ef3903d9 100644 --- a/src/textures.c +++ b/src/textures.c @@ -294,7 +294,7 @@ Image LoadImageAnim(const char *fileName, int *frames) return image; } -// Load image from memory buffer, fileType refers to extension: i.e. "png" +// Load image from memory buffer, fileType refers to extension: i.e. ".png" Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize) { Image image = { 0 }; @@ -303,28 +303,28 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i strcpy(fileExtLower, TextToLower(fileType)); #if defined(SUPPORT_FILEFORMAT_PNG) - if ((TextIsEqual(fileExtLower, "png")) + if ((TextIsEqual(fileExtLower, ".png")) #else if ((false) #endif #if defined(SUPPORT_FILEFORMAT_BMP) - || (TextIsEqual(fileExtLower, "bmp")) + || (TextIsEqual(fileExtLower, ".bmp")) #endif #if defined(SUPPORT_FILEFORMAT_TGA) - || (TextIsEqual(fileExtLower, "tga")) + || (TextIsEqual(fileExtLower, ".tga")) #endif #if defined(SUPPORT_FILEFORMAT_JPG) - || (TextIsEqual(fileExtLower, "jpg") || - TextIsEqual(fileExtLower, "jpeg")) + || (TextIsEqual(fileExtLower, ".jpg") || + TextIsEqual(fileExtLower, ".jpeg")) #endif #if defined(SUPPORT_FILEFORMAT_GIF) - || (TextIsEqual(fileExtLower, "gif")) + || (TextIsEqual(fileExtLower, ".gif")) #endif #if defined(SUPPORT_FILEFORMAT_PIC) - || (TextIsEqual(fileExtLower, "pic")) + || (TextIsEqual(fileExtLower, ".pic")) #endif #if defined(SUPPORT_FILEFORMAT_PSD) - || (TextIsEqual(fileExtLower, "psd")) + || (TextIsEqual(fileExtLower, ".psd")) #endif ) { From c514431e796fa491832372b5b85060e3484cae6c Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 01:35:30 +0100 Subject: [PATCH 33/51] REVIEWED: rlUnloadMesh() --- src/rlgl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 20b42cf80..1bfe188fd 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -3015,11 +3015,11 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c void rlUnloadMesh(Mesh *mesh) { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - for (int i = 0; i < 7; i++) glDeleteBuffers(1, mesh->vboId[i]); // DEFAULT_MESH_VERTEX_BUFFERS (model.c) + for (int i = 0; i < 7; i++) glDeleteBuffers(1, &mesh->vboId[i]); // DEFAULT_MESH_VERTEX_BUFFERS (model.c) if (RLGL.ExtSupported.vao) { glBindVertexArray(0); - glDeleteVertexArrays(1, mesh->vaoId); + glDeleteVertexArrays(1, &mesh->vaoId); TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", mesh.vaoId); } else TRACELOG(LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)"); From 8df56c5843778fa9061a51e4f1f5888192fc0c1b Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 01:41:30 +0100 Subject: [PATCH 34/51] REVIEWED: rlUnloadMesh() --- src/rlgl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index 1bfe188fd..af864911c 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -3020,7 +3020,7 @@ void rlUnloadMesh(Mesh *mesh) { glBindVertexArray(0); glDeleteVertexArrays(1, &mesh->vaoId); - TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", mesh.vaoId); + TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", mesh->vaoId); } else TRACELOG(LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)"); #endif From 01b3c97c42d366522a7e82fab2b0ac47e350ee77 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 02:03:52 +0100 Subject: [PATCH 35/51] Some misc tweaks --- src/core.c | 4 ++-- src/models.c | 60 +++++++++++++++++++++++++--------------------------- src/rlgl.h | 28 +++++++++++------------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/core.c b/src/core.c index d55bcf3db..8ac725e25 100644 --- a/src/core.c +++ b/src/core.c @@ -3879,7 +3879,7 @@ static bool InitGraphicsDevice(int width, int height) TRACELOG(LOG_TRACE, "DISPLAY: EGL configs available: %d", numConfigs); - EGLConfig *configs = calloc(numConfigs, sizeof(*configs)); + EGLConfig *configs = RL_CALLOC(numConfigs, sizeof(*configs)); if (!configs) { TRACELOG(LOG_WARNING, "DISPLAY: Failed to get memory for EGL configs"); @@ -3916,7 +3916,7 @@ static bool InitGraphicsDevice(int width, int height) } } - free(configs); + RL_FREE(configs); if (!found) { diff --git a/src/models.c b/src/models.c index b3cd625ea..00e4c1e31 100644 --- a/src/models.c +++ b/src/models.c @@ -4019,7 +4019,7 @@ static bool GltfReadFloat(cgltf_accessor* acc, unsigned int index, float* variab } // LoadGLTF loads in animation data from given filename -static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCount) +static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCount) { /*********************************************************************************** @@ -4032,6 +4032,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo - ... *************************************************************************************/ + // glTF file loading unsigned int dataSize = 0; unsigned char *fileData = LoadFileData(fileName, &dataSize); @@ -4081,6 +4082,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo cgltf_animation_channel* channel = animation->channels + i; int frameCounts = (int)channel->sampler->input->count; float lastFrameTime = 0.0f; + if (GltfReadFloat(channel->sampler->input, frameCounts - 1, &lastFrameTime, 1)) { animationDuration = fmaxf(lastFrameTime, animationDuration); @@ -4137,7 +4139,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo for (unsigned int j = 0; j < sampler->input->count; j++) { float inputFrameTime; - if (GltfReadFloat(sampler->input, j, (float*)&inputFrameTime, 1)) + if (GltfReadFloat(sampler->input, j, (float *)&inputFrameTime, 1)) { if (frameTime < inputFrameTime) { @@ -4146,59 +4148,53 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo outputMax = j; float previousInputTime = 0.0f; - if (GltfReadFloat(sampler->input, outputMin, (float*)&previousInputTime, 1)) + if (GltfReadFloat(sampler->input, outputMin, (float *)&previousInputTime, 1)) { - lerpPercent = (frameTime - previousInputTime) / (inputFrameTime - previousInputTime); + lerpPercent = (frameTime - previousInputTime)/(inputFrameTime - previousInputTime); } + break; } - } else { - break; - } + } + else break; } // If the current transformation has no information for the current frame time point - if (shouldSkipFurtherTransformation) { - continue; - } + if (shouldSkipFurtherTransformation) continue; - if (channel->target_path == cgltf_animation_path_type_translation) { + if (channel->target_path == cgltf_animation_path_type_translation) + { Vector3 translationStart; Vector3 translationEnd; - bool success = GltfReadFloat(sampler->output, outputMin, (float*)&translationStart, 3); - success = GltfReadFloat(sampler->output, outputMax, (float*)&translationEnd, 3) || success; + bool success = GltfReadFloat(sampler->output, outputMin, (float *)&translationStart, 3); + success = GltfReadFloat(sampler->output, outputMax, (float *)&translationEnd, 3) || success; - if (success) - { - output->framePoses[frame][boneId].translation = Vector3Lerp(translationStart, translationEnd, lerpPercent); - } + if (success) output->framePoses[frame][boneId].translation = Vector3Lerp(translationStart, translationEnd, lerpPercent); } - if (channel->target_path == cgltf_animation_path_type_rotation) { + if (channel->target_path == cgltf_animation_path_type_rotation) + { Quaternion rotationStart; Quaternion rotationEnd; - bool success = GltfReadFloat(sampler->output, outputMin, (float*)&rotationStart, 4); - success = GltfReadFloat(sampler->output, outputMax, (float*)&rotationEnd, 4) || success; + bool success = GltfReadFloat(sampler->output, outputMin, (float *)&rotationStart, 4); + success = GltfReadFloat(sampler->output, outputMax, (float *)&rotationEnd, 4) || success; if (success) { output->framePoses[frame][boneId].rotation = QuaternionLerp(rotationStart, rotationEnd, lerpPercent); output->framePoses[frame][boneId].rotation = QuaternionNormalize(output->framePoses[frame][boneId].rotation); - } } - if (channel->target_path == cgltf_animation_path_type_scale) { + if (channel->target_path == cgltf_animation_path_type_scale) + { Vector3 scaleStart; Vector3 scaleEnd; - bool success = GltfReadFloat(sampler->output, outputMin, (float*)&scaleStart, 3); - success = GltfReadFloat(sampler->output, outputMax, (float*)&scaleEnd, 3) || success; + bool success = GltfReadFloat(sampler->output, outputMin, (float *)&scaleStart, 3); + success = GltfReadFloat(sampler->output, outputMax, (float *)&scaleEnd, 3) || success; - if (success) - { - output->framePoses[frame][boneId].scale = Vector3Lerp(scaleStart, scaleEnd, lerpPercent); - } + if (success) output->framePoses[frame][boneId].scale = Vector3Lerp(scaleStart, scaleEnd, lerpPercent); } } } @@ -4206,15 +4202,17 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo // Build frameposes for (int frame = 0; frame < output->frameCount; frame++) { - bool* completedBones = RL_CALLOC(output->boneCount, sizeof(bool)); + bool *completedBones = RL_CALLOC(output->boneCount, sizeof(bool)); int numberCompletedBones = 0; - while (numberCompletedBones < output->boneCount) { + while (numberCompletedBones < output->boneCount) + { for (int i = 0; i < output->boneCount; i++) { if (completedBones[i]) continue; - if (output->bones[i].parent < 0) { + if (output->bones[i].parent < 0) + { completedBones[i] = true; numberCompletedBones++; continue; diff --git a/src/rlgl.h b/src/rlgl.h index af864911c..70b0471ee 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -4051,25 +4051,21 @@ static unsigned int CompileShader(const char *shaderStr, int type) glCompileShader(shader); glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - if (success != GL_TRUE) + if (success == GL_FALSE) { TRACELOG(LOG_WARNING, "SHADER: [ID %i] Failed to compile shader code", shader); + int maxLength = 0; - int length; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); - -#if defined(_MSC_VER) - char *log = RL_MALLOC(maxLength); -#else - char log[maxLength]; -#endif - glGetShaderInfoLog(shader, maxLength, &length, log); - - TRACELOG(LOG_WARNING, "SHADER: [ID %i] Compile error: %s", shader, log); - -#if defined(_MSC_VER) - RL_FREE(log); -#endif + + if (maxLength > 0) + { + int length = 0; + char *log = RL_CALLOC(maxLength, sizeof(char)); + glGetShaderInfoLog(shader, maxLength, &length, log); + TRACELOG(LOG_WARNING, "SHADER: [ID %i] Compile error: %s", shader, log); + RL_FREE(log); + } } else TRACELOG(LOG_INFO, "SHADER: [ID %i] Compiled successfully", shader); @@ -4113,7 +4109,7 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad if (maxLength > 0) { - int length; + int length = 0; char *log = RL_CALLOC(maxLength, sizeof(char)); glGetProgramInfoLog(program, maxLength, &length, log); TRACELOG(LOG_WARNING, "SHADER: [ID %i] Link error: %s", program, log); From 2a5ce960474d5aafa1787b9c7d780f833bc4be4e Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 12:44:53 +0100 Subject: [PATCH 36/51] REVIEWED: Wait() to support FreeBSD #1618 --- src/core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core.c b/src/core.c index 8ac725e25..409621380 100644 --- a/src/core.c +++ b/src/core.c @@ -202,15 +202,16 @@ unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod); unsigned int __stdcall timeEndPeriod(unsigned int uPeriod); #endif - - #elif defined(__linux__) + #endif + #if defined(__linux__) || defined(__FreeBSD__) #include // Required for: timespec, nanosleep(), select() - POSIX //#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type //#define GLFW_EXPOSE_NATIVE_WAYLAND //#define GLFW_EXPOSE_NATIVE_MIR #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() - #elif defined(__APPLE__) + #endif + #if defined(__APPLE__) #include // Required for: usleep() //#define GLFW_EXPOSE_NATIVE_COCOA // WARNING: Fails due to type redefinition @@ -4234,7 +4235,8 @@ static void Wait(float ms) #if defined(_WIN32) Sleep((unsigned int)ms); - #elif defined(__linux__) || defined(PLATFORM_WEB) + #endif + #if defined(__linux__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) struct timespec req = { 0 }; time_t sec = (int)(ms/1000.0f); ms -= (sec*1000); @@ -4243,7 +4245,8 @@ static void Wait(float ms) // NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated. while (nanosleep(&req, &req) == -1) continue; - #elif defined(__APPLE__) + #endif + #if defined(__APPLE__) usleep(ms*1000.0f); #endif From ab36fbf24aa7fd89bfe0414276b0a962812ff62c Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Mar 2021 12:45:23 +0100 Subject: [PATCH 37/51] Reviewed defines, try to avoid elif statements --- src/core.c | 59 ++++++++++++++++++++++++------------------- src/physac.h | 6 +++-- src/rlgl.h | 70 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/core.c b/src/core.c index 409621380..d5f588411 100644 --- a/src/core.c +++ b/src/core.c @@ -1445,18 +1445,20 @@ void *GetWindowHandle(void) #if defined(PLATFORM_DESKTOP) && defined(_WIN32) // NOTE: Returned handle is: void *HWND (windows.h) return glfwGetWin32Window(CORE.Window.handle); -#elif defined(__linux__) +#endif +#if defined(__linux__) // NOTE: Returned handle is: unsigned long Window (X.h) // typedef unsigned long XID; // typedef XID Window; //unsigned long id = (unsigned long)glfwGetX11Window(window); return NULL; // TODO: Find a way to return value... cast to void *? -#elif defined(__APPLE__) +#endif +#if defined(__APPLE__) // NOTE: Returned handle is: (objc_object *) return NULL; // TODO: return (void *)glfwGetCocoaWindow(window); -#else - return NULL; #endif + + return NULL; } // Get number of monitors @@ -2717,6 +2719,7 @@ bool SaveStorageValue(unsigned int position, int value) int LoadStorageValue(unsigned int position) { int value = 0; + #if defined(SUPPORT_DATA_STORAGE) char path[512] = { 0 }; #if defined(PLATFORM_ANDROID) @@ -2768,9 +2771,11 @@ void OpenURL(const char *url) char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char)); #if defined(_WIN32) sprintf(cmd, "explorer %s", url); - #elif defined(__linux__) + #endif + #if defined(__linux__) || defined(__FreeBSD__) sprintf(cmd, "xdg-open '%s'", url); // Alternatives: firefox, x-www-browser - #elif defined(__APPLE__) + #endif + #if defined(__APPLE__) sprintf(cmd, "open '%s'", url); #endif system(cmd); @@ -2904,13 +2909,12 @@ const char *GetGamepadName(int gamepad) #if defined(PLATFORM_DESKTOP) if (CORE.Input.Gamepad.ready[gamepad]) return glfwGetJoystickName(gamepad); else return NULL; -#elif defined(PLATFORM_RPI) || defined(PLATFORM_DRM) - if (CORE.Input.Gamepad.ready[gamepad]) ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name); - - return CORE.Input.Gamepad.name; -#else - return NULL; #endif +#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM) + if (CORE.Input.Gamepad.ready[gamepad]) ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name); + return CORE.Input.Gamepad.name; +#endif + return NULL; } // Return gamepad axis count @@ -3112,11 +3116,12 @@ float GetMouseWheelMove(void) { #if defined(PLATFORM_ANDROID) return 0.0f; -#elif defined(PLATFORM_WEB) - return CORE.Input.Mouse.previousWheelMove/100.0f; -#else - return CORE.Input.Mouse.previousWheelMove; #endif +#if defined(PLATFORM_WEB) + return CORE.Input.Mouse.previousWheelMove/100.0f; +#endif + + return CORE.Input.Mouse.previousWheelMove; } // Returns mouse cursor @@ -3166,11 +3171,16 @@ Vector2 GetTouchPosition(int index) { Vector2 position = { -1.0f, -1.0f }; -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) || defined(PLATFORM_UWP) +#if defined(PLATFORM_DESKTOP) + // TODO: GLFW does not support multi-touch input just yet + // https://www.codeproject.com/Articles/668404/Programming-for-Multi-Touch + // https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages + if (index == 0) position = GetMousePosition(); +#endif +#if defined(PLATFORM_ANDROID) if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index]; else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS); - #if defined(PLATFORM_ANDROID) if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height)) { position.x = position.x*((float)CORE.Window.screen.width/(float)(CORE.Window.display.width - CORE.Window.renderOffset.x)) - CORE.Window.renderOffset.x/2; @@ -3181,13 +3191,12 @@ Vector2 GetTouchPosition(int index) position.x = position.x*((float)CORE.Window.render.width/(float)CORE.Window.display.width) - CORE.Window.renderOffset.x/2; position.y = position.y*((float)CORE.Window.render.height/(float)CORE.Window.display.height) - CORE.Window.renderOffset.y/2; } - #endif - -#elif defined(PLATFORM_DESKTOP) - // TODO: GLFW is not supporting multi-touch input just yet - // https://www.codeproject.com/Articles/668404/Programming-for-Multi-Touch - // https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages - if (index == 0) position = GetMousePosition(); +#endif +#if defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) || defined(PLATFORM_UWP) + if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index]; + else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS); + + // TODO: Touch position scaling required? #endif return position; diff --git a/src/physac.h b/src/physac.h index fde0b90e3..4b419bbaf 100644 --- a/src/physac.h +++ b/src/physac.h @@ -258,13 +258,15 @@ PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex); // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); - #elif defined(__linux__) + #endif + #if defined(__linux__) || defined(__FreeBSD__) #if _POSIX_C_SOURCE < 199309L #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext. #endif #include // Required for: timespec - #elif defined(__APPLE__) // macOS also defines __MACH__ + #endif + #if defined(__APPLE__) // macOS also defines __MACH__ #include // Required for: mach_absolute_time() #endif #endif diff --git a/src/rlgl.h b/src/rlgl.h index 70b0471ee..703821f0d 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -136,7 +136,8 @@ // This is the maximum amount of elements (quads) per batch // NOTE: Be careful with text, every letter maps to a quad #define DEFAULT_BATCH_BUFFER_ELEMENTS 8192 - #elif defined(GRAPHICS_API_OPENGL_ES2) + #endif + #if defined(GRAPHICS_API_OPENGL_ES2) // We reduce memory sizes for embedded systems (RPI and HTML5) // NOTE: On HTML5 (emscripten) this is allocated on heap, // by default it's only 16MB!...just take care... @@ -811,7 +812,8 @@ typedef struct VertexBuffer { unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) #if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33) unsigned int *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad) -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) unsigned short *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad) #endif unsigned int vaoId; // OpenGL Vertex Array Object id @@ -970,7 +972,6 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight); //---------------------------------------------------------------------------------- #if defined(GRAPHICS_API_OPENGL_11) - // Fallback to OpenGL 1.1 function calls //--------------------------------------- void rlMatrixMode(int mode) @@ -1001,9 +1002,8 @@ void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); } void rlRotatef(float angleDeg, float x, float y, float z) { glRotatef(angleDeg, x, y, z); } void rlScalef(float x, float y, float z) { glScalef(x, y, z); } void rlMultMatrixf(float *matf) { glMultMatrixf(matf); } - -#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - +#endif +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Choose the current matrix to be transformed void rlMatrixMode(int mode) { @@ -1124,7 +1124,6 @@ void rlViewport(int x, int y, int width, int height) // Module Functions Definition - Vertex level operations //---------------------------------------------------------------------------------- #if defined(GRAPHICS_API_OPENGL_11) - // Fallback to OpenGL 1.1 function calls //--------------------------------------- void rlBegin(int mode) @@ -1147,9 +1146,8 @@ void rlNormal3f(float x, float y, float z) { glNormal3f(x, y, z); } void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { glColor4ub(r, g, b, a); } void rlColor3f(float x, float y, float z) { glColor3f(x, y, z); } void rlColor4f(float x, float y, float z, float w) { glColor4f(x, y, z, w); } - -#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - +#endif +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Initialize drawing mode (how to organize vertex) void rlBegin(int mode) { @@ -1898,15 +1896,18 @@ int rlGetVersion(void) { #if defined(GRAPHICS_API_OPENGL_11) return OPENGL_11; -#elif defined(GRAPHICS_API_OPENGL_21) +#endif +#if defined(GRAPHICS_API_OPENGL_21) #if defined(__APPLE__) return OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX #else return OPENGL_21; #endif -#elif defined(GRAPHICS_API_OPENGL_33) +#endif +#if defined(GRAPHICS_API_OPENGL_33) return OPENGL_33; -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) return OPENGL_ES_20; #endif } @@ -1951,7 +1952,8 @@ void rlLoadExtensions(void *loader) #if defined(GRAPHICS_API_OPENGL_21) if (GLAD_GL_VERSION_2_1) TRACELOG(LOG_INFO, "GL: OpenGL 2.1 profile supported"); - #elif defined(GRAPHICS_API_OPENGL_33) + #endif + #if defined(GRAPHICS_API_OPENGL_33) if (GLAD_GL_VERSION_3_3) TRACELOG(LOG_INFO, "GL: OpenGL 3.3 Core profile supported"); else TRACELOG(LOG_ERROR, "GL: OpenGL 3.3 Core profile not supported"); #endif @@ -2051,7 +2053,8 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi { #if defined(GRAPHICS_API_OPENGL_21) GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA }; - #elif defined(GRAPHICS_API_OPENGL_33) + #endif + #if defined(GRAPHICS_API_OPENGL_33) GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN }; #endif glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); @@ -2218,7 +2221,8 @@ unsigned int rlLoadTextureCubemap(void *data, int size, int format) { #if defined(GRAPHICS_API_OPENGL_21) GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA }; -#elif defined(GRAPHICS_API_OPENGL_33) +#endif +#if defined(GRAPHICS_API_OPENGL_33) GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN }; #endif glTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); @@ -2284,7 +2288,8 @@ void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned case UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB; *glFormat = GL_RGB; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float case UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float #endif - #elif defined(GRAPHICS_API_OPENGL_33) + #endif + #if defined(GRAPHICS_API_OPENGL_33) case UNCOMPRESSED_GRAYSCALE: *glInternalFormat = GL_R8; *glFormat = GL_RED; *glType = GL_UNSIGNED_BYTE; break; case UNCOMPRESSED_GRAY_ALPHA: *glInternalFormat = GL_RG8; *glFormat = GL_RG; *glType = GL_UNSIGNED_BYTE; break; case UNCOMPRESSED_R5G6B5: *glInternalFormat = GL_RGB565; *glFormat = GL_RGB; *glType = GL_UNSIGNED_SHORT_5_6_5; break; @@ -2296,7 +2301,7 @@ void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned case UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB32F; *glFormat = GL_RGB; *glType = GL_FLOAT; break; case UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA32F; *glFormat = GL_RGBA; *glType = GL_FLOAT; break; #endif - #if !defined(GRAPHICS_API_OPENGL_11) + #if !defined(GRAPHICS_API_OPENGL_11) case COMPRESSED_DXT1_RGB: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; case COMPRESSED_DXT1_RGBA: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; case COMPRESSED_DXT3_RGBA: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; @@ -2308,7 +2313,7 @@ void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned case COMPRESSED_PVRT_RGBA: if (RLGL.ExtSupported.texCompPVRT) *glInternalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; break; // NOTE: Requires PowerVR GPU case COMPRESSED_ASTC_4x4_RGBA: if (RLGL.ExtSupported.texCompASTC) *glInternalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR; break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3 case COMPRESSED_ASTC_8x8_RGBA: if (RLGL.ExtSupported.texCompASTC) *glInternalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR; break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3 - #endif + #endif default: TRACELOG(LOG_WARNING, "TEXTURE: Current format not supported (%i)", format); break; } } @@ -2456,7 +2461,8 @@ void rlGenerateMipmaps(Texture2D *texture) } else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to generate mipmaps for provided texture format", texture->id); } -#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) if ((texIsPOT) || (RLGL.ExtSupported.texNPOT)) { //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE @@ -4140,7 +4146,8 @@ static Shader LoadShaderDefault(void) const char *defaultVShaderStr = #if defined(GRAPHICS_API_OPENGL_21) "#version 120 \n" -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) "#version 100 \n" #endif #if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21) @@ -4149,7 +4156,8 @@ static Shader LoadShaderDefault(void) "attribute vec4 vertexColor; \n" "varying vec2 fragTexCoord; \n" "varying vec4 fragColor; \n" -#elif defined(GRAPHICS_API_OPENGL_33) +#endif +#if defined(GRAPHICS_API_OPENGL_33) "#version 330 \n" "in vec3 vertexPosition; \n" "in vec2 vertexTexCoord; \n" @@ -4169,14 +4177,16 @@ static Shader LoadShaderDefault(void) const char *defaultFShaderStr = #if defined(GRAPHICS_API_OPENGL_21) "#version 120 \n" -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) "#version 100 \n" "precision mediump float; \n" // precision required for OpenGL ES2 (WebGL) #endif #if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21) "varying vec2 fragTexCoord; \n" "varying vec4 fragColor; \n" -#elif defined(GRAPHICS_API_OPENGL_33) +#endif +#if defined(GRAPHICS_API_OPENGL_33) "#version 330 \n" "in vec2 fragTexCoord; \n" "in vec4 fragColor; \n" @@ -4189,7 +4199,8 @@ static Shader LoadShaderDefault(void) #if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21) " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0 " gl_FragColor = texelColor*colDiffuse*fragColor; \n" -#elif defined(GRAPHICS_API_OPENGL_33) +#endif +#if defined(GRAPHICS_API_OPENGL_33) " vec4 texelColor = texture(texture0, fragTexCoord); \n" " finalColor = texelColor*colDiffuse*fragColor; \n" #endif @@ -4289,7 +4300,8 @@ static RenderBatch LoadRenderBatch(int numBuffers, int bufferElements) batch.vertexBuffer[i].colors = (unsigned char *)RL_MALLOC(bufferElements*4*4*sizeof(unsigned char)); // 4 float by color, 4 colors by quad #if defined(GRAPHICS_API_OPENGL_33) batch.vertexBuffer[i].indices = (unsigned int *)RL_MALLOC(bufferElements*6*sizeof(unsigned int)); // 6 int by quad (indices) -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) batch.vertexBuffer[i].indices = (unsigned short *)RL_MALLOC(bufferElements*6*sizeof(unsigned short)); // 6 int by quad (indices) #endif @@ -4358,7 +4370,8 @@ static RenderBatch LoadRenderBatch(int numBuffers, int bufferElements) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]); #if defined(GRAPHICS_API_OPENGL_33) glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(int), batch.vertexBuffer[i].indices, GL_STATIC_DRAW); -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(short), batch.vertexBuffer[i].indices, GL_STATIC_DRAW); #endif } @@ -4519,7 +4532,8 @@ static void DrawRenderBatch(RenderBatch *batch) // NOTE: The final parameter tells the GPU the offset in bytes from the // start of the index buffer to the location of the first index to process glDrawElements(GL_TRIANGLES, batch->draws[i].vertexCount/4*6, GL_UNSIGNED_INT, (GLvoid *)(vertexOffset/4*6*sizeof(GLuint))); -#elif defined(GRAPHICS_API_OPENGL_ES2) +#endif +#if defined(GRAPHICS_API_OPENGL_ES2) glDrawElements(GL_TRIANGLES, batch->draws[i].vertexCount/4*6, GL_UNSIGNED_SHORT, (GLvoid *)(vertexOffset/4*6*sizeof(GLushort))); #endif } From e09f5179e6ff876ecccc5a74e929c055b07d8b98 Mon Sep 17 00:00:00 2001 From: waotzi Date: Wed, 3 Mar 2021 00:03:55 +0100 Subject: [PATCH 38/51] replace vraylib link (#1627) the vraylib binding from MajorHard doesn't seem to be getting any updates, so maybe replace it with the working fork? --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 56344b100..97efa73dc 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -78,7 +78,7 @@ Here it is a list with the ones I'm aware of: | raylib-Ada | 3.0 | [Ada](https://www.adacore.com/about-ada) | https://github.com/mimo/raylib-Ada | | jaylib | 3.0 | [Janet](https://janet-lang.org/) | https://github.com/janet-lang/jaylib | | raykit | ? | [Kit](https://www.kitlang.org/) | https://github.com/Gamerfiend/raykit | -| vraylib | 2.5 | [V](https://vlang.io/) | https://github.com/MajorHard/vraylib | +| vraylib | 3.5 | [V](https://vlang.io/) | https://github.com/waotzi/vraylib | | ray.mod | 3.0 | [BlitzMax](https://blitzmax.org/) | https://github.com/bmx-ng/ray.mod | | ray-ocaml | 3.0 | [OCaml](https://ocaml.org/) | https://github.com/tjammer/raylib-ocaml | | raylib-mosaic | 3.0 | [Mosaic](https://github.com/sal55/langs/tree/master/Mosaic) | https://github.com/pluckyporcupine/raylib-mosaic | From 81908f7960005e35a50d0675e970483989cd7ff2 Mon Sep 17 00:00:00 2001 From: hristo Date: Wed, 3 Mar 2021 16:41:15 +0200 Subject: [PATCH 39/51] Removing +1 on comparing extesnions because this way it checked the file extension without the . against the file extension with the . resulting in always false. (#1629) --- src/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.c b/src/core.c index d5f588411..d7cea0be4 100644 --- a/src/core.c +++ b/src/core.c @@ -2325,7 +2325,7 @@ bool IsFileExtension(const char *fileName, const char *ext) for (int i = 0; i < extCount; i++) { - if (TextIsEqual(fileExtLower, TextToLower(checkExts[i] + 1))) + if (TextIsEqual(fileExtLower, TextToLower(checkExts[i]))) { result = true; break; From 408f5aedb8d4966aec3eea47524b7460be9446ea Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 19:36:28 +0100 Subject: [PATCH 40/51] WARNING: BREAKING: RENAMED enum values RENAMED: CubemapLayoutType and NPatchType --- examples/textures/textures_npatch_drawing.c | 14 +++++------ src/raylib.h | 18 ++++++------- src/textures.c | 28 ++++++++++----------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/textures/textures_npatch_drawing.c b/examples/textures/textures_npatch_drawing.c index 1c57e2e72..170b992f3 100644 --- a/examples/textures/textures_npatch_drawing.c +++ b/examples/textures/textures_npatch_drawing.c @@ -36,15 +36,15 @@ int main(void) Rectangle dstRecH = { 160.0f, 93.0f, 32.0f, 32.0f }; Rectangle dstRecV = { 92.0f, 160.0f, 32.0f, 32.0f }; - // A 9-patch (NPT_9PATCH) changes its sizes in both axis - NPatchInfo ninePatchInfo1 = { (Rectangle){ 0.0f, 0.0f, 64.0f, 64.0f }, 12, 40, 12, 12, NPT_9PATCH }; - NPatchInfo ninePatchInfo2 = { (Rectangle){ 0.0f, 128.0f, 64.0f, 64.0f }, 16, 16, 16, 16, NPT_9PATCH }; + // A 9-patch (NPATCH_NINE_PATCH) changes its sizes in both axis + NPatchInfo ninePatchInfo1 = { (Rectangle){ 0.0f, 0.0f, 64.0f, 64.0f }, 12, 40, 12, 12, NPATCH_NINE_PATCH }; + NPatchInfo ninePatchInfo2 = { (Rectangle){ 0.0f, 128.0f, 64.0f, 64.0f }, 16, 16, 16, 16, NPATCH_NINE_PATCH }; - // A horizontal 3-patch (NPT_3PATCH_HORIZONTAL) changes its sizes along the x axis only - NPatchInfo h3PatchInfo = { (Rectangle){ 0.0f, 64.0f, 64.0f, 64.0f }, 8, 8, 8, 8, NPT_3PATCH_HORIZONTAL }; + // A horizontal 3-patch (NPATCH_THREE_PATCH_HORIZONTAL) changes its sizes along the x axis only + NPatchInfo h3PatchInfo = { (Rectangle){ 0.0f, 64.0f, 64.0f, 64.0f }, 8, 8, 8, 8, NPATCH_THREE_PATCH_HORIZONTAL }; - // A vertical 3-patch (NPT_3PATCH_VERTICAL) changes its sizes along the y axis only - NPatchInfo v3PatchInfo = { (Rectangle){ 0.0f, 192.0f, 64.0f, 64.0f }, 6, 6, 6, 6, NPT_3PATCH_VERTICAL }; + // A vertical 3-patch (NPATCH_THREE_PATCH_VERTICAL) changes its sizes along the y axis only + NPatchInfo v3PatchInfo = { (Rectangle){ 0.0f, 192.0f, 64.0f, 64.0f }, 6, 6, 6, 6, NPATCH_THREE_PATCH_VERTICAL }; SetTargetFPS(60); //--------------------------------------------------------------------------------------- diff --git a/src/raylib.h b/src/raylib.h index 21597738f..1fb54320a 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -809,12 +809,12 @@ typedef enum { // Cubemap layouts typedef enum { - CUBEMAP_AUTO_DETECT = 0, // Automatically detect layout type - CUBEMAP_LINE_VERTICAL, // Layout is defined by a vertical line with faces - CUBEMAP_LINE_HORIZONTAL, // Layout is defined by an horizontal line with faces - CUBEMAP_CROSS_THREE_BY_FOUR, // Layout is defined by a 3x4 cross with cubemap faces - CUBEMAP_CROSS_FOUR_BY_THREE, // Layout is defined by a 4x3 cross with cubemap faces - CUBEMAP_PANORAMA // Layout is defined by a panorama image (equirectangular map) + CUBEMAP_LAYOUT_AUTO_DETECT = 0, // Automatically detect layout type + CUBEMAP_LAYOUT_LINE_VERTICAL, // Layout is defined by a vertical line with faces + CUBEMAP_LAYOUT_LINE_HORIZONTAL, // Layout is defined by an horizontal line with faces + CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR, // Layout is defined by a 3x4 cross with cubemap faces + CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE, // Layout is defined by a 4x3 cross with cubemap faces + CUBEMAP_LAYOUT_PANORAMA // Layout is defined by a panorama image (equirectangular map) } CubemapLayoutType; // Font type, defines generation method @@ -867,9 +867,9 @@ typedef enum { // N-patch types typedef enum { - NPT_9PATCH = 0, // Npatch defined by 3x3 tiles - NPT_3PATCH_VERTICAL, // Npatch defined by 1x3 tiles - NPT_3PATCH_HORIZONTAL // Npatch defined by 3x1 tiles + NPATCH_NINE_PATCH = 0, // Npatch defined by 3x3 tiles + NPATCH_THREE_PATCH_VERTICAL, // Npatch defined by 1x3 tiles + NPATCH_THREE_PATCH_HORIZONTAL // Npatch defined by 3x1 tiles } NPatchType; // Callbacks to be implemented by users diff --git a/src/textures.c b/src/textures.c index 7ef3903d9..2c5921994 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2749,7 +2749,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) { TextureCubemap cubemap = { 0 }; - if (layoutType == CUBEMAP_AUTO_DETECT) // Try to automatically guess layout type + if (layoutType == CUBEMAP_LAYOUT_AUTO_DETECT) // Try to automatically guess layout type { // Check image width/height to determine the type of cubemap provided if (image.width > image.height) @@ -2767,7 +2767,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) cubemap.height = cubemap.width; } - if (layoutType != CUBEMAP_AUTO_DETECT) + if (layoutType != CUBEMAP_LAYOUT_AUTO_DETECT) { int size = cubemap.width; @@ -2775,20 +2775,20 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) Rectangle faceRecs[6] = { 0 }; // Face source rectangles for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size }; - if (layoutType == CUBEMAP_LINE_VERTICAL) + if (layoutType == CUBEMAP_LAYOUT_LINE_VERTICAL) { faces = image; for (int i = 0; i < 6; i++) faceRecs[i].y = (float)size*i; } - else if (layoutType == CUBEMAP_PANORAMA) + else if (layoutType == CUBEMAP_LAYOUT_PANORAMA) { // TODO: Convert panorama image to square faces... // Ref: https://github.com/denivip/panorama/blob/master/panorama.cpp } else { - if (layoutType == CUBEMAP_LINE_HORIZONTAL) for (int i = 0; i < 6; i++) faceRecs[i].x = (float)size*i; - else if (layoutType == CUBEMAP_CROSS_THREE_BY_FOUR) + if (layoutType == CUBEMAP_LAYOUT_LINE_HORIZONTAL) for (int i = 0; i < 6; i++) faceRecs[i].x = (float)size*i; + else if (layoutType == CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR) { faceRecs[0].x = (float)size; faceRecs[0].y = (float)size; faceRecs[1].x = (float)size; faceRecs[1].y = (float)size*3; @@ -2797,7 +2797,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) faceRecs[4].x = 0; faceRecs[4].y = (float)size; faceRecs[5].x = (float)size*2; faceRecs[5].y = (float)size; } - else if (layoutType == CUBEMAP_CROSS_FOUR_BY_THREE) + else if (layoutType == CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE) { faceRecs[0].x = (float)size*2; faceRecs[0].y = (float)size; faceRecs[1].x = 0; faceRecs[1].y = (float)size; @@ -3251,8 +3251,8 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, if (nPatchInfo.source.width < 0) nPatchInfo.source.x -= nPatchInfo.source.width; if (nPatchInfo.source.height < 0) nPatchInfo.source.y -= nPatchInfo.source.height; - if (nPatchInfo.type == NPT_3PATCH_HORIZONTAL) patchHeight = nPatchInfo.source.height; - if (nPatchInfo.type == NPT_3PATCH_VERTICAL) patchWidth = nPatchInfo.source.width; + if (nPatchInfo.type == NPATCH_THREE_PATCH_HORIZONTAL) patchHeight = nPatchInfo.source.height; + if (nPatchInfo.type == NPATCH_THREE_PATCH_VERTICAL) patchWidth = nPatchInfo.source.width; bool drawCenter = true; bool drawMiddle = true; @@ -3262,14 +3262,14 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, float bottomBorder = (float)nPatchInfo.bottom; // adjust the lateral (left and right) border widths in case patchWidth < texture.width - if (patchWidth <= (leftBorder + rightBorder) && nPatchInfo.type != NPT_3PATCH_VERTICAL) + if (patchWidth <= (leftBorder + rightBorder) && nPatchInfo.type != NPATCH_THREE_PATCH_VERTICAL) { drawCenter = false; leftBorder = (leftBorder/(leftBorder + rightBorder))*patchWidth; rightBorder = patchWidth - leftBorder; } // adjust the lateral (top and bottom) border heights in case patchHeight < texture.height - if (patchHeight <= (topBorder + bottomBorder) && nPatchInfo.type != NPT_3PATCH_HORIZONTAL) + if (patchHeight <= (topBorder + bottomBorder) && nPatchInfo.type != NPATCH_THREE_PATCH_HORIZONTAL) { drawMiddle = false; topBorder = (topBorder/(topBorder + bottomBorder))*patchHeight; @@ -3307,7 +3307,7 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer - if (nPatchInfo.type == NPT_9PATCH) + if (nPatchInfo.type == NPATCH_NINE_PATCH) { // ------------------------------------------------------------ // TOP-LEFT QUAD @@ -3373,7 +3373,7 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Top-right corner for texture and quad rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); // Top-left corner for texture and quad } - else if (nPatchInfo.type == NPT_3PATCH_VERTICAL) + else if (nPatchInfo.type == NPATCH_THREE_PATCH_VERTICAL) { // TOP QUAD // ----------------------------------------------------------- @@ -3400,7 +3400,7 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Top-right corner for texture and quad rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); // Top-left corner for texture and quad } - else if (nPatchInfo.type == NPT_3PATCH_HORIZONTAL) + else if (nPatchInfo.type == NPATCH_THREE_PATCH_HORIZONTAL) { // LEFT QUAD // ----------------------------------------------------------- From dfe797060abe25f5f17a875bdb5168b2e0c654f7 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 19:47:37 +0100 Subject: [PATCH 41/51] WARNING: BREAKING: RENAMED: enums values RENAMED: TextureFilterMode values RENAMED: TextureWrapMode values --- src/core.c | 2 +- src/raylib.h | 23 ++++++++------- src/rlgl.h | 39 ++++++++++++------------ src/text.c | 4 +-- src/textures.c | 80 +++++++++++++++++++++++++------------------------- 5 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/core.c b/src/core.c index d7cea0be4..889eae8a0 100644 --- a/src/core.c +++ b/src/core.c @@ -754,7 +754,7 @@ void InitWindow(int width, int height, const char *title) if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) { // Set default font texture filter for HighDPI (blurry) - SetTextureFilter(GetFontDefault().texture, FILTER_BILINEAR); + SetTextureFilter(GetFontDefault().texture, TEXTURE_FILTER_BILINEAR); } #endif diff --git a/src/raylib.h b/src/raylib.h index 1fb54320a..470ffa70a 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -157,7 +157,8 @@ #define LoadText LoadFileText #define GetExtension GetFileExtension #define GetImageData LoadImageColors -//#define Fade(c, a) ColorAlpha(c, a) +#define FILTER_POINT TEXTURE_FILTER_POINT +#define FILTER_BILINEAR TEXTURE_FILTER_BILINEAR //---------------------------------------------------------------------------------- // Structures Definition @@ -791,20 +792,20 @@ typedef enum { // NOTE 1: Filtering considers mipmaps if available in the texture // NOTE 2: Filter is accordingly set for minification and magnification typedef enum { - FILTER_POINT = 0, // No filter, just pixel aproximation - FILTER_BILINEAR, // Linear filtering - FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) - FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x - FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x - FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x + TEXTURE_FILTER_POINT = 0, // No filter, just pixel aproximation + TEXTURE_FILTER_BILINEAR, // Linear filtering + TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x } TextureFilterMode; // Texture parameters: wrap mode typedef enum { - WRAP_REPEAT = 0, // Repeats texture in tiled mode - WRAP_CLAMP, // Clamps texture to edge pixel in tiled mode - WRAP_MIRROR_REPEAT, // Mirrors and repeats the texture in tiled mode - WRAP_MIRROR_CLAMP // Mirrors and clamps to border the texture in tiled mode + TEXTURE_WRAP_REPEAT = 0, // Repeats texture in tiled mode + TEXTURE_WRAP_CLAMP, // Clamps texture to edge pixel in tiled mode + TEXTURE_WRAP_MIRROR_REPEAT, // Mirrors and repeats the texture in tiled mode + TEXTURE_WRAP_MIRROR_CLAMP // Mirrors and clamps to border the texture in tiled mode } TextureWrapMode; // Cubemap layouts diff --git a/src/rlgl.h b/src/rlgl.h index 703821f0d..21cea8ca3 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -185,19 +185,19 @@ #define RL_TEXTURE_WRAP_T 0x2803 // GL_TEXTURE_WRAP_T #define RL_TEXTURE_MAG_FILTER 0x2800 // GL_TEXTURE_MAG_FILTER #define RL_TEXTURE_MIN_FILTER 0x2801 // GL_TEXTURE_MIN_FILTER -#define RL_TEXTURE_ANISOTROPIC_FILTER 0x3000 // Anisotropic filter (custom identifier) -#define RL_FILTER_NEAREST 0x2600 // GL_NEAREST -#define RL_FILTER_LINEAR 0x2601 // GL_LINEAR -#define RL_FILTER_MIP_NEAREST 0x2700 // GL_NEAREST_MIPMAP_NEAREST -#define RL_FILTER_NEAREST_MIP_LINEAR 0x2702 // GL_NEAREST_MIPMAP_LINEAR -#define RL_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST -#define RL_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR +#define RL_TEXTURE_FILTER_NEAREST 0x2600 // GL_NEAREST +#define RL_TEXTURE_FILTER_LINEAR 0x2601 // GL_LINEAR +#define RL_TEXTURE_FILTER_MIP_NEAREST 0x2700 // GL_NEAREST_MIPMAP_NEAREST +#define RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR 0x2702 // GL_NEAREST_MIPMAP_LINEAR +#define RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST +#define RL_TEXTURE_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR +#define RL_TEXTURE_FILTER_ANISOTROPIC 0x3000 // Anisotropic filter (custom identifier) -#define RL_WRAP_REPEAT 0x2901 // GL_REPEAT -#define RL_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE -#define RL_WRAP_MIRROR_REPEAT 0x8370 // GL_MIRRORED_REPEAT -#define RL_WRAP_MIRROR_CLAMP 0x8742 // GL_MIRROR_CLAMP_EXT +#define RL_TEXTURE_WRAP_REPEAT 0x2901 // GL_REPEAT +#define RL_TEXTURE_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE +#define RL_TEXTURE_WRAP_MIRROR_REPEAT 0x8370 // GL_MIRRORED_REPEAT +#define RL_TEXTURE_WRAP_MIRROR_CLAMP 0x8742 // GL_MIRROR_CLAMP_EXT // Matrix modes (equivalent to OpenGL) #define RL_MODELVIEW 0x1700 // GL_MODELVIEW @@ -391,12 +391,12 @@ typedef enum { // NOTE 1: Filtering considers mipmaps if available in the texture // NOTE 2: Filter is accordingly set for minification and magnification typedef enum { - FILTER_POINT = 0, // No filter, just pixel aproximation - FILTER_BILINEAR, // Linear filtering - FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) - FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x - FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x - FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x + TEXTURE_FILTER_POINT = 0, // No filter, just pixel aproximation + TEXTURE_FILTER_BILINEAR, // Linear filtering + TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x } TextureFilterMode; // Color blending modes (pre-defined) @@ -1383,6 +1383,7 @@ void rlTextureParameters(unsigned int id, int param, int value) case RL_TEXTURE_WRAP_T: { if (value == RL_WRAP_MIRROR_CLAMP) + if (value == RL_TEXTURE_WRAP_MIRROR_CLAMP) { #if !defined(GRAPHICS_API_OPENGL_11) if (RLGL.ExtSupported.texMirrorClamp) glTexParameteri(GL_TEXTURE_2D, param, value); @@ -1394,7 +1395,7 @@ void rlTextureParameters(unsigned int id, int param, int value) } break; case RL_TEXTURE_MAG_FILTER: case RL_TEXTURE_MIN_FILTER: glTexParameteri(GL_TEXTURE_2D, param, value); break; - case RL_TEXTURE_ANISOTROPIC_FILTER: + case RL_TEXTURE_FILTER_ANISOTROPIC: { #if !defined(GRAPHICS_API_OPENGL_11) if (value <= RLGL.ExtSupported.maxAnisotropicLevel) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value); @@ -3633,7 +3634,7 @@ TextureCubemap GenTexturePrefilter(Shader shader, TextureCubemap cubemap, int si //------------------------------------------------------------------------------------------ unsigned int rbo = rlLoadTextureDepth(size, size, true); prefilter.id = rlLoadTextureCubemap(NULL, size, UNCOMPRESSED_R32G32B32); - rlTextureParameters(prefilter.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_MIP_LINEAR); + rlTextureParameters(prefilter.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_MIP_LINEAR); unsigned int fbo = rlLoadFramebuffer(size, size); rlFramebufferAttach(fbo, rbo, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER); diff --git a/src/text.c b/src/text.c index e0b0b324d..be8ab48c1 100644 --- a/src/text.c +++ b/src/text.c @@ -328,7 +328,7 @@ Font LoadFont(const char *fileName) TRACELOG(LOG_WARNING, "FONT: [%s] Failed to load font texture -> Using default font", fileName); font = GetFontDefault(); } - else SetTextureFilter(font.texture, FILTER_POINT); // By default we set point filter (best performance) + else SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); // By default we set point filter (best performance) return font; } @@ -432,7 +432,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) } // NOTE: We need to remove key color borders from image to avoid weird - // artifacts on texture scaling when using FILTER_BILINEAR or FILTER_TRILINEAR + // artifacts on texture scaling when using TEXTURE_FILTER_BILINEAR or TEXTURE_FILTER_TRILINEAR for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK; // Create a new image with the processed color data (key color replaced by BLANK) diff --git a/src/textures.c b/src/textures.c index 2c5921994..dcdbe5c74 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2967,63 +2967,63 @@ void SetTextureFilter(Texture2D texture, int filterMode) { switch (filterMode) { - case FILTER_POINT: + case TEXTURE_FILTER_POINT: { if (texture.mipmaps > 1) { - // RL_FILTER_MIP_NEAREST - tex filter: POINT, mipmaps filter: POINT (sharp switching between mipmaps) - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_MIP_NEAREST); + // RL_TEXTURE_FILTER_MIP_NEAREST - tex filter: POINT, mipmaps filter: POINT (sharp switching between mipmaps) + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_MIP_NEAREST); - // RL_FILTER_NEAREST - tex filter: POINT (no filter), no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_NEAREST); + // RL_TEXTURE_FILTER_NEAREST - tex filter: POINT (no filter), no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_NEAREST); } else { - // RL_FILTER_NEAREST - tex filter: POINT (no filter), no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_NEAREST); - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_NEAREST); + // RL_TEXTURE_FILTER_NEAREST - tex filter: POINT (no filter), no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_NEAREST); + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_NEAREST); } } break; - case FILTER_BILINEAR: + case TEXTURE_FILTER_BILINEAR: { if (texture.mipmaps > 1) { - // RL_FILTER_LINEAR_MIP_NEAREST - tex filter: BILINEAR, mipmaps filter: POINT (sharp switching between mipmaps) - // Alternative: RL_FILTER_NEAREST_MIP_LINEAR - tex filter: POINT, mipmaps filter: BILINEAR (smooth transition between mipmaps) - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_LINEAR_MIP_NEAREST); + // RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST - tex filter: BILINEAR, mipmaps filter: POINT (sharp switching between mipmaps) + // Alternative: RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR - tex filter: POINT, mipmaps filter: BILINEAR (smooth transition between mipmaps) + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST); - // RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR); + // RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR); } else { - // RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_LINEAR); - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR); + // RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR); + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR); } } break; - case FILTER_TRILINEAR: + case TEXTURE_FILTER_TRILINEAR: { if (texture.mipmaps > 1) { - // RL_FILTER_MIP_LINEAR - tex filter: BILINEAR, mipmaps filter: BILINEAR (smooth transition between mipmaps) - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_MIP_LINEAR); + // RL_TEXTURE_FILTER_MIP_LINEAR - tex filter: BILINEAR, mipmaps filter: BILINEAR (smooth transition between mipmaps) + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_MIP_LINEAR); - // RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR); + // RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR); } else { TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] No mipmaps available for TRILINEAR texture filtering", texture.id); - // RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps - rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_LINEAR); - rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR); + // RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps + rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR); + rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR); } } break; - case FILTER_ANISOTROPIC_4X: rlTextureParameters(texture.id, RL_TEXTURE_ANISOTROPIC_FILTER, 4); break; - case FILTER_ANISOTROPIC_8X: rlTextureParameters(texture.id, RL_TEXTURE_ANISOTROPIC_FILTER, 8); break; - case FILTER_ANISOTROPIC_16X: rlTextureParameters(texture.id, RL_TEXTURE_ANISOTROPIC_FILTER, 16); break; + case TEXTURE_FILTER_ANISOTROPIC_4X: rlTextureParameters(texture.id, RL_TEXTURE_FILTER_ANISOTROPIC, 4); break; + case TEXTURE_FILTER_ANISOTROPIC_8X: rlTextureParameters(texture.id, RL_TEXTURE_FILTER_ANISOTROPIC, 8); break; + case TEXTURE_FILTER_ANISOTROPIC_16X: rlTextureParameters(texture.id, RL_TEXTURE_FILTER_ANISOTROPIC, 16); break; default: break; } } @@ -3033,25 +3033,25 @@ void SetTextureWrap(Texture2D texture, int wrapMode) { switch (wrapMode) { - case WRAP_REPEAT: + case TEXTURE_WRAP_REPEAT: { - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_WRAP_REPEAT); - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_WRAP_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_REPEAT); } break; - case WRAP_CLAMP: + case TEXTURE_WRAP_CLAMP: { - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_WRAP_CLAMP); - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_WRAP_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_CLAMP); } break; - case WRAP_MIRROR_REPEAT: + case TEXTURE_WRAP_MIRROR_REPEAT: { - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_WRAP_MIRROR_REPEAT); - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_WRAP_MIRROR_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_REPEAT); } break; - case WRAP_MIRROR_CLAMP: + case TEXTURE_WRAP_MIRROR_CLAMP: { - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_WRAP_MIRROR_CLAMP); - rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_WRAP_MIRROR_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_CLAMP); } break; default: break; } From 0b108c2087c7e690993f1f25647fd840f9f39aaa Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 19:49:10 +0100 Subject: [PATCH 42/51] Corrected bug --- src/rlgl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index 21cea8ca3..4fba97365 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1382,7 +1382,6 @@ void rlTextureParameters(unsigned int id, int param, int value) case RL_TEXTURE_WRAP_S: case RL_TEXTURE_WRAP_T: { - if (value == RL_WRAP_MIRROR_CLAMP) if (value == RL_TEXTURE_WRAP_MIRROR_CLAMP) { #if !defined(GRAPHICS_API_OPENGL_11) From c938d71d15192ba62049294d715bcffd65d44eea Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 19:51:23 +0100 Subject: [PATCH 43/51] Corrected issue with enums renamed --- src/textures.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/textures.c b/src/textures.c index dcdbe5c74..ea3bd3712 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2754,14 +2754,14 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) // Check image width/height to determine the type of cubemap provided if (image.width > image.height) { - if ((image.width/6) == image.height) { layoutType = CUBEMAP_LINE_HORIZONTAL; cubemap.width = image.width/6; } - else if ((image.width/4) == (image.height/3)) { layoutType = CUBEMAP_CROSS_FOUR_BY_THREE; cubemap.width = image.width/4; } - else if (image.width >= (int)((float)image.height*1.85f)) { layoutType = CUBEMAP_PANORAMA; cubemap.width = image.width/4; } + if ((image.width/6) == image.height) { layoutType = CUBEMAP_LAYOUT_LINE_HORIZONTAL; cubemap.width = image.width/6; } + else if ((image.width/4) == (image.height/3)) { layoutType = CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE; cubemap.width = image.width/4; } + else if (image.width >= (int)((float)image.height*1.85f)) { layoutType = CUBEMAP_LAYOUT_PANORAMA; cubemap.width = image.width/4; } } else if (image.height > image.width) { - if ((image.height/6) == image.width) { layoutType = CUBEMAP_LINE_VERTICAL; cubemap.width = image.height/6; } - else if ((image.width/3) == (image.height/4)) { layoutType = CUBEMAP_CROSS_THREE_BY_FOUR; cubemap.width = image.width/3; } + if ((image.height/6) == image.width) { layoutType = CUBEMAP_LAYOUT_LINE_VERTICAL; cubemap.width = image.height/6; } + else if ((image.width/3) == (image.height/4)) { layoutType = CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR; cubemap.width = image.width/3; } } cubemap.height = cubemap.width; @@ -3035,23 +3035,23 @@ void SetTextureWrap(Texture2D texture, int wrapMode) { case TEXTURE_WRAP_REPEAT: { - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_REPEAT); - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_REPEAT); } break; case TEXTURE_WRAP_CLAMP: { - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_CLAMP); - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_CLAMP); } break; case TEXTURE_WRAP_MIRROR_REPEAT: { - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_REPEAT); - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_REPEAT); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_REPEAT); } break; case TEXTURE_WRAP_MIRROR_CLAMP: { - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_CLAMP); - rlTextureParameters(texture.id, RL_TEXTURE_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_S, RL_TEXTURE_WRAP_MIRROR_CLAMP); + rlTextureParameters(texture.id, RL_TEXTURE_WRAP_T, RL_TEXTURE_WRAP_MIRROR_CLAMP); } break; default: break; } From ca22a8794977aadce9a90f41bdb7693b16e3010f Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 19:55:09 +0100 Subject: [PATCH 44/51] REVIEWED: TextFormat() #1626 --- src/text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text.c b/src/text.c index be8ab48c1..204cc4e38 100644 --- a/src/text.c +++ b/src/text.c @@ -1175,7 +1175,7 @@ const char *TextFormat(const char *text, ...) va_list args; va_start(args, text); - vsprintf(currentBuffer, text, args); + vsnprintf(currentBuffer, MAX_TEXT_BUFFER_LENGTH, text, args); va_end(args); index += 1; // Move to next buffer for next function call From c8ed231eca7a602bddea5e9c4f710ab503dd4d38 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Mar 2021 23:05:52 +0100 Subject: [PATCH 45/51] Update text_font_filters.c --- examples/text/text_font_filters.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/text/text_font_filters.c b/examples/text/text_font_filters.c index d90c4277c..9ad5cff4e 100644 --- a/examples/text/text_font_filters.c +++ b/examples/text/text_font_filters.c @@ -40,8 +40,8 @@ int main(void) Vector2 textSize = { 0.0f, 0.0f }; // Setup texture scaling filter - SetTextureFilter(font.texture, FILTER_POINT); - int currentFontFilter = 0; // FILTER_POINT + SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); + int currentFontFilter = 0; // TEXTURE_FILTER_POINT SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -56,18 +56,18 @@ int main(void) // Choose font texture filter method if (IsKeyPressed(KEY_ONE)) { - SetTextureFilter(font.texture, FILTER_POINT); + SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); currentFontFilter = 0; } else if (IsKeyPressed(KEY_TWO)) { - SetTextureFilter(font.texture, FILTER_BILINEAR); + SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR); currentFontFilter = 1; } else if (IsKeyPressed(KEY_THREE)) { // NOTE: Trilinear filter won't be noticed on 2D drawing - SetTextureFilter(font.texture, FILTER_TRILINEAR); + SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR); currentFontFilter = 2; } From af3926af4b81fdd72c2b40617675f8de15fa17cc Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 11:51:54 +0100 Subject: [PATCH 46/51] REVIEWED: Examples to new enum values --- examples/models/models_first_person_maze.c | 4 ---- examples/models/models_skybox.c | 4 ++-- examples/textures/textures_draw_tiled.c | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/models/models_first_person_maze.c b/examples/models/models_first_person_maze.c index 2d37e978c..6899a4dd1 100644 --- a/examples/models/models_first_person_maze.c +++ b/examples/models/models_first_person_maze.c @@ -39,7 +39,6 @@ int main(void) UnloadImage(imMap); // Unload image from RAM Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position - Vector3 playerPosition = camera.position; // Set player position SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode @@ -93,10 +92,7 @@ int main(void) ClearBackground(RAYWHITE); BeginMode3D(camera); - DrawModel(model, mapPosition, 1.0f, WHITE); // Draw maze map - //DrawCubeV(playerPosition, (Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player - EndMode3D(); DrawTextureEx(cubicmap, (Vector2){ GetScreenWidth() - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE); diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index ad9c46c22..2b8b65f45 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -69,7 +69,7 @@ int main(void) else { Image img = LoadImage("resources/skybox.png"); - skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_AUTO_DETECT); + skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_LAYOUT_AUTO_DETECT); // CUBEMAP_LAYOUT_PANORAMA UnloadImage(img); } @@ -108,7 +108,7 @@ int main(void) else { Image img = LoadImage(droppedFiles[0]); - skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_AUTO_DETECT); + skybox.materials[0].maps[MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_LAYOUT_AUTO_DETECT); UnloadImage(img); } diff --git a/examples/textures/textures_draw_tiled.c b/examples/textures/textures_draw_tiled.c index faf2d1711..7d8a3c419 100644 --- a/examples/textures/textures_draw_tiled.c +++ b/examples/textures/textures_draw_tiled.c @@ -27,7 +27,7 @@ int main(int argc, char **argv) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Texture texPattern = LoadTexture("resources/patterns.png"); - SetTextureFilter(texPattern, FILTER_TRILINEAR); // Makes the texture smoother when upscaled + SetTextureFilter(texPattern, TEXTURE_FILTER_TRILINEAR); // Makes the texture smoother when upscaled // Coordinates for all patterns inside the texture const Rectangle recPattern[] = { From c4a7c702b4d8c1d6cc18b4bfa3f90ae9e53a878d Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 12:06:28 +0100 Subject: [PATCH 47/51] FEATURE: Several callbacks added -WIP- #1523 #1329 NOTE: This feature is still under consideration and not complete. --- src/raylib.h | 20 +++++++++----- src/utils.c | 75 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 470ffa70a..198fbac25 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -876,10 +876,13 @@ typedef enum { // Callbacks to be implemented by users typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); typedef void *(*MemAllocCallback)(int size); -typedef void *(*MemReallocCallback)(int size); +typedef void *(*MemReallocCallback)(void *ptr, int size); typedef void (*MemFreeCallback)(void *ptr); -typedef unsigned char* (*LoadFileDataCallback)(const char* fileName, unsigned int* bytesRead); // Load file data as byte array (read) -typedef char* (*LoadFileTextCallback)(const char* fileName); // Load text data from file (read), returns a '\0' terminated string +typedef unsigned char* (*LoadFileDataCallback)(const char* fileName, unsigned int* bytesRead); +typedef void (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); +typedef char *(*LoadFileTextCallback)(const char* fileName); +typedef void (*SaveFileTextCallback)(const char *fileName, char *text); + #if defined(__cplusplus) extern "C" { // Prevents name mangling of functions @@ -979,15 +982,18 @@ RLAPI void SetConfigFlags(unsigned int flags); // Setup init RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR) RLAPI void SetTraceLogLevel(int logType); // Set the current threshold (minimum) log level RLAPI void *MemAlloc(int size); // Internal memory allocator +RLAPI void *MemRealloc(void *ptr, int size); // Internal memory reallocator RLAPI void MemFree(void *ptr); // Internal memory free -// Set system callbacks -RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set a trace log callback to enable custom logging +// Set custom system callbacks +RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log RLAPI void SetMemAllocCallback(MemAllocCallback callback); // Set custom memory allocator RLAPI void SetMemReallocCallback(MemReallocCallback callback); // Set custom memory reallocator RLAPI void SetMemFreeCallback(MemFreeCallback callback); // Set custom memory free -RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // override default file access functions -RLAPI void SetLoadFileTextCallback(LoadFileDataCallback callback); // override default file access functions +RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file data loader +RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file data saver +RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text loader +RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text saver // Files management functions RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read) diff --git a/src/utils.c b/src/utils.c index 428301157..7c9fa41d0 100644 --- a/src/utils.c +++ b/src/utils.c @@ -65,9 +65,29 @@ //---------------------------------------------------------------------------------- // Log types messages -static int logTypeLevel = LOG_INFO; // Minimum log type level -static int logTypeExit = LOG_ERROR; // Log type that exits -static TraceLogCallback logCallback = NULL; // Log callback function pointer +static int logTypeLevel = LOG_INFO; // Minimum log type level + +static TraceLogCallback traceLog = NULL; // TraceLog callback function pointer +static MemAllocCallback memAlloc = NULL; // MemAlloc callback function pointer +static MemReallocCallback memRealloc = NULL; // MemRealloc callback funtion pointer +static MemFreeCallback memFree = NULL; // MemFree callback funtion pointer +static LoadFileDataCallback loadFileData = NULL; // LoadFileData callback funtion pointer +static SaveFileDataCallback saveFileData = NULL; // SaveFileText callback funtion pointer +static LoadFileTextCallback loadFileText = NULL; // LoadFileText callback funtion pointer +static SaveFileTextCallback saveFileText = NULL; // SaveFileText callback funtion pointer + +//void *MemAllocDefault(unsigned int size) { return RL_MALLOC(size); } +//void MemFreeDefault(void *ptr) { RL_FREE(ptr); } + +void SetTraceLogCallback(TraceLogCallback callback) { traceLog = callback; } // Set custom trace log +void SetMemAllocCallback(MemAllocCallback callback) { memAlloc = callback; } // Set custom memory allocator +void SetMemReallocCallback(MemReallocCallback callback) { memRealloc = callback; } // Set custom memory reallocator +void SetMemFreeCallback(MemFreeCallback callback) { memFree = callback; } // Set custom memory free +void SetLoadFileDataCallback(LoadFileDataCallback callback) { loadFileData = callback; } // Set custom file data loader +void SetSaveFileDataCallback(SaveFileDataCallback callback) { saveFileData = callback; } // Set custom file data saver +void SetLoadFileTextCallback(LoadFileTextCallback callback) { loadFileText = callback; } // Set custom file text loader +void SetSaveFileTextCallback(SaveFileTextCallback callback) { saveFileText = callback; } // Set custom file text saver + #if defined(PLATFORM_ANDROID) static AAssetManager *assetManager = NULL; // Android assets manager pointer @@ -92,16 +112,7 @@ static int android_close(void *cookie); //---------------------------------------------------------------------------------- // Set the current threshold (minimum) log level -void SetTraceLogLevel(int logType) -{ - logTypeLevel = logType; -} - -// Set a trace log callback to enable custom logging -void SetTraceLogCallback(TraceLogCallback callback) -{ - logCallback = callback; -} +void SetTraceLogLevel(int logType) { logTypeLevel = logType; } // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG) void TraceLog(int logType, const char *text, ...) @@ -113,9 +124,9 @@ void TraceLog(int logType, const char *text, ...) va_list args; va_start(args, text); - if (logCallback) + if (traceLog) { - logCallback(logType, text, args); + traceLog(logType, text, args); va_end(args); return; } @@ -152,21 +163,37 @@ void TraceLog(int logType, const char *text, ...) va_end(args); - if (logType >= logTypeExit) exit(1); // If exit message, exit program + if (logType == LOG_ERROR) exit(1); // If error, exit program #endif // SUPPORT_TRACELOG } // Internal memory allocator +// NOTE: Initializes to zero by default void *MemAlloc(int size) { - return RL_MALLOC(size); + // WARNING: This implementation allows changing memAlloc at any + // point during program execution, it could be a security risk + void *ptr = NULL; + if (memAlloc) ptr = memAlloc(size); + else ptr = RL_CALLOC(size, 1); + return ptr; +} + +// Internal memory reallocator +void *MemRealloc(void *ptr, int size) +{ + void *ret = NULL; + if (memRealloc) ret = memRealloc(ptr, size); + else ret = RL_REALLOC(ptr, size); + return ret; } // Internal memory free void MemFree(void *ptr) { - RL_FREE(ptr); + if (memFree) memFree(ptr); + else RL_FREE(ptr); } // Load data from file into a buffer @@ -177,6 +204,12 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) if (fileName != NULL) { + if (loadFileData) + { + data = loadFileData(fileName, bytesRead); + return data; + } + FILE *file = fopen(fileName, "rb"); if (file != NULL) @@ -222,6 +255,12 @@ bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite) if (fileName != NULL) { + if (saveFileData) + { + saveFileData(fileName, data, bytesToWrite); + return success; + } + FILE *file = fopen(fileName, "wb"); if (file != NULL) From 1ed72b7812ba1749107d1f20fbfe331e54acf1a2 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 12:08:54 +0100 Subject: [PATCH 48/51] Minor struct organization tweak --- src/raudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 050b37de9..aaac982e9 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -343,8 +343,8 @@ typedef struct AudioData { int defaultSize; // Default audio buffer size for audio streams } Buffer; struct { - AudioBuffer *pool[MAX_AUDIO_BUFFER_POOL_CHANNELS]; // Multichannel AudioBuffer pointers pool unsigned int poolCounter; // AudioBuffer pointers pool counter + AudioBuffer *pool[MAX_AUDIO_BUFFER_POOL_CHANNELS]; // Multichannel AudioBuffer pointers pool unsigned int channels[MAX_AUDIO_BUFFER_POOL_CHANNELS]; // AudioBuffer pool channels } MultiChannel; } AudioData; From 7ad1370193cf963b4142f480130a77803e9e682e Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 20:22:58 +0100 Subject: [PATCH 49/51] Some naming tweaks --- src/rlgl.h | 14 +++++++------- src/utils.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 4fba97365..d77608d81 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -4915,21 +4915,21 @@ char *LoadFileText(const char *fileName) if (fileName != NULL) { - FILE *textFile = fopen(fileName, "rt"); + FILE *file = fopen(fileName, "rt"); - if (textFile != NULL) + if (file != NULL) { // WARNING: When reading a file as 'text' file, // text mode causes carriage return-linefeed translation... // ...but using fseek() should return correct byte-offset - fseek(textFile, 0, SEEK_END); - int size = ftell(textFile); - fseek(textFile, 0, SEEK_SET); + fseek(file, 0, SEEK_END); + int size = ftell(file); + fseek(file, 0, SEEK_SET); if (size > 0) { text = (char *)RL_MALLOC((size + 1)*sizeof(char)); - int count = (int)fread(text, sizeof(char), size, textFile); + int count = (int)fread(text, sizeof(char), size, file); // WARNING: \r\n is converted to \n on reading, so, // read bytes count gets reduced by the number of lines @@ -4942,7 +4942,7 @@ char *LoadFileText(const char *fileName) } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to read text file", fileName); - fclose(textFile); + fclose(file); } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open text file", fileName); } diff --git a/src/utils.c b/src/utils.c index 7c9fa41d0..000be3730 100644 --- a/src/utils.c +++ b/src/utils.c @@ -45,7 +45,7 @@ #include // Required for: Android assets manager: AAsset, AAssetManager_open(), ... #endif -#include // Required for: exit() +#include // Required for: exit(), FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), fclose() #include // Required for: vprintf() #include // Required for: va_list, va_start(), va_end() #include // Required for: strcpy(), strcat() @@ -289,21 +289,21 @@ char *LoadFileText(const char *fileName) if (fileName != NULL) { - FILE *textFile = fopen(fileName, "rt"); + FILE *file = fopen(fileName, "rt"); - if (textFile != NULL) + if (file != NULL) { // WARNING: When reading a file as 'text' file, // text mode causes carriage return-linefeed translation... // ...but using fseek() should return correct byte-offset - fseek(textFile, 0, SEEK_END); - unsigned int size = (unsigned int)ftell(textFile); - fseek(textFile, 0, SEEK_SET); + fseek(file, 0, SEEK_END); + unsigned int size = (unsigned int)ftell(file); + fseek(file, 0, SEEK_SET); if (size > 0) { text = (char *)RL_MALLOC((size + 1)*sizeof(char)); - unsigned int count = (unsigned int)fread(text, sizeof(char), size, textFile); + unsigned int count = (unsigned int)fread(text, sizeof(char), size, file); // WARNING: \r\n is converted to \n on reading, so, // read bytes count gets reduced by the number of lines @@ -316,7 +316,7 @@ char *LoadFileText(const char *fileName) } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to read text file", fileName); - fclose(textFile); + fclose(file); } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open text file", fileName); } From b0845528081e33a163ad50707310f848046352b4 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 20:36:04 +0100 Subject: [PATCH 50/51] ADDED: Config flag: SUPPORT_STANDARD_FILEIO This new flag allows omitting stdio.h library in case of a custom implementation is used. --- src/config.h | 2 ++ src/textures.c | 1 - src/utils.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/config.h b/src/config.h index ce943901d..d0c8cfdd9 100644 --- a/src/config.h +++ b/src/config.h @@ -203,6 +203,8 @@ //------------------------------------------------------------------------------------ // Module: utils - Configuration Flags //------------------------------------------------------------------------------------ +// Standard file io library (stdio.h) included +#define SUPPORT_STANDARD_FILEIO // Show TRACELOG() output messages // NOTE: By default LOG_DEBUG traces not shown #define SUPPORT_TRACELOG 1 diff --git a/src/textures.c b/src/textures.c index ea3bd3712..0d78c2a26 100644 --- a/src/textures.c +++ b/src/textures.c @@ -65,7 +65,6 @@ #endif #include // Required for: malloc(), free() -#include // Required for: FILE, fopen(), fclose(), fread() #include // Required for: strlen() [Used in ImageTextEx()] #include // Required for: fabsf() diff --git a/src/utils.c b/src/utils.c index 000be3730..568c6c886 100644 --- a/src/utils.c +++ b/src/utils.c @@ -45,8 +45,8 @@ #include // Required for: Android assets manager: AAsset, AAssetManager_open(), ... #endif -#include // Required for: exit(), FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), fclose() -#include // Required for: vprintf() +#include // Required for: exit() +#include // Required for: FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), vprintf(), fclose() #include // Required for: va_list, va_start(), va_end() #include // Required for: strcpy(), strcat() @@ -209,7 +209,7 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) data = loadFileData(fileName, bytesRead); return data; } - +#if defined(SUPPORT_STANDARD_FILEIO) FILE *file = fopen(fileName, "rb"); if (file != NULL) @@ -236,6 +236,9 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) fclose(file); } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open file", fileName); +#else + TRACELOG(LOG_WARNING, "FILEIO: Standard file io not supported, use custom file callback"); +#endif } else TRACELOG(LOG_WARNING, "FILEIO: File name provided is not valid"); @@ -260,7 +263,7 @@ bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite) saveFileData(fileName, data, bytesToWrite); return success; } - +#if defined(SUPPORT_STANDARD_FILEIO) FILE *file = fopen(fileName, "wb"); if (file != NULL) @@ -275,6 +278,9 @@ bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite) if (result == 0) success = true; } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open file", fileName); +#else + TRACELOG(LOG_WARNING, "FILEIO: Standard file io not supported, use custom file callback"); +#endif } else TRACELOG(LOG_WARNING, "FILEIO: File name provided is not valid"); @@ -289,6 +295,12 @@ char *LoadFileText(const char *fileName) if (fileName != NULL) { + if (loadFileText) + { + text = loadFileText(fileName); + return text; + } +#if defined(SUPPORT_STANDARD_FILEIO) FILE *file = fopen(fileName, "rt"); if (file != NULL) @@ -319,6 +331,9 @@ char *LoadFileText(const char *fileName) fclose(file); } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open text file", fileName); +#else + TRACELOG(LOG_WARNING, "FILEIO: Standard file io not supported, use custom file callback"); +#endif } else TRACELOG(LOG_WARNING, "FILEIO: File name provided is not valid"); @@ -338,6 +353,12 @@ bool SaveFileText(const char *fileName, char *text) if (fileName != NULL) { + if (saveFileText) + { + saveFileText(fileName, text); + return success; + } +#if defined(SUPPORT_STANDARD_FILEIO) FILE *file = fopen(fileName, "wt"); if (file != NULL) @@ -351,6 +372,9 @@ bool SaveFileText(const char *fileName, char *text) if (result == 0) success = true; } else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open text file", fileName); +#else + TRACELOG(LOG_WARNING, "FILEIO: Standard file io not supported, use custom file callback"); +#endif } else TRACELOG(LOG_WARNING, "FILEIO: File name provided is not valid"); From 0d096b43c236895054cc278364fecf7b415d20d7 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 4 Mar 2021 20:44:22 +0100 Subject: [PATCH 51/51] Update some comments to warn users about callbacks --- src/raylib.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 198fbac25..5696be2a2 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -873,15 +873,18 @@ typedef enum { NPATCH_THREE_PATCH_HORIZONTAL // Npatch defined by 3x1 tiles } NPatchType; -// Callbacks to be implemented by users -typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); -typedef void *(*MemAllocCallback)(int size); -typedef void *(*MemReallocCallback)(void *ptr, int size); -typedef void (*MemFreeCallback)(void *ptr); -typedef unsigned char* (*LoadFileDataCallback)(const char* fileName, unsigned int* bytesRead); -typedef void (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); -typedef char *(*LoadFileTextCallback)(const char* fileName); -typedef void (*SaveFileTextCallback)(const char *fileName, char *text); +// Callbacks to hook some internal functions +// WARNING: This callbacks are intended for advance users +typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); // Logging: Redirect trace log messages + +typedef void *(*MemAllocCallback)(int size); // Memory: Custom allocator +typedef void *(*MemReallocCallback)(void *ptr, int size); // Memory: Custom re-allocator +typedef void (*MemFreeCallback)(void *ptr); // Memory: Custom free + +typedef unsigned char* (*LoadFileDataCallback)(const char* fileName, unsigned int* bytesRead); // FileIO: Load binary data +typedef void (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); // FileIO: Save binary data +typedef char *(*LoadFileTextCallback)(const char* fileName); // FileIO: Load text data +typedef void (*SaveFileTextCallback)(const char *fileName, char *text); // FileIO: Save text data #if defined(__cplusplus) @@ -985,15 +988,16 @@ RLAPI void *MemAlloc(int size); // Internal me RLAPI void *MemRealloc(void *ptr, int size); // Internal memory reallocator RLAPI void MemFree(void *ptr); // Internal memory free -// Set custom system callbacks +// Set custom callbacks +// WARNING: Callbacks setup is intended for advance users RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log RLAPI void SetMemAllocCallback(MemAllocCallback callback); // Set custom memory allocator RLAPI void SetMemReallocCallback(MemReallocCallback callback); // Set custom memory reallocator RLAPI void SetMemFreeCallback(MemFreeCallback callback); // Set custom memory free -RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file data loader -RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file data saver -RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text loader -RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text saver +RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file binary data loader +RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file binary data saver +RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text data loader +RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver // Files management functions RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)