diff --git a/BINDINGS.md b/BINDINGS.md index b9b42233c..56c7e79c1 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -6,10 +6,10 @@ Some people ported raylib to other languages in the form of bindings or wrappers | Name | raylib Version | Language | License | | :--------------------------------------------------------------------------------------- | :--------------: | :------------------------------------------------------------------: | :------------------: | -| [raylib](https://github.com/raysan5/raylib) | **5.0** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib | +| [raylib](https://github.com/raysan5/raylib) | **5.5** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib | | [raylib-beef](https://github.com/Starpelly/raylib-beef) | **5.5** | [Beef](https://www.beeflang.org) | MIT | -| [raylib-boo](https://github.com/Rabios/raylib-boo) | 3.7 | [Boo](http://boo-language.github.io) | MIT | -| [raybit](https://github.com/Alex-Velez/raybit) | **5.0** | [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) | MIT | +| [raybit](https://github.com/Alex-Velez/raybit) | **5.0** | [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) | MIT | +| [raylib-c3](https://github.com/c3lang/vendor/tree/main/libraries/raylib55.c3l) | **5.5** | [C3](https://c3-lang.org) | MIT | | [Raylib-cs](https://github.com/ChrisDill/Raylib-cs) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib | | [Raylib-CsLo](https://github.com/NotNotTech/Raylib-CsLo) | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | | [Raylib-CSharp-Vinculum](https://github.com/ZeroElectric/Raylib-CSharp-Vinculum) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | @@ -18,36 +18,38 @@ Some people ported raylib to other languages in the form of bindings or wrappers | [claylib/wrap](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib | | [claw-raylib](https://github.com/bohonghuang/claw-raylib) | **auto** | [Common Lisp](https://common-lisp.net) | Apache-2.0 | | [chez-raylib](https://github.com/Yunoinsky/chez-raylib) | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme) | GPLv3 | +| [CLIPSraylib](https://github.com/mrryanjohnston/CLIPSraylib) | **auto** | [CLIPS](https://www.clipsrules.net/) | MIT | | [raylib-cr](https://github.com/sol-vin/raylib-cr) | 4.6-dev (5e1a81) | [Crystal](https://crystal-lang.org) | Apache-2.0 | | [ray-cyber](https://github.com/fubark/ray-cyber) | **5.0** | [Cyber](https://cyberscript.dev) | MIT | | [dart-raylib](https://gitlab.com/wolfenrain/dart-raylib) | 4.0 | [Dart](https://dart.dev) | MIT | | [bindbc-raylib3](https://github.com/o3o/bindbc-raylib3) | **5.0** | [D](https://dlang.org) | BSL-1.0 | -| [dray](https://github.com/redthing1/dray) | **5.0** | [D](https://dlang.org) | Apache-2.0 | +| [dray](https://github.com/redthing1/dray) | **5.0** | [D](https://dlang.org) | Apache-2.0 | | [raylib-d](https://github.com/schveiguy/raylib-d) | **5.5** | [D](https://dlang.org) | Zlib | | [rayex](https://github.com/shiryel/rayex) | 3.7 | [elixir](https://elixir-lang.org) | Apache-2.0 | | [raylib-factor](https://github.com/factor/factor/blob/master/extra/raylib/raylib.factor) | 4.5 | [Factor](https://factorcode.org) | BSD | | [raylib-freebasic](https://github.com/WIITD/raylib-freebasic) | **5.0** | [FreeBASIC](https://www.freebasic.net) | MIT | | [fortran-raylib](https://github.com/interkosmos/fortran-raylib) | **5.5** | [Fortran](https://fortran-lang.org) | ISC | -| [raylib-go](https://github.com/gen2brain/raylib-go) | **5.0** | [Go](https://golang.org) | Zlib | +| [raylib-go](https://github.com/gen2brain/raylib-go) | **5.5** | [Go](https://golang.org) | Zlib | | [raylib-guile](https://github.com/petelliott/raylib-guile) | **auto** | [Guile](https://www.gnu.org/software/guile) | Zlib | | [gforth-raylib](https://github.com/ArnautDaniel/gforth-raylib) | 3.5 | [Gforth](https://gforth.org) | **???** | | [h-raylib](https://github.com/Anut-py/h-raylib) | **5.5-dev** | [Haskell](https://haskell.org) | Apache-2.0 | | [raylib-hx](https://github.com/foreignsasquatch/raylib-hx) | 4.2 | [Haxe](https://haxe.org) | Zlib | | [hb-raylib](https://github.com/MarcosLeonardoMendezGerencir/hb-raylib) | 3.5 | [Harbour](https://harbour.github.io) | MIT | | [jaylib](https://github.com/janet-lang/jaylib) | **5.0** | [Janet](https://janet-lang.org) | MIT | -| [jaylib](https://github.com/electronstudio/jaylib/) | **5.5** | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | GPLv3+CE | +| [jaylib](https://github.com/electronstudio/jaylib/) | **5.5** | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | GPLv3+CE | | [raylib-j](https://github.com/CreedVI/Raylib-J) | 4.0 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | Zlib | -| [Raylib.jl](https://github.com/chengchingwen/Raylib.jl) | 4.2 | [Julia](https://julialang.org) | Zlib | +| [Raylib.jl](https://github.com/chengchingwen/Raylib.jl) | 4.2 | [Julia](https://julialang.org) | Zlib | | [kaylib](https://github.com/electronstudio/kaylib) | 3.7 | [Kotlin/native](https://kotlinlang.org) | **???** | | [KaylibKit](https://codeberg.org/Kenta/KaylibKit) | 4.5 | [Kotlin/native](https://kotlinlang.org) | Zlib | -| [raylib-lua](https://github.com/TSnake41/raylib-lua) | 4.5 | [Lua](http://www.lua.org) | ISC | -| [raylua](https://github.com/Rabios/raylua) | 4.0 | [Lua](http://www.lua.org) | MIT | -| [raylib-matte](https://github.com/jcorks/raylib-matte) | 4.6-dev | [Matte](https://github.com/jcorks/matte) | MIT | +| [raylib-lua](https://github.com/TSnake41/raylib-lua) | 5.0 | [Lua](http://www.lua.org) | ISC | +| [raylib-lua-bindings (WIP)](https://github.com/legendaryredfox/raylib-lua-bindings) | 5.5 | [Lua](http://www.lua.org) | ISC | +| [ReiLua](https://github.com/nullstare/ReiLua) | 5.5 | [Lua](http://www.lua.org) | MIT | +| [raylib-matte](https://github.com/jcorks/raylib-matte) | 4.6-dev | [Matte](https://github.com/jcorks/matte) | **???** | | [Raylib.nelua](https://github.com/AuzFox/Raylib.nelua) | **5.0** | [nelua](https://nelua.io) | Zlib | -| [raylib-bindings](https://github.com/vaiorabbit/raylib-bindings) | 4.5 | [Ruby](https://www.ruby-lang.org/en) | Zlib | +| [raylib-bindings](https://github.com/vaiorabbit/raylib-bindings) | 5.6-dev | [Ruby](https://www.ruby-lang.org/en) | Zlib | | [naylib](https://github.com/planetis-m/naylib) | **5.1-dev** | [Nim](https://nim-lang.org) | MIT | | [node-raylib](https://github.com/RobLoach/node-raylib) | 4.5 | [Node.js](https://nodejs.org/en) | Zlib | -| [raylib-odin](https://github.com/odin-lang/Odin/tree/master/vendor/raylib) | **5.0** | [Odin](https://odin-lang.org) | BSD-3Clause | +| [raylib-odin](https://github.com/odin-lang/Odin/tree/master/vendor/raylib) | **5.5** | [Odin](https://odin-lang.org) | BSD-3Clause | | [raylib_odin_bindings](https://github.com/Deathbat2190/raylib_odin_bindings) | 4.0-dev | [Odin](https://odin-lang.org) | MIT | | [raylib-ocaml](https://github.com/tjammer/raylib-ocaml) | **5.0** | [OCaml](https://ocaml.org) | MIT | | [TurboRaylib](https://github.com/turborium/TurboRaylib) | 4.5 | [Object Pascal](https://en.wikipedia.org/wiki/Object_Pascal) | MIT | @@ -55,25 +57,25 @@ Some people ported raylib to other languages in the form of bindings or wrappers | [Raylib.4.0.Pascal](https://github.com/sysrpl/Raylib.4.0.Pascal) | 4.0 | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib | | [pyraylib](https://github.com/Ho011/pyraylib) | 3.7 | [Python](https://www.python.org) | Zlib | | [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi) | **5.5** | [Python](https://www.python.org) | EPL-2.0 | -| [raylibpyctbg](https://github.com/overdev/raylibpyctbg) | 4.5 | [Python](https://www.python.org) | MIT | +| [raylibpyctbg](https://github.com/overdev/raylibpyctbg) | 5.5 | [Python](https://www.python.org) | MIT | | [raylib-py](https://github.com/overdev/raylib-py) | 5.5 | [Python](https://www.python.org) | MIT | | [raylib-python-ctypes](https://github.com/sDos280/raylib-python-ctypes) | 4.6-dev | [Python](https://www.python.org) | MIT | -| [raylib-pkpy-bindings](https://github.com/blueloveTH/pkpy-bindings) | 4.6-dev | [pocketpy](https://pocketpy.dev) | MIT | +| [raylib-pkpy-bindings](https://github.com/blueloveTH/pkpy-bindings) | 5.1-dev | [pocketpy](https://pocketpy.dev) | MIT | | [raylib-php](https://github.com/joseph-montanez/raylib-php) | 4.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib | | [raylib-phpcpp](https://github.com/oraoto/raylib-phpcpp) | 3.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib | | [raylibr](https://github.com/jeroenjanssens/raylibr) | 4.0 | [R](https://www.r-project.org) | MIT | -| [raylib-ffi](https://github.com/ewpratten/raylib-ffi) | 4.5 | [Rust](https://www.rust-lang.org) | GPLv3 | -| [raylib-rs](https://github.com/raylib-rs/raylib-rs) | **5.0** | [Rust](https://www.rust-lang.org) | Zlib | +| [raylib-ffi](https://github.com/ewpratten/raylib-ffi) | 5.5 | [Rust](https://www.rust-lang.org) | GPLv3 | +| [raylib-rs](https://github.com/raylib-rs/raylib-rs) | **5.5** | [Rust](https://www.rust-lang.org) | Zlib | | [Relib](https://github.com/RedCubeDev-ByteSpace/Relib) | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | **???** | | [racket-raylib](https://github.com/eutro/racket-raylib) | 4.0 | [Racket](https://racket-lang.org) | MIT/Apache-2.0 | | [raylib-swift](https://github.com/STREGAsGate/Raylib) | 4.0 | [Swift](https://swift.org) | MIT | | [raylib-scopes](https://github.com/salotz/raylib-scopes) | auto | [Scopes](http://scopes.rocks) | MIT | -| [raylib-SmallBASIC](https://github.com/smallbasic/smallbasic.plugins/tree/master/raylib) | **5.0** | [SmallBASIC](https://github.com/smallbasic/SmallBASIC) | GPLv3 | +| [raylib-SmallBASIC](https://github.com/smallbasic/smallbasic.plugins/tree/master/raylib) | **5.5** | [SmallBASIC](https://github.com/smallbasic/SmallBASIC) | GPLv3 | | [raylib-umka](https://github.com/robloach/raylib-umka) | 4.5 | [Umka](https://github.com/vtereshkov/umka-lang) | Zlib | | [raylib.v](https://github.com/irishgreencitrus/raylib.v) | 4.2 | [V](https://vlang.io) | Zlib | | [raylib-vapi](https://github.com/lxmcf/raylib-vapi) | **5.0** | [Vala](https://vala.dev) | Zlib | -| [raylib-wren](https://github.com/TSnake41/raylib-wren) | 4.0 | [Wren](http://wren.io) | ISC | -| [raylib-zig](https://github.com/Not-Nik/raylib-zig) | **5.0** | [Zig](https://ziglang.org) | MIT | +| [raylib-wren](https://github.com/TSnake41/raylib-wren) | 4.5 | [Wren](http://wren.io) | ISC | +| [raylib-zig](https://github.com/Not-Nik/raylib-zig) | **5.5** | [Zig](https://ziglang.org) | MIT | | [raylib.zig](https://github.com/ryupold/raylib.zig) | **5.1-dev** | [Zig](https://ziglang.org) | MIT | | [raylib-zig-bindings](https://github.com/L-Briand/raylib-zig-bindings) | **5.0** | [Zig](https://ziglang.org) | Zlib | | [hare-raylib](https://git.sr.ht/~evantj/hare-raylib) | **auto** | [Hare](https://harelang.org) | Zlib | @@ -84,6 +86,8 @@ Some people ported raylib to other languages in the form of bindings or wrappers | [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | **5.5-dev** | [Lean4](https://lean-lang.org) | BSD-3-Clause | | [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain | | [raylib-apl](https://github.com/Brian-ED/raylib-apl) | **5.0** | [Dyalog APL](https://www.dyalog.com/) | MIT | +| [raylib-jai](https://github.com/ahmedqarmout2/raylib-jai) | **5.5** | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) | MIT | +| [fnl-raylib](https://github.com/0riginaln0/fnl-raylib) | **5.5** | [Fennel](https://fennel-lang.org/) | MIT | ### Utility Wrapers @@ -93,7 +97,7 @@ These are utility wrappers for specific languages, they are not required to use | [raylib-cpp](https://github.com/robloach/raylib-cpp) | **5.5** | [C++](https://en.wikipedia.org/wiki/C%2B%2B) | Zlib | | [claylib](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib | | [rayed-bqn](https://github.com/Brian-ED/rayed-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT | -| [DOOR](https://github.com/RealDoigt/DOOR) | 4.0 | [D](https://dlang.org) | MIT | +| [DOOR](https://github.com/RealDoigt/DOOR) | 4.0 | [D](https://dlang.org) | MIT | ### Older or Unmaintained Language Bindings @@ -153,7 +157,7 @@ These are older raylib bindings that are more than 2 versions old or have not be | [ray.mod](https://github.com/bmx-ng/ray.mod) | 3.0 | [BlitzMax](https://blitzmax.org) | | [raylib-mosaic](https://github.com/pluckyporcupine/raylib-mosaic) | 3.0 | [Mosaic](https://github.com/sal55/langs/tree/master/Mosaic) | | [raylib-xdpw](https://github.com/vtereshkov/raylib-xdpw) | 2.6 | [XD Pascal](https://github.com/vtereshkov/xdpw) | -| [raylib-carp](https://github.com/sacredbirdman/raylib-carp) | 3.0 | [Carp](https://github.com/carp-lang/Carp) | +| [raylib-carp](https://github.com/sacredbirdman/raylib-carp) | 3.0 | [Carp](https://github.com/carp-lang/Carp) | | [raylib-fb](https://github.com/IchMagBier/raylib-fb) | 3.0 | [FreeBasic](https://www.freebasic.net) | | [raylib-purebasic](https://github.com/D-a-n-i-l-o/raylib-purebasic) | 3.0 | [PureBasic](https://www.purebasic.com) | | [raylib-ats2](https://github.com/mephistopheles-8/raylib-ats2) | 3.0 | [ATS2](http://www.ats-lang.org) | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d70617c13..7d4c8acf1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,7 +54,7 @@ To open new issues for raylib (bug, enhancement, discussion...), just try to fol - If applicable, attach some screenshot of the issue and a .zip file with the code sample and required resources. - On issue description, add a brackets tag about the raylib module that relates to this issue. If don't know which module, just report the issue, I will review it. - - You can check other issues to see how is being done! + - You can check other issues to see how it's being done! ### Sending a Pull-Request diff --git a/FAQ.md b/FAQ.md index d2f9308ac..778e3455d 100644 --- a/FAQ.md +++ b/FAQ.md @@ -90,7 +90,7 @@ I personally consider raylib a graphics library with some high-level features ra ### What does raylib provide that other engines or libraries don't? -I would say "simplicity" and "enjoyment" at a really low level of coding but actually is up to the user to discover it, to try it and to see if it fits their needs. raylib is not good for everyone but it's worth a try. +I would say "simplicity" and "enjoyment" at a really low level of coding but actually it is up to the user to discover it, to try it and to see if it fits their needs. raylib is not good for everyone but it's worth a try. ### How does raylib compare to Unity/Unreal/Godot? diff --git a/examples/Makefile b/examples/Makefile index a65a4961e..34cf36f04 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -54,10 +54,15 @@ # Define target platform: PLATFORM_DESKTOP, PLATFORM_DESKTOP_SDL, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB PLATFORM ?= PLATFORM_DESKTOP -ifeq ($(PLATFORM), PLATFORM_DESKTOP) - TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW +ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP_GLFW PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW)) + TARGET_PLATFORM := $(PLATFORM) + override PLATFORM = PLATFORM_DESKTOP else - TARGET_PLATFORM = $(PLATFORM) + ifeq ($(PLATFORM), PLATFORM_DESKTOP) + TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW + else + TARGET_PLATFORM = $(PLATFORM) + endif endif # Define required raylib variables @@ -653,7 +658,7 @@ OTHERS = \ ifeq ($(TARGET_PLATFORM), PLATFORM_DESKTOP_GFLW) OTHERS += others/rlgl_standalone endif - + CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST)) diff --git a/examples/core/core_input_virtual_controls.c b/examples/core/core_input_virtual_controls.c index bbbad208f..76eeafee4 100644 --- a/examples/core/core_input_virtual_controls.c +++ b/examples/core/core_input_virtual_controls.c @@ -6,7 +6,8 @@ * * Example create by GreenSnakeLinux (@GreenSnakeLinux), * lighter by oblerion (@oblerion) and -* reviewed by Ramon Santamaria (@raysan5) +* reviewed by Ramon Santamaria (@raysan5) and +* improved by danilwhale (@danilwhale) * * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software @@ -17,6 +18,16 @@ #include "raylib.h" #include + +typedef enum { + BUTTON_NONE = -1, + BUTTON_UP, + BUTTON_LEFT, + BUTTON_RIGHT, + BUTTON_DOWN, + BUTTON_MAX +} PadButton; + //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -29,24 +40,38 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [core] example - input virtual controls"); - const float dpadX = 90; - const float dpadY = 300; - const float dpadRad = 25.0f;//radius of each pad - Color dpadColor = BLUE; - int dpadKeydown = -1;//-1 if not down, else 0,1,2,3 + Vector2 padPosition = { 100, 350 }; + float buttonRadius = 30; - - const float dpadCollider[4][2]= // collider array with x,y position + Vector2 buttonPositions[BUTTON_MAX] = { - {dpadX,dpadY-dpadRad*1.5f},//up - {dpadX-dpadRad*1.5f,dpadY},//left - {dpadX+dpadRad*1.5f,dpadY},//right - {dpadX,dpadY+dpadRad*1.5f}//down + { padPosition.x,padPosition.y - buttonRadius*1.5f }, // Up + { padPosition.x - buttonRadius*1.5f, padPosition.y }, // Left + { padPosition.x + buttonRadius*1.5f, padPosition.y }, // Right + { padPosition.x, padPosition.y + buttonRadius*1.5f } // Down }; - const char dpadLabel[4]="XYBA";//label of Dpad - float playerX=100; - float playerY=100; + const char *buttonLabels[BUTTON_MAX] = + { + "Y", // Up + "X", // Left + "B", // Right + "A" // Down + }; + + Color buttonLabelColors[BUTTON_MAX] = + { + YELLOW, // Up + BLUE, // Left + RED, // Right + GREEN // Down + }; + + int pressedButton = BUTTON_NONE; + Vector2 inputPosition = { 0, 0 }; + + Vector2 playerPosition = { (float)screenWidth/2, (float)screenHeight/2 }; + float playerSpeed = 75; SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -54,63 +79,89 @@ int main(void) // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - // Update - //-------------------------------------------------------------------------- - dpadKeydown = -1; //reset - int inputX = 0; - int inputY = 0; - if(GetTouchPointCount()>0) - {//use touch pos - inputX = GetTouchX(); - inputY = GetTouchY(); + // Update + //-------------------------------------------------------------------------- + if ((GetTouchPointCount() > 0)) + { + // Use touch position + inputPosition = GetTouchPosition(0); } else - {//use mouse pos - inputX = GetMouseX(); - inputY = GetMouseY(); - } - for(int i=0;i<4;i++) { - //test distance each collider and input < radius - if( fabsf(dpadCollider[i][1]-inputY) + fabsf(dpadCollider[i][0]-inputX) < dpadRad) - { - dpadKeydown = i; - break; - } + // Use mouse position + inputPosition = GetMousePosition(); } - // move player - switch(dpadKeydown){ - case 0: playerY -= 50*GetFrameTime(); - break; - case 1: playerX -= 50*GetFrameTime(); - break; - case 2: playerX += 50*GetFrameTime(); - break; - case 3: playerY += 50*GetFrameTime(); - default:; - }; - //-------------------------------------------------------------------------- - // Draw - //-------------------------------------------------------------------------- - BeginDrawing(); - ClearBackground(RAYWHITE); - for(int i=0;i<4;i++) + + // Reset pressed button to none + pressedButton = BUTTON_NONE; + + // Make sure user is pressing left mouse button if they're from desktop + if ((GetTouchPointCount() > 0) || ((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT))) + { + // Find nearest D-Pad button to the input position + for (int i = 0; i < BUTTON_MAX; i++) { - //draw all pad - DrawCircleV((Vector2) { dpadCollider[i][0], dpadCollider[i][1] }, dpadRad, dpadColor); - if(i!=dpadKeydown) + float distX = fabsf(buttonPositions[i].x - inputPosition.x); + float distY = fabsf(buttonPositions[i].y - inputPosition.y); + + if ((distX + distY < buttonRadius)) { - //draw label - DrawText(TextSubtext(dpadLabel,i,1), - (int)dpadCollider[i][0]-7, - (int)dpadCollider[i][1]-8,20,BLACK); + pressedButton = i; + break; } } + } + + // Move player according to pressed button + switch (pressedButton) + { + case BUTTON_UP: + { + playerPosition.y -= playerSpeed*GetFrameTime(); + break; + } + case BUTTON_LEFT: + { + playerPosition.x -= playerSpeed*GetFrameTime(); + break; + } + case BUTTON_RIGHT: + { + playerPosition.x += playerSpeed*GetFrameTime(); + break; + } + case BUTTON_DOWN: + { + playerPosition.y += playerSpeed*GetFrameTime(); + break; + } + default: break; + }; + + //-------------------------------------------------------------------------- + // Draw + //-------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw world + DrawCircleV(playerPosition, 50, MAROON); + + // Draw GUI + for (int i = 0; i < BUTTON_MAX; i++) + { + DrawCircleV(buttonPositions[i], buttonRadius, (i == pressedButton)? DARKGRAY : BLACK); + + DrawText(buttonLabels[i], + (int)buttonPositions[i].x - 7, (int)buttonPositions[i].y - 8, + 20, buttonLabelColors[i]); + } + + DrawText("move the player with D-Pad buttons", 10, 10, 20, DARKGRAY); - DrawRectangleRec((Rectangle) { playerX - 4, playerY - 4, 75, 28 }, RED); - DrawText("Player", (int)playerX, (int)playerY, 20, WHITE); EndDrawing(); - //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- } // De-Initialization diff --git a/examples/core/core_input_virtual_controls.png b/examples/core/core_input_virtual_controls.png index cb1444598..83097a54c 100644 Binary files a/examples/core/core_input_virtual_controls.png and b/examples/core/core_input_virtual_controls.png differ diff --git a/examples/shaders/resources/shaders/glsl100/pbr.fs b/examples/shaders/resources/shaders/glsl100/pbr.fs index 27d496968..70e3b4885 100644 --- a/examples/shaders/resources/shaders/glsl100/pbr.fs +++ b/examples/shaders/resources/shaders/glsl100/pbr.fs @@ -1,6 +1,6 @@ #version 100 -precision highp float; +precision highp float; #define MAX_LIGHTS 4 #define LIGHT_DIRECTIONAL 0 @@ -24,7 +24,6 @@ varying vec3 fragNormal; varying vec4 shadowPos; varying mat3 TBN; - // Input uniform values uniform int numOfLights; uniform sampler2D albedoMap; @@ -153,4 +152,4 @@ void main() gl_FragColor = vec4(color,1.0); -} \ No newline at end of file +} diff --git a/examples/shaders/resources/shaders/glsl100/pbr.vs b/examples/shaders/resources/shaders/glsl100/pbr.vs index 3fa651f79..87e142e07 100644 --- a/examples/shaders/resources/shaders/glsl100/pbr.vs +++ b/examples/shaders/resources/shaders/glsl100/pbr.vs @@ -1,11 +1,11 @@ #version 100 // Input vertex attributes -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; -attribute vec3 vertexTangent; -attribute vec4 vertexColor; +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; +attribute vec3 vertexTangent; +attribute vec4 vertexColor; // Input uniform values uniform mat4 mvp; @@ -72,4 +72,4 @@ void main() // Calculate final vertex position gl_Position = mvp * vec4(vertexPosition, 1.0); -} \ No newline at end of file +} diff --git a/examples/shaders/resources/shaders/glsl330/lighting_instancing.vs b/examples/shaders/resources/shaders/glsl330/lighting_instancing.vs index 3e4da1e28..32db8cdd4 100644 --- a/examples/shaders/resources/shaders/glsl330/lighting_instancing.vs +++ b/examples/shaders/resources/shaders/glsl330/lighting_instancing.vs @@ -25,7 +25,7 @@ void main() // Send vertex attributes to fragment shader fragPosition = vec3(instanceTransform*vec4(vertexPosition, 1.0)); fragTexCoord = vertexTexCoord; - //fragColor = vertexColor; + fragColor = vec4(1.0); fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); // Calculate final vertex position, note that we multiply mvp by instanceTransform diff --git a/examples/shaders/shaders_mesh_instancing.c b/examples/shaders/shaders_mesh_instancing.c index eb42cb471..1e0bf0696 100644 --- a/examples/shaders/shaders_mesh_instancing.c +++ b/examples/shaders/shaders_mesh_instancing.c @@ -61,7 +61,7 @@ int main(void) { Matrix translation = MatrixTranslate((float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50)); Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) }); - float angle = (float)GetRandomValue(0, 10)*DEG2RAD; + float angle = (float)GetRandomValue(0, 180)*DEG2RAD; Matrix rotation = MatrixRotate(axis, angle); transforms[i] = MatrixMultiply(rotation, translation); @@ -73,7 +73,6 @@ int main(void) // Get shader locations shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp"); shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos"); - shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform"); // Set shader value: ambient light level int ambientLoc = GetShaderLocation(shader, "ambient"); diff --git a/parser/output/raylib_api.json b/parser/output/raylib_api.json index 62ecd1fa9..e05d8a748 100644 --- a/parser/output/raylib_api.json +++ b/parser/output/raylib_api.json @@ -2543,6 +2543,11 @@ "name": "SHADER_LOC_BONE_MATRICES", "value": 28, "description": "Shader location: array of matrices uniform: boneMatrices" + }, + { + "name": "SHADER_LOC_VERTEX_INSTANCE_TX", + "value": 29, + "description": "Shader location: vertex attribute: instanceTransform" } ] }, @@ -2591,8 +2596,28 @@ "description": "Shader uniform type: ivec4 (4 int)" }, { - "name": "SHADER_UNIFORM_SAMPLER2D", + "name": "SHADER_UNIFORM_UINT", "value": 8, + "description": "Shader uniform type: unsigned int" + }, + { + "name": "SHADER_UNIFORM_UIVEC2", + "value": 9, + "description": "Shader uniform type: uivec2 (2 unsigned int)" + }, + { + "name": "SHADER_UNIFORM_UIVEC3", + "value": 10, + "description": "Shader uniform type: uivec3 (3 unsigned int)" + }, + { + "name": "SHADER_UNIFORM_UIVEC4", + "value": 11, + "description": "Shader uniform type: uivec4 (4 unsigned int)" + }, + { + "name": "SHADER_UNIFORM_SAMPLER2D", + "value": 12, "description": "Shader uniform type: sampler2d" } ] @@ -4882,9 +4907,9 @@ "returnType": "int" }, { - "name": "SetExitKey", - "description": "Set a custom key to exit program (default is ESC)", - "returnType": "void", + "name": "GetKeyName", + "description": "Get name of a QWERTY key on the current keyboard layout (eg returns string 'q' for KEY_A on an AZERTY keyboard)", + "returnType": "const char *", "params": [ { "type": "int", @@ -4893,9 +4918,9 @@ ] }, { - "name": "GetKeyName", - "description": "Get name of a QWERTY key on the current keyboard layout (eg returns string "q" for KEY_A on an AZERTY keyboard)", - "returnType": "const char *", + "name": "SetExitKey", + "description": "Set a custom key to exit program (default is ESC)", + "returnType": "void", "params": [ { "type": "int", diff --git a/parser/output/raylib_api.lua b/parser/output/raylib_api.lua index d62a94a7f..d8a848b45 100644 --- a/parser/output/raylib_api.lua +++ b/parser/output/raylib_api.lua @@ -2543,6 +2543,11 @@ return { name = "SHADER_LOC_BONE_MATRICES", value = 28, description = "Shader location: array of matrices uniform: boneMatrices" + }, + { + name = "SHADER_LOC_VERTEX_INSTANCE_TX", + value = 29, + description = "Shader location: vertex attribute: instanceTransform" } } }, @@ -2591,8 +2596,28 @@ return { description = "Shader uniform type: ivec4 (4 int)" }, { - name = "SHADER_UNIFORM_SAMPLER2D", + name = "SHADER_UNIFORM_UINT", value = 8, + description = "Shader uniform type: unsigned int" + }, + { + name = "SHADER_UNIFORM_UIVEC2", + value = 9, + description = "Shader uniform type: uivec2 (2 unsigned int)" + }, + { + name = "SHADER_UNIFORM_UIVEC3", + value = 10, + description = "Shader uniform type: uivec3 (3 unsigned int)" + }, + { + name = "SHADER_UNIFORM_UIVEC4", + value = 11, + description = "Shader uniform type: uivec4 (4 unsigned int)" + }, + { + name = "SHADER_UNIFORM_SAMPLER2D", + value = 12, description = "Shader uniform type: sampler2d" } } @@ -4327,17 +4352,17 @@ return { returnType = "int" }, { - name = "SetExitKey", - description = "Set a custom key to exit program (default is ESC)", - returnType = "void", + name = "GetKeyName", + description = "Get name of a QWERTY key on the current keyboard layout (eg returns string 'q' for KEY_A on an AZERTY keyboard)", + returnType = "const char *", params = { {type = "int", name = "key"} } }, { - name = "GetKeyName", - description = "Get name of a QWERTY key on the current keyboard layout (eg returns string "q" for KEY_A on an AZERTY keyboard)", - returnType = "const char *", + name = "SetExitKey", + description = "Set a custom key to exit program (default is ESC)", + returnType = "void", params = { {type = "int", name = "key"} } diff --git a/parser/output/raylib_api.txt b/parser/output/raylib_api.txt index 721304906..7c7b003c4 100644 --- a/parser/output/raylib_api.txt +++ b/parser/output/raylib_api.txt @@ -795,7 +795,7 @@ Enum 08: MaterialMapIndex (11 values) Value[MATERIAL_MAP_IRRADIANCE]: 8 Value[MATERIAL_MAP_PREFILTER]: 9 Value[MATERIAL_MAP_BRDF]: 10 -Enum 09: ShaderLocationIndex (29 values) +Enum 09: ShaderLocationIndex (30 values) Name: ShaderLocationIndex Description: Shader location index Value[SHADER_LOC_VERTEX_POSITION]: 0 @@ -827,7 +827,8 @@ Enum 09: ShaderLocationIndex (29 values) Value[SHADER_LOC_VERTEX_BONEIDS]: 26 Value[SHADER_LOC_VERTEX_BONEWEIGHTS]: 27 Value[SHADER_LOC_BONE_MATRICES]: 28 -Enum 10: ShaderUniformDataType (9 values) + Value[SHADER_LOC_VERTEX_INSTANCE_TX]: 29 +Enum 10: ShaderUniformDataType (13 values) Name: ShaderUniformDataType Description: Shader uniform data type Value[SHADER_UNIFORM_FLOAT]: 0 @@ -838,7 +839,11 @@ Enum 10: ShaderUniformDataType (9 values) Value[SHADER_UNIFORM_IVEC2]: 5 Value[SHADER_UNIFORM_IVEC3]: 6 Value[SHADER_UNIFORM_IVEC4]: 7 - Value[SHADER_UNIFORM_SAMPLER2D]: 8 + Value[SHADER_UNIFORM_UINT]: 8 + Value[SHADER_UNIFORM_UIVEC2]: 9 + Value[SHADER_UNIFORM_UIVEC3]: 10 + Value[SHADER_UNIFORM_UIVEC4]: 11 + Value[SHADER_UNIFORM_SAMPLER2D]: 12 Enum 11: ShaderAttributeDataType (4 values) Name: ShaderAttributeDataType Description: Shader attribute data types @@ -1886,16 +1891,16 @@ Function 167: GetCharPressed() (0 input parameters) Return type: int Description: Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty No input parameters -Function 168: SetExitKey() (1 input parameters) +Function 168: GetKeyName() (1 input parameters) + Name: GetKeyName + Return type: const char * + Description: Get name of a QWERTY key on the current keyboard layout (eg returns string 'q' for KEY_A on an AZERTY keyboard) + Param[1]: key (type: int) +Function 169: SetExitKey() (1 input parameters) Name: SetExitKey Return type: void Description: Set a custom key to exit program (default is ESC) Param[1]: key (type: int) -Function 169: GetKeyName() (1 input parameters) - Name: GetKeyName - Return type: const char * - Description: Get name of a QWERTY key on the current keyboard layout (eg returns string "q" for KEY_A on an AZERTY keyboard) - Param[1]: key (type: int) Function 170: IsGamepadAvailable() (1 input parameters) Name: IsGamepadAvailable Return type: bool diff --git a/parser/output/raylib_api.xml b/parser/output/raylib_api.xml index fde502831..e1b1f35e2 100644 --- a/parser/output/raylib_api.xml +++ b/parser/output/raylib_api.xml @@ -507,7 +507,7 @@ - + @@ -537,8 +537,9 @@ + - + @@ -547,7 +548,11 @@ - + + + + + @@ -1181,10 +1186,10 @@ - + - + diff --git a/src/config.h b/src/config.h index 4cc3b7206..2a827ceca 100644 --- a/src/config.h +++ b/src/config.h @@ -284,6 +284,8 @@ #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8 #endif #endif +#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9 + // Default shader vertex attribute names to set location points // NOTE: When a new shader is loaded, the following locations are tried to be set for convenience diff --git a/src/raudio.c b/src/raudio.c index 198ac4043..3b73f7141 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1550,7 +1550,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data, else if ((strcmp(fileType, ".ogg") == 0) || (strcmp(fileType, ".OGG") == 0)) { // Open ogg audio stream - stb_vorbis* ctxOgg = stb_vorbis_open_memory((const unsigned char *)data, dataSize, NULL, NULL); + stb_vorbis *ctxOgg = stb_vorbis_open_memory((const unsigned char *)data, dataSize, NULL, NULL); if (ctxOgg != NULL) { @@ -2461,23 +2461,18 @@ static ma_uint32 ReadAudioBufferFramesInMixingFormat(AudioBuffer *audioBuffer, f float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut); - /* At this point we can convert the data to our mixing format. */ - ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration); /* Safe cast. */ + // At this point we can convert the data to our mixing format + ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration); ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration; ma_data_converter_process_pcm_frames(&audioBuffer->converter, inputBuffer, &inputFramesProcessedThisIteration, runningFramesOut, &outputFramesProcessedThisIteration); - totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; /* Safe cast. */ + totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; // Safe cast - if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration) - { - break; /* Ran out of input data. */ - } + if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration) break; // Ran out of input data - /* This should never be hit, but will add it here for safety. Ensures we get out of the loop when no input nor output frames are processed. */ - if (inputFramesProcessedThisIteration == 0 && outputFramesProcessedThisIteration == 0) - { - break; - } + // This should never be hit, but added here for safety + // Ensures we get out of the loop when no input nor output frames are processed + if ((inputFramesProcessedThisIteration == 0) && (outputFramesProcessedThisIteration == 0)) break; } return totalOutputFramesProcessed; diff --git a/src/raylib.h b/src/raylib.h index 980e19b6c..7482d4392 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -801,7 +801,8 @@ typedef enum { SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: boneWeights - SHADER_LOC_BONE_MATRICES // Shader location: array of matrices uniform: boneMatrices + SHADER_LOC_BONE_MATRICES, // Shader location: array of matrices uniform: boneMatrices + SHADER_LOC_VERTEX_INSTANCE_TX // Shader location: vertex attribute: instanceTransform } ShaderLocationIndex; #define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO @@ -817,6 +818,10 @@ typedef enum { SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int) SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int) SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int) + SHADER_UNIFORM_UINT, // Shader uniform type: unsigned int + SHADER_UNIFORM_UIVEC2, // Shader uniform type: uivec2 (2 unsigned int) + SHADER_UNIFORM_UIVEC3, // Shader uniform type: uivec3 (3 unsigned int) + SHADER_UNIFORM_UIVEC4, // Shader uniform type: uivec4 (4 unsigned int) SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d } ShaderUniformDataType; @@ -1177,8 +1182,8 @@ RLAPI bool IsKeyReleased(int key); // Check if a key RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty +RLAPI const char *GetKeyName(int key); // Get name of a QWERTY key on the current keyboard layout (eg returns string 'q' for KEY_A on an AZERTY keyboard) RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -RLAPI const char *GetKeyName(int key); // Get name of a QWERTY key on the current keyboard layout (eg returns string "q" for KEY_A on an AZERTY keyboard) // Input-related functions: gamepads RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available diff --git a/src/raymath.h b/src/raymath.h index 5b5e4c74f..9d712027c 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -328,8 +328,9 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2) return result; } -// Calculate angle between two vectors -// NOTE: Angle is calculated from origin point (0, 0) +// Calculate the signed angle from v1 to v2, relative to the origin (0, 0) +// NOTE: Coordinate system convention: positive X right, positive Y down, +// positive angles appear clockwise, and negative angles appear counterclockwise RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { float result = 0.0f; @@ -2664,12 +2665,12 @@ inline const Vector2& operator *= (Vector2& lhs, const Matrix& rhs) inline Vector2 operator / (const Vector2& lhs, const float& rhs) { - return Vector2Scale(lhs, 1.0f / rhs); + return Vector2Scale(lhs, 1.0f/rhs); } inline const Vector2& operator /= (Vector2& lhs, const float& rhs) { - lhs = Vector2Scale(lhs, 1.0f / rhs); + lhs = Vector2Scale(lhs, 1.0f/rhs); return lhs; } @@ -2758,12 +2759,12 @@ inline const Vector3& operator *= (Vector3& lhs, const Matrix& rhs) inline Vector3 operator / (const Vector3& lhs, const float& rhs) { - return Vector3Scale(lhs, 1.0f / rhs); + return Vector3Scale(lhs, 1.0f/rhs); } inline const Vector3& operator /= (Vector3& lhs, const float& rhs) { - lhs = Vector3Scale(lhs, 1.0f / rhs); + lhs = Vector3Scale(lhs, 1.0f/rhs); return lhs; } @@ -2842,12 +2843,12 @@ inline const Vector4& operator *= (Vector4& lhs, const Vector4& rhs) inline Vector4 operator / (const Vector4& lhs, const float& rhs) { - return Vector4Scale(lhs, 1.0f / rhs); + return Vector4Scale(lhs, 1.0f/rhs); } inline const Vector4& operator /= (Vector4& lhs, const float& rhs) { - lhs = Vector4Scale(lhs, 1.0f / rhs); + lhs = Vector4Scale(lhs, 1.0f/rhs); return lhs; } diff --git a/src/rcamera.h b/src/rcamera.h index bd2b36e03..ab998ae03 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -154,7 +154,7 @@ RLAPI void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAr RLAPI void CameraRoll(Camera *camera, float angle); RLAPI Matrix GetCameraViewMatrix(Camera *camera); -RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect); +RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect); #if defined(__cplusplus) } diff --git a/src/rcore.c b/src/rcore.c index 57e537e5f..16868a5a6 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1346,6 +1346,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode) shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR); shader.locs[SHADER_LOC_VERTEX_BONEIDS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS); shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS); + shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX); // Get handles to GLSL uniform locations (vertex shader) shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP); @@ -2765,7 +2766,8 @@ unsigned int *ComputeMD5(unsigned char *data, int dataSize) // Compute SHA-1 hash code // NOTE: Returns a static int[5] array (20 bytes) -unsigned int *ComputeSHA1(unsigned char *data, int dataSize) { +unsigned int *ComputeSHA1(unsigned char *data, int dataSize) +{ #define ROTATE_LEFT(x, c) (((x) << (c)) | ((x) >> (32 - (c)))) static unsigned int hash[5] = { 0 }; // Hash to be returned @@ -2800,17 +2802,16 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize) { { // Break chunk into sixteen 32-bit words w[j], 0 <= j <= 15 unsigned int w[80] = {0}; - for (int i = 0; i < 16; i++) { - w[i] = (msg[offset + (i * 4) + 0] << 24) | - (msg[offset + (i * 4) + 1] << 16) | - (msg[offset + (i * 4) + 2] << 8) | - (msg[offset + (i * 4) + 3]); + for (int i = 0; i < 16; i++) + { + w[i] = (msg[offset + (i*4) + 0] << 24) | + (msg[offset + (i*4) + 1] << 16) | + (msg[offset + (i*4) + 2] << 8) | + (msg[offset + (i*4) + 3]); } // Message schedule: extend the sixteen 32-bit words into eighty 32-bit words: - for (int i = 16; i < 80; ++i) { - w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1); - } + for (int i = 16; i < 80; i++) w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1); // Initialize hash value for this chunk unsigned int a = hash[0]; @@ -2824,16 +2825,23 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize) { unsigned int f = 0; unsigned int k = 0; - if (i < 20) { + if (i < 20) + { f = (b & c) | ((~b) & d); k = 0x5A827999; - } else if (i < 40) { + } + else if (i < 40) + { f = b ^ c ^ d; k = 0x6ED9EBA1; - } else if (i < 60) { + } + else if (i < 60) + { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC; - } else { + } + else + { f = b ^ c ^ d; k = 0xCA62C1D6; } @@ -3315,7 +3323,8 @@ float GetGamepadAxisMovement(int gamepad, int axis) { float value = (axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER)? -1.0f : 0.0f; - if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) { + if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) + { float movement = value < 0.0f ? CORE.Input.Gamepad.axisState[gamepad][axis] : fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]); if (movement > value) value = CORE.Input.Gamepad.axisState[gamepad][axis]; diff --git a/src/rlgl.h b/src/rlgl.h index 92971df62..b09b04b18 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -355,6 +355,9 @@ #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8 #endif #endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX + #define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9 +#endif //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -998,6 +1001,9 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad #ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS #define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS #endif +#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX + #define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX +#endif #ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix @@ -3959,7 +3965,7 @@ void rlDrawVertexArrayElements(int offset, int count, const void *buffer) void rlDrawVertexArrayInstanced(int offset, int count, int instances) { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - glDrawArraysInstanced(GL_TRIANGLES, 0, count, instances); + glDrawArraysInstanced(GL_TRIANGLES, offset, count, instances); #endif } @@ -4216,6 +4222,7 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId) glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR); glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT); glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2); + glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX); #ifdef RL_SUPPORT_MESH_GPU_SKINNING glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS); diff --git a/src/rmodels.c b/src/rmodels.c index c745d792a..8ab8012da 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -96,9 +96,9 @@ #endif #if SUPPORT_MESH_GENERATION - #define PAR_MALLOC(T, N) ((T*)RL_MALLOC(N*sizeof(T))) - #define PAR_CALLOC(T, N) ((T*)RL_CALLOC(N*sizeof(T), 1)) - #define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N))) + #define PAR_MALLOC(T, N) ((T *)RL_MALLOC(N*sizeof(T))) + #define PAR_CALLOC(T, N) ((T *)RL_CALLOC(N*sizeof(T), 1)) + #define PAR_REALLOC(T, BUF, N) ((T *)RL_REALLOC(BUF, sizeof(T)*(N))) #define PAR_FREE RL_FREE #if defined(_MSC_VER) // Disable some MSVC warning @@ -1734,12 +1734,12 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i // no faster, since we're transferring all the transform matrices anyway instancesVboId = rlLoadVertexBuffer(instanceTransforms, instances*sizeof(float16), false); - // Instances transformation matrices are send to shader attribute location: SHADER_LOC_MATRIX_MODEL + // Instances transformation matrices are sent to shader attribute location: SHADER_LOC_VERTEX_INSTANCE_TX for (unsigned int i = 0; i < 4; i++) { - rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i); - rlSetVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4)); - rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i, 1); + rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i); + rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4)); + rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i, 1); } rlDisableVertexBuffer(); @@ -2308,7 +2308,7 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame) } } -// at least 2x speed up vs the old method +// at least 2x speed up vs the old method // Update model animated vertex data (positions and normals) for a given frame // NOTE: Updated data is uploaded to GPU void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) @@ -2340,14 +2340,16 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) { boneWeight = mesh.boneWeights[boneCounter]; boneId = mesh.boneIds[boneCounter]; + // Early stop when no transformation will be applied if (boneWeight == 0.0f) continue; animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] }; animVertex = Vector3Transform(animVertex,model.meshes[m].boneMatrices[boneId]); - mesh.animVertices[vCounter] += animVertex.x * boneWeight; - mesh.animVertices[vCounter+1] += animVertex.y * boneWeight; - mesh.animVertices[vCounter+2] += animVertex.z * boneWeight; + mesh.animVertices[vCounter] += animVertex.x*boneWeight; + mesh.animVertices[vCounter+1] += animVertex.y*boneWeight; + mesh.animVertices[vCounter+2] += animVertex.z*boneWeight; updated = true; + // Normals processing // NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals) if (mesh.normals != NULL) @@ -2360,6 +2362,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) } } } + if (updated) { rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position @@ -2725,11 +2728,11 @@ Mesh GenMeshCube(float width, float height, float length) #else // Use par_shapes library to generate cube mesh /* // Platonic solids: -par_shapes_mesh* par_shapes_create_tetrahedron(); // 4 sides polyhedron (pyramid) -par_shapes_mesh* par_shapes_create_cube(); // 6 sides polyhedron (cube) -par_shapes_mesh* par_shapes_create_octahedron(); // 8 sides polyhedron (diamond) -par_shapes_mesh* par_shapes_create_dodecahedron(); // 12 sides polyhedron -par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron +par_shapes_mesh *par_shapes_create_tetrahedron(); // 4 sides polyhedron (pyramid) +par_shapes_mesh *par_shapes_create_cube(); // 6 sides polyhedron (cube) +par_shapes_mesh *par_shapes_create_octahedron(); // 8 sides polyhedron (diamond) +par_shapes_mesh *par_shapes_create_dodecahedron(); // 12 sides polyhedron +par_shapes_mesh *par_shapes_create_icosahedron(); // 20 sides polyhedron */ // Platonic solid generation: cube (6 sides) // NOTE: No normals/texcoords generated by default @@ -3840,7 +3843,7 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector for (int i = 0; i < 4; i++) { points[i] = Vector3Subtract(points[i], origin3D); - if (rotation != 0.0) points[i] = Vector3RotateByAxisAngle(points[i], forward, rotation * DEG2RAD); + if (rotation != 0.0) points[i] = Vector3RotateByAxisAngle(points[i], forward, rotation*DEG2RAD); points[i] = Vector3Add(points[i], position); } @@ -4049,7 +4052,7 @@ RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix transform) for (int i = 0; i < triangleCount; i++) { Vector3 a, b, c; - Vector3* vertdata = (Vector3*)mesh.vertices; + Vector3 *vertdata = (Vector3 *)mesh.vertices; if (mesh.indices) { @@ -4190,30 +4193,27 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform static Model LoadOBJ(const char *fileName) { tinyobj_attrib_t objAttributes = { 0 }; - tinyobj_shape_t* objShapes = NULL; + tinyobj_shape_t *objShapes = NULL; unsigned int objShapeCount = 0; - tinyobj_material_t* objMaterials = NULL; + tinyobj_material_t *objMaterials = NULL; unsigned int objMaterialCount = 0; Model model = { 0 }; model.transform = MatrixIdentity(); - char* fileText = LoadFileText(fileName); + char *fileText = LoadFileText(fileName); if (fileText == NULL) { - TRACELOG(LOG_ERROR, "MODEL Unable to read obj file %s", fileName); + TRACELOG(LOG_ERROR, "MODEL: [%s] Unable to read obj file", fileName); return model; } char currentDir[1024] = { 0 }; strcpy(currentDir, GetWorkingDirectory()); // Save current working directory - const char* workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness - if (CHDIR(workingDir) != 0) - { - TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir); - } + const char *workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness + if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir); unsigned int dataSize = (unsigned int)strlen(fileText); @@ -4222,7 +4222,7 @@ static Model LoadOBJ(const char *fileName) if (ret != TINYOBJ_SUCCESS) { - TRACELOG(LOG_ERROR, "MODEL Unable to read obj data %s", fileName); + TRACELOG(LOG_ERROR, "MODEL: Unable to read obj data %s", fileName); return model; } @@ -4233,52 +4233,51 @@ static Model LoadOBJ(const char *fileName) int lastMaterial = -1; unsigned int meshIndex = 0; - // count meshes + // Count meshes unsigned int nextShapeEnd = objAttributes.num_face_num_verts; - // see how many verts till the next shape - + // See how many verts till the next shape if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset; - // walk all the faces + // Walk all the faces for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) { if (faceId >= nextShapeEnd) { - // try to find the last vert in the next shape + // Try to find the last vert in the next shape nextShape++; if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset; - else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces + else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces meshIndex++; } - else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) + else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial)) { - meshIndex++;// if this is a new material, we need to allocate a new mesh + meshIndex++; // If this is a new material, we need to allocate a new mesh } lastMaterial = objAttributes.material_ids[faceId]; faceVertIndex += objAttributes.face_num_verts[faceId]; } - // allocate the base meshes and materials + // Allocate the base meshes and materials model.meshCount = meshIndex + 1; - model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount); + model.meshes = (Mesh *)MemAlloc(sizeof(Mesh)*model.meshCount); if (objMaterialCount > 0) { model.materialCount = objMaterialCount; - model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount); + model.materials = (Material *)MemAlloc(sizeof(Material)*objMaterialCount); } - else // we must allocate at least one material + else // We must allocate at least one material { model.materialCount = 1; - model.materials = (Material*)MemAlloc(sizeof(Material) * 1); + model.materials = (Material *)MemAlloc(sizeof(Material)*1); } - model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount); + model.meshMaterial = (int *)MemAlloc(sizeof(int)*model.meshCount); - // see how many verts are in each mesh - unsigned int* localMeshVertexCounts = (unsigned int*)MemAlloc(sizeof(unsigned int) * model.meshCount); + // See how many verts are in each mesh + unsigned int *localMeshVertexCounts = (unsigned int *)MemAlloc(sizeof(unsigned int)*model.meshCount); faceVertIndex = 0; nextShapeEnd = objAttributes.num_face_num_verts; @@ -4287,23 +4286,22 @@ static Model LoadOBJ(const char *fileName) unsigned int localMeshVertexCount = 0; nextShape = 1; - if (objShapeCount > 1) - nextShapeEnd = objShapes[nextShape].face_offset; + if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset; - // walk all the faces + // Walk all the faces for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) { - bool newMesh = false; // do we need a new mesh? + bool newMesh = false; // Do we need a new mesh? if (faceId >= nextShapeEnd) { - // try to find the last vert in the next shape + // Try to find the last vert in the next shape nextShape++; if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset; else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces newMesh = true; } - else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) + else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial)) { newMesh = true; } @@ -4321,50 +4319,52 @@ static Model LoadOBJ(const char *fileName) faceVertIndex += objAttributes.face_num_verts[faceId]; localMeshVertexCount += objAttributes.face_num_verts[faceId]; } + localMeshVertexCounts[meshIndex] = localMeshVertexCount; for (int i = 0; i < model.meshCount; i++) { - // allocate the buffers for each mesh + // Allocate the buffers for each mesh unsigned int vertexCount = localMeshVertexCounts[i]; model.meshes[i].vertexCount = vertexCount; - model.meshes[i].triangleCount = vertexCount / 3; + model.meshes[i].triangleCount = vertexCount/3; - model.meshes[i].vertices = (float*)MemAlloc(sizeof(float) * vertexCount * 3); - model.meshes[i].normals = (float*)MemAlloc(sizeof(float) * vertexCount * 3); - model.meshes[i].texcoords = (float*)MemAlloc(sizeof(float) * vertexCount * 2); - model.meshes[i].colors = (unsigned char*)MemAlloc(sizeof(unsigned char) * vertexCount * 4); + model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3); + model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3); + model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2); + model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4); } MemFree(localMeshVertexCounts); localMeshVertexCounts = NULL; - // fill meshes + // Fill meshes faceVertIndex = 0; nextShapeEnd = objAttributes.num_face_num_verts; - // see how many verts till the next shape + // See how many verts till the next shape nextShape = 1; if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset; lastMaterial = -1; meshIndex = 0; localMeshVertexCount = 0; - // walk all the faces + // Walk all the faces for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) { - bool newMesh = false; // do we need a new mesh? + bool newMesh = false; // Do we need a new mesh? if (faceId >= nextShapeEnd) { - // try to find the last vert in the next shape + // Try to find the last vert in the next shape nextShape++; if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset; - else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces + else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces newMesh = true; } - // if this is a new material, we need to allocate a new mesh + + // If this is a new material, we need to allocate a new mesh if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) newMesh = true; lastMaterial = objAttributes.material_ids[faceId]; @@ -4375,8 +4375,7 @@ static Model LoadOBJ(const char *fileName) } int matId = 0; - if (lastMaterial >= 0 && lastMaterial < (int)objMaterialCount) - matId = lastMaterial; + if ((lastMaterial >= 0) && (lastMaterial < (int)objMaterialCount)) matId = lastMaterial; model.meshMaterial[meshIndex] = matId; @@ -4386,19 +4385,15 @@ static Model LoadOBJ(const char *fileName) int normalIndex = objAttributes.faces[faceVertIndex].vn_idx; int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx; - for (int i = 0; i < 3; i++) - model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i]; + for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i]; - for (int i = 0; i < 3; i++) - model.meshes[meshIndex].normals[localMeshVertexCount * 3 + i] = objAttributes.normals[normalIndex * 3 + i]; + for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i]; - for (int i = 0; i < 2; i++) - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + i] = objAttributes.texcoords[texcordIndex * 2 + i]; + for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i]; - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1]; + model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1]; - for (int i = 0; i < 4; i++) - model.meshes[meshIndex].colors[localMeshVertexCount * 4 + i] = 255; + for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255; faceVertIndex++; localMeshVertexCount++; @@ -4412,8 +4407,7 @@ static Model LoadOBJ(const char *fileName) tinyobj_shapes_free(objShapes, objShapeCount); tinyobj_materials_free(objMaterials, objMaterialCount); - for (int i = 0; i < model.meshCount; i++) - UploadMesh(model.meshes + i, true); + for (int i = 0; i < model.meshCount; i++) UploadMesh(model.meshes + i, true); // Restore current working directory if (CHDIR(currentDir) != 0) @@ -5069,6 +5063,8 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat { Image image = { 0 }; + if (cgltfImage == NULL) return image; + if (cgltfImage->uri != NULL) // Check if image data is provided as an uri (base64 or path) { if ((strlen(cgltfImage->uri) > 5) && @@ -5110,7 +5106,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat image = LoadImage(TextFormat("%s/%s", texPath, cgltfImage->uri)); } } - else if (cgltfImage->buffer_view->buffer->data != NULL) // Check if image is provided as data buffer + else if (cgltfImage->buffer_view != NULL && cgltfImage->buffer_view->buffer->data != NULL) // Check if image is provided as data buffer { unsigned char *data = RL_MALLOC(cgltfImage->buffer_view->size); int offset = (int)cgltfImage->buffer_view->offset; @@ -5664,7 +5660,7 @@ static Model LoadGLTF(const char *fileName) } // Load primitive indices data (if provided) - if (mesh->primitives[p].indices != NULL) + if ((mesh->primitives[p].indices != NULL) && (mesh->primitives[p].indices->buffer_view != NULL)) { cgltf_accessor *attribute = mesh->primitives[p].indices; @@ -5681,7 +5677,7 @@ static Model LoadGLTF(const char *fileName) else if (attribute->component_type == cgltf_component_type_r_8u) { // Init raylib mesh indices to copy glTF attribute data - model.meshes[meshIndex].indices = RL_MALLOC(attribute->count * sizeof(unsigned short)); + model.meshes[meshIndex].indices = RL_MALLOC(attribute->count*sizeof(unsigned short)); LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short) } @@ -5736,7 +5732,7 @@ static Model LoadGLTF(const char *fileName) for (int i = 0; i < model.boneCount; i++) { - cgltf_node* node = skin.joints[i]; + cgltf_node *node = skin.joints[i]; cgltf_float worldTransform[16]; cgltf_node_transform_world(node, worldTransform); Matrix worldMatrix = { diff --git a/src/rtext.c b/src/rtext.c index ad9986537..5de11a1f8 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1282,7 +1282,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing { Vector2 textSize = { 0 }; - if ((isGpuReady && (font.texture.id == 0)) || + if ((isGpuReady && (font.texture.id == 0)) || (text == NULL) || (text[0] == '\0')) return textSize; // Security check int size = TextLength(text); // Get size in bytes of text @@ -2325,9 +2325,9 @@ static Font LoadBMFont(const char *fileName) // Convert hexadecimal to decimal (single digit) static unsigned char HexToInt(char hex) { - if (hex >= '0' && hex <= '9') return hex - '0'; - else if (hex >= 'a' && hex <= 'f') return hex - 'a' + 10; - else if (hex >= 'A' && hex <= 'F') return hex - 'A' + 10; + if ((hex >= '0') && (hex <= '9')) return hex - '0'; + else if ((hex >= 'a') && (hex <= 'f')) return hex - 'a' + 10; + else if ((hex >= 'A') && (hex <= 'F')) return hex - 'A' + 10; else return 0; } diff --git a/src/rtextures.c b/src/rtextures.c index 91b09a10d..6f84f2c1d 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -829,11 +829,11 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start, // Calculate how far the top-left pixel is along the gradient direction from the center of said gradient float startingPos = 0.5f - (cosDir*width/2) - (sinDir*height/2); - // With directions that lie in the first or third quadrant (i.e. from top-left to + // With directions that lie in the first or third quadrant (i.e. from top-left to // bottom-right or vice-versa), pixel (0, 0) is the farthest point on the gradient // (i.e. the pixel which should become one of the gradient's ends color); while for // directions that lie in the second or fourth quadrant, that point is pixel (width, 0). - float maxPosValue = + float maxPosValue = ((signbit(sinDir) != 0) == (signbit(cosDir) != 0)) ? fabsf(startingPos) : fabsf(startingPos+width*cosDir); @@ -842,12 +842,12 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start, for (int j = 0; j < height; j++) { // Calculate the relative position of the pixel along the gradient direction - float pos = (startingPos + (i*cosDir + j*sinDir)) / maxPosValue; + float pos = (startingPos + (i*cosDir + j*sinDir))/maxPosValue; float factor = pos; factor = (factor > 1.0f)? 1.0f : factor; // Clamp to [-1,1] factor = (factor < -1.0f)? -1.0f : factor; // Clamp to [-1,1] - factor = factor / 2 + 0.5f; + factor = factor/2.0f + 0.5f; // Generate the color for this pixel pixels[j*width + i].r = (int)((float)end.r*factor + (float)start.r*(1.0f - factor)); @@ -1007,7 +1007,8 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float { Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); - float aspectRatio = (float)width / (float)height; + float aspectRatio = (float)width/(float)height; + for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) @@ -3567,7 +3568,7 @@ void ImageDrawLineEx(Image *dst, Vector2 start, Vector2 end, int thick, Color co ImageDrawLine(dst, x1, y1, x2, y2, color); // Determine if the line is more horizontal or vertical - if (dx != 0 && abs(dy/dx) < 1) + if ((dx != 0) && (abs(dy/dx) < 1)) { // Line is more horizontal // Calculate half the width of the line @@ -5387,7 +5388,7 @@ static float HalfToFloat(unsigned short x) const unsigned int e = (x & 0x7C00) >> 10; // Exponent const unsigned int m = (x & 0x03FF) << 13; // Mantissa const float fm = (float)m; - const unsigned int v = (*(unsigned int*)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format + const unsigned int v = (*(unsigned int *)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized result = *(float *)&r; @@ -5400,7 +5401,7 @@ static unsigned short FloatToHalf(float x) { unsigned short result = 0; - const unsigned int b = (*(unsigned int*) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa + const unsigned int b = (*(unsigned int *) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa const unsigned int e = (b & 0x7F800000) >> 23; // Exponent const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding