Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop

This commit is contained in:
victorfisac
2016-01-20 13:48:00 +01:00
76 changed files with 633 additions and 651 deletions

152
README.md
View File

@@ -34,7 +34,7 @@ I've coded quite a lot in C# and XNA and I really love it (in fact, my students
so, I decided to use C# language notation and XNA naming conventions. That way, students can jump from
raylib to XNA, MonoGame or similar libs extremely easily.
raylib started as a weekend project and after three months of hard work, first version was published.
raylib started as a weekend project and after three months of hard work, raylib 1.0 was published on November 2013.
Enjoy it.
@@ -99,14 +99,37 @@ Most of the examples have been completely rewritten and +10 new examples have be
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.3.
notes on raylib 1.4
-------------------
On February 2016, after 4 months of raylib 1.3 release, it comes raylib 1.4.
Lots of parts of the library have been reviewed to better accomodate to shaders systems and multiple new features have been added.
SpriteFonts system has been improved, adding support for AngelCode fonts (.fnt) and TTF fonts (using stb_truetype).
Finally, raycast system for 3D picking is working, including some ray collision-detection functions.
A set of Image manipulation functions have been added to crop, resize, colorize, dither and even draw image-to-image or text-to-image.
Two new functions added for persistent data storage.
New [physac](https://github.com/raysan5/raylib/blob/develop/src/physac.h) physics module!
Complete LUA scripting support to allow raylib usage from LUA and LUA scripts support within raylib.
Up to 8 new examples have been added to show the new raylib features.
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.4.
features
--------
* Written in plain C code (C99)
* Uses C# PascalCase/camelCase notation
* Hardware accelerated with OpenGL (1.1, 3.3 or ES2)
* Unique OpenGL abstraction layer: [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
* Powerful fonts module with SpriteFonts support
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
* Powerful fonts module with multiple SpriteFonts formats support (XNA bitmap fonts, AngelCode fonts, TTF)
* Outstanding texture formats support, including compressed formats
* Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
@@ -145,126 +168,12 @@ Since raylib v1.1, you can download a Windows Installer package for easy install
building source (generate libraylib.a)
--------------------------------------
**Building raylib sources on desktop platforms:**
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/src/` folder and type:
mingw32-make PLATFORM=PLATFORM_DESKTOP
NOTE: By default raylib compiles using OpenGL 1.1 to maximize compatibility; to use OpenGL 3.3 just type:
mingw32-make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_33
**Building raylib sources on Raspberry Pi:**
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
sudo apt-get install openal1
_Step 2._ Navigate from command line to `raylib/src/` folder and type:
make
**Building raylib sources for Android:**
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
> Download and decompress on C: [Android SDK r23](http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
> Download and decompress on C: [Android NDK r10b](http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
> Download and decompress on C: [Apache Ant 1.9.4](http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
_Step 2._ Create the following environment variables with the correct paths:
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
ANDROID_NDK_ROOT = C:\android-ndk-r10b
ANT_HOME = C:\apache-ant-1.9.4
_Step 3._ Navigate from command line to folder `raylib/template_android/` and type:
%ANDROID_NDK_ROOT%\ndk-build
NOTE: libraylib.a will be generated in folder `raylib/src_android/obj/local/armeabi/`, it must be copied
to Android project; if using `raylib/template_android` project, copy it to `raylib/template_android/jni/libs/`.
**Building raylib sources for Web (HTML5)**
_Step 1._ Make sure you have installed emscripten SDK:
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
_Step 2._ Open `raylib/src/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
Check raylib wiki page: [Building source](https://github.com/raysan5/raylib/wiki/Building-source)
building examples
-----------------
**Building raylib examples on desktop platforms:**
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/examples/` folder and type:
mingw32-make PLATFORM=PLATFORM_DESKTOP
NOTE: Make sure the following libs (and their headers) are placed on their respectibe MinGW folders:
libglfw3.a - GLFW3 (static version)
libglew32.a - GLEW, OpenGL extension loading, only required if using OpenGL 3.3+ or ES2
libopenal32.a - OpenAL Soft, audio device management
**Building raylib examples on Raspberry Pi:**
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
sudo apt-get install openal1
_Step 2._ Navigate from command line to `raylib/examples/` folder and type:
make
**Building raylib examples for HTML5 (emscripten):**
_Step 1._ Make sure you have installed emscripten SDK:
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
_Step 2._ Open `raylib/examples/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
NOTE: At this moment, raylib examples are not ready to directly compile for HTML5, code needs to be reorganized due to the way web browsers work. To see how code should be refactored to fit compilation for web, check [core_basic_window_web.c](https://github.com/raysan5/raylib/blob/master/examples/core_basic_window_web.c) example.
**Building raylib project for Android (using template):**
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
> Download and decompress on C: [Android SDK r23] (http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
> Download and decompress on C: [Android NDK r10b] (http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
> Download and decompress on C: [Apache Ant 1.9.4] (http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
_Step 2._ Create the following environment variables with the correct paths:
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
ANDROID_NDK_ROOT = C:\android-ndk-r10b
ANT_HOME = C:\apache-ant-1.9.4
_Step 3._ To compile project, navigate from command line to folder `raylib/template_android/` and type:
%ANDROID_NDK_ROOT%\ndk-build
_Step 4._ To generate APK, navigate to folder `raylib/template_android/` and type:
%ANT_HOME%\bin\ant debug
_Step 5:_ To install APK into connected device (previously intalled drivers and activated USB debug mode on device):
%ANT_HOME%\bin\ant installd
_Step 6:_ To view log output from device:
%ANDROID_SDK_TOOLS%\adb logcat -c
%ANDROID_SDK_TOOLS%\adb -d logcat raylib:V *:S
**If you have any doubt, [just let me know][raysan5].**
Check raylib wiki page: [Building examples](https://github.com/raysan5/raylib/wiki/Building-examples)
contact
-------
@@ -292,6 +201,9 @@ The following people have contributed in some way to make raylib project a reali
- Daniel Moreno for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
- Daniel Gomez for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
- Sergio Martinez for helping on raygui development and tools development.
- Victor Fisac for developing physics raylib module (physac) and implementing light shaders and raycast system... and multiple tools and games.
- Albert Martos for helping on raygui and porting examples and game-templates to Android and HTML5.
- Ian Eito for helping on raygui and porting examples and game-templates to Android and HTML5.
[raysan5]: mailto:raysan@raysanweb.com "Ramon Santamaria - Ray San"
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"

View File

@@ -8,14 +8,17 @@ Around the source code there are multiple TODO points with pending revisions/bug
raylib v1.4
- TTF fonts support (using stb_truetype)
- Raycast system for 3D picking (including collisions detection)
[DONE] TTF fonts support (using stb_truetype)
[DONE] Raycast system for 3D picking (including collisions detection)
[DONE] Floyd-Steinberg dithering on 16bit image format conversion
[DONE] Basic image manipulation functions (crop, resize, draw...)
[DONE] Storage load/save data functionality
[DONE] Physics module
[IN PROGRESS] LUA scripting support (wrapper to lua lib)
- Remove GLEW dependency (use another solution... glad?)
- Floyd-Steinberg dithering on 16bit image format conversion
- Basic image manipulation functions (crop, resize, draw...)
- Basic image procedural generation (spot, gradient, noise...)
- Basic GPU stats sytem (memory, draws, time...)
- LUA scripting support (wrapper to lua lib)
Check [GITHUB ISSUES][issues] for further details on implementation status for this features!

View File

@@ -27,7 +27,7 @@ int main()
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
int framesCounter = 0;
float timePlayed = 0;
float timePlayed = 0.0f;
//float volume = 1.0;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second

View File

@@ -26,6 +26,8 @@ int main()
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@@ -23,7 +23,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
// Generates some random columns
float heights[MAX_COLUMNS];
@@ -37,7 +37,7 @@ int main()
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
}
Vector3 playerPosition = { 4, 2, 4 }; // Define player position
Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
@@ -60,16 +60,16 @@ int main()
Begin3dMode(camera);
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground
DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall
DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall
DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall
DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground
DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall
DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall
// Draw some cubes around
for (int i = 0; i < MAX_COLUMNS; i++)
{
DrawCube(positions[i], 2, heights[i], 2, colors[i]);
DrawCubeWires(positions[i], 2, heights[i], 2, MAROON);
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
}
End3dMode();

View File

@@ -21,9 +21,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera;
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@@ -48,10 +51,10 @@ int main()
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGrid(10, 1.0f);
End3dMode();

View File

@@ -21,11 +21,14 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera;
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
//SetTargetFPS(60); // Set our game to run at 60 frames-per-second, but not now...
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@@ -40,14 +43,14 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(WHITE);
ClearBackground(RAYWHITE);
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGrid(10, 1.0f);
End3dMode();

View File

@@ -21,10 +21,10 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Vector3 cubePosition = { 0.0, 1.0, 0.0 };
Vector3 cubeSize = { 2.0, 2.0, 2.0 };
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray; // Picking line ray
@@ -50,8 +50,8 @@ int main()
// Check collision between ray and box
collision = CheckCollisionRayBox(ray,
(Vector3){cubePosition.x - cubeSize.x / 2,cubePosition.y - cubeSize.y / 2,cubePosition.z - cubeSize.z / 2},
(Vector3){cubePosition.x + cubeSize.x / 2,cubePosition.y + cubeSize.y / 2,cubePosition.z + cubeSize.z / 2});
(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 });
}
//----------------------------------------------------------------------------------
@@ -66,10 +66,10 @@ int main()
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
DrawGrid(10.0, 1.0);
DrawRay(ray, MAROON);
DrawGrid(10, 1.0f);
End3dMode();
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);

View File

@@ -29,6 +29,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@@ -23,8 +23,8 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
Vector2 gamepadMovement = { 0, 0 };
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
Vector2 gamepadMovement = { 0.0f, 0.0f };
SetTargetFPS(60); // Set target frames-per-second
//--------------------------------------------------------------------------------------
@@ -43,8 +43,8 @@ int main()
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
{
ballPosition.x = screenWidth/2;
ballPosition.y = screenHeight/2;
ballPosition.x = (float)screenWidth/2;
ballPosition.y = (float)screenHeight/2;
}
}
//----------------------------------------------------------------------------------

View File

@@ -20,7 +20,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
SetTargetFPS(60); // Set target frames-per-second
//--------------------------------------------------------------------------------------
@@ -30,10 +30,10 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8;
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8;
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8;
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f;
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f;
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f;
//----------------------------------------------------------------------------------
// Draw

View File

@@ -20,8 +20,9 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
int mouseX, mouseY;
Vector2 ballPosition = { -100.0, -100.0 };
Vector2 ballPosition = { -100.0f, -100.0f };
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
// Main game loop
@@ -31,11 +32,7 @@ int main()
//----------------------------------------------------------------------------------
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
mouseX = GetMouseX();
mouseY = GetMouseY();
ballPosition.x = (float)mouseX;
ballPosition.y = (float)mouseY;
ballPosition = GetMousePosition();
}
//----------------------------------------------------------------------------------

View File

@@ -22,7 +22,7 @@ int main()
int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8,5); // Get a random integer number between -8 and 5 (both included)
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -37,7 +37,7 @@ int main()
// Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1)
{
randValue = GetRandomValue(-8,5);
randValue = GetRandomValue(-8, 5);
framesCounter = 0;
}
//----------------------------------------------------------------------------------

View File

@@ -21,9 +21,9 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
Vector2 cubeScreenPosition;
@@ -53,10 +53,10 @@ int main()
Begin3dMode(camera);
DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10.0, 1.0);
DrawGrid(10, 1.0f);
End3dMode();

View File

@@ -21,10 +21,10 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world
Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@@ -49,10 +49,10 @@ int main()
Begin3dMode(camera);
DrawGrid(10.0, 1.0); // Draw a grid
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();
DrawFPS(10, 10);

View File

@@ -21,16 +21,16 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Vector3 playerPosition = { 0, 1, 2 };
Vector3 playerSize = { 1, 2, 1 };
Vector3 playerPosition = { 0.0f, 1.0f, 2.0f };
Vector3 playerSize = { 1.0f, 2.0f, 1.0f };
Color playerColor = GREEN;
Vector3 enemyBoxPos = { -4, 1, 0 };
Vector3 enemyBoxSize = { 2, 2, 2 };
Vector3 enemyBoxPos = { -4.0f, 1.0f, 0.0f };
Vector3 enemyBoxSize = { 2.0f, 2.0f, 2.0f };
Vector3 enemySpherePos = { 4, 0, 0 };
Vector3 enemySpherePos = { 4.0f, 0.0f, 0.0f };
float enemySphereSize = 1.5f;
bool collision = false;
@@ -98,7 +98,7 @@ int main()
// Draw player
DrawCubeV(playerPosition, playerSize, playerColor);
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
// Define the camera to look into our 3d world
Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
@@ -31,7 +31,7 @@ int main()
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
SetModelTexture(&map, texture); // Bind texture to map model
Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM

View File

@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
// Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -42,21 +42,21 @@ int main()
Begin3dMode(camera);
DrawCube((Vector3){-4, 0, 2}, 2, 5, 2, RED);
DrawCubeWires((Vector3){-4, 0, 2}, 2, 5, 2, GOLD);
DrawCubeWires((Vector3){-4, 0, -2}, 3, 6, 2, MAROON);
DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
DrawSphere((Vector3){-1, 0, -2}, 1, GREEN);
DrawSphereWires((Vector3){1, 0, 2}, 2, 16, 16, LIME);
DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
DrawCylinder((Vector3){4, 0, -2}, 1, 2, 3, 4, SKYBLUE);
DrawCylinderWires((Vector3){4, 0, -2}, 1, 2, 3, 4, DARKBLUE);
DrawCylinderWires((Vector3){4.5, -1, 2}, 1, 1, 2, 6, BROWN);
DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
DrawCylinder((Vector3){1, 0, -4}, 0, 1.5, 3, 8, GOLD);
DrawCylinderWires((Vector3){1, 0, -4}, 0, 1.5, 3, 8, PINK);
DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@@ -21,13 +21,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define our custom camera to look into our 3d world
Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 24.0f, 18.0f, 24.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Model map = LoadHeightmap(image, 32); // Load heightmap model
SetModelTexture(&map, texture); // Bind texture to model
Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!)
Vector3 mapPosition = { -16.0f, 0.0f, -16.0f }; // Set model position (depends on model scaling!)
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM

View File

@@ -21,12 +21,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -49,7 +49,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
DrawGizmo(position); // Draw gizmo

View File

@@ -6,8 +6,7 @@ in vec3 vertexNormal;
out vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
// NOTE: Add here your custom variables
@@ -15,5 +14,5 @@ void main()
{
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,16 +5,16 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
fragColor = vec4(gray, gray, gray, tintColor.a);
fragColor = vec4(gray, gray, gray, fragTintColor.a);
}

View File

@@ -6,19 +6,19 @@ in vec3 fragNormal;
// Diffuse data
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// Light attributes
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);
uniform vec3 light_diffuseColor = vec3(1, 0.5, 0);
uniform vec3 light_specularColor = vec3(0, 1, 0);
uniform float light_intensity = 1;
uniform float light_specIntensity = 1;
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0.0);
uniform vec3 light_diffuseColor = vec3(1.0, 0.5, 0.0);
uniform vec3 light_specularColor = vec3(0.0, 1.0, 0.0);
uniform float light_intensity = 1.0;
uniform float light_specIntensity = 1.0;
// Material attributes
uniform vec3 mat_ambientColor = vec3(1, 1, 1);
uniform vec3 mat_specularColor = vec3(1, 1, 1);
uniform float mat_glossiness = 50;
uniform vec3 mat_ambientColor = vec3(1.0, 1.0, 1.0);
uniform vec3 mat_specularColor = vec3(1.0, 1.0, 1.0);
uniform float mat_glossiness = 50.0;
// World attributes
uniform vec3 lightPos;
@@ -29,7 +29,7 @@ out vec4 fragColor;
vec3 AmbientLighting()
{
return mat_ambientColor * light_ambientColor;
return (mat_ambientColor*light_ambientColor);
}
vec3 DiffuseLighting(in vec3 N, in vec3 L)
@@ -37,15 +37,15 @@ vec3 DiffuseLighting(in vec3 N, in vec3 L)
// Lambertian reflection calculation
float diffuse = clamp(dot(N, L), 0, 1);
return tintColor.xyz * light_diffuseColor * light_intensity * diffuse;
return (fragTintColor.xyz*light_diffuseColor*light_intensity*diffuse);
}
vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
{
float specular = 0;
float specular = 0.0;
// Calculate specular reflection only if the surface is oriented to the light source
if(dot(N, L) > 0)
if (dot(N, L) > 0)
{
// Calculate half vector
vec3 H = normalize(L + V);
@@ -54,7 +54,7 @@ vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
specular = pow(dot(N, H), 3 + mat_glossiness);
}
return mat_specularColor * light_specularColor * light_specIntensity * specular;
return (mat_specularColor*light_specularColor*light_specIntensity*specular);
}
void main()

View File

@@ -6,8 +6,7 @@ in vec2 vertexTexCoord;
in vec3 vertexNormal;
// Projection and model data
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
uniform mat4 modelMatrix;
// Attributes to fragment shader
@@ -21,8 +20,8 @@ void main()
// Calculate view vector normal from model
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
fragNormal = normalize(normalMatrix * vertexNormal);
fragNormal = normalize(normalMatrix*vertexNormal);
// Calculate final vertex position
gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -4,16 +4,15 @@ attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec4 vertexColor;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec4 fragTintColor;
void main()
{
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
fragTintColor = vertexColor;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -2,11 +2,11 @@
uniform sampler2D texture0;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec4 fragTintColor;
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*fragColor;
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));

View File

@@ -5,17 +5,17 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 800; // HARDCODED for example!
const float renderHeight = 480; // Use uniforms instead...
const float renderWidth = 800.0; // HARDCODED for example!
const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
uniform vec2 center = vec2(200.0, 200.0);
void main (void)
{

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [lighting] example - Basic Phong lighting
* raylib [shaders] example - Basic lighting: Blinn-Phong
*
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -22,14 +22,13 @@ int main()
const int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [lighting] example - blinn phong lighting");
SetTargetFPS(60);
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting");
// Camera initialization
Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
// Model initialization
Vector3 position = { 0.0, 0.0, 0.0 };
Vector3 position = { 0.0f, 0.0f, 0.0f };
Model model = LoadModel("resources/model/dwarf.obj");
Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs");
SetModelShader(&model, shader);
@@ -54,7 +53,7 @@ int main()
Material matBlinn;
// Light initialization
light.position = (Vector3){ 5.0f, 1.0f, 1.0f };
light.position = (Vector3){ 4.0f, 2.0f, 0.0f };
light.direction = (Vector3){ 5.0f, 1.0f, 1.0f };
light.intensity = 1.0f;
light.diffuse = WHITE;
@@ -72,6 +71,8 @@ int main()
SetCameraMode(CAMERA_FREE); // Set camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
@@ -79,9 +80,7 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
// Update camera position
UpdateCamera(&camera);
UpdateCamera(&camera); // Update camera position
// Glossiness input control
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
@@ -129,7 +128,9 @@ int main()
Begin3dMode(camera);
DrawModel(model, position, 4.0f, matBlinn.diffuse);
DrawSphere(light.position, 1.0f, YELLOW);
DrawSphere(light.position, 0.5f, GOLD);
DrawGrid(20, 1.0f);
End3dMode();

View File

@@ -30,13 +30,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
Shader shader = LoadShader("resources/shaders/base.vs",
"resources/shaders/swirl.fs"); // Load postpro shader
@@ -45,7 +45,7 @@ int main()
// NOTE: If uniform variable could not be found in the shader, function returns -1
int swirlCenterLoc = GetShaderLocation(shader, "center");
float swirlCenter[2] = { screenWidth/2, screenHeight/2 };
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
SetPostproShader(shader); // Set fullscreen postprocessing shader
@@ -83,7 +83,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@@ -30,7 +30,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
@@ -40,7 +40,7 @@ int main()
SetModelShader(&dwarf, shader); // Set shader effect to 3d model
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
// Setup orbital camera
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
@@ -68,7 +68,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@@ -30,13 +30,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
// Define the camera to look into our 3d world
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
SetModelTexture(&dwarf, texture); // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
Shader shader = LoadShader("resources/shaders/base.vs",
"resources/shaders/bloom.fs"); // Load postpro shader
@@ -69,7 +69,7 @@ int main()
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
DrawGrid(10.0, 1.0); // Draw a grid
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();

View File

@@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@@ -19,6 +19,8 @@ int main()
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop

View File

@@ -35,9 +35,7 @@ int main()
char raylib[8] = " \0"; // raylib text array, max 8 letters
int state = 0; // Tracking animation states (State Machine)
float alpha = 1.0; // Useful for fading
float alpha = 1.0f; // Useful for fading
SetTargetFPS(60);
//--------------------------------------------------------------------------------------

View File

@@ -38,8 +38,7 @@ int main()
ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2,
screenHeight/2 - texture.height/2, WHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
DrawText("this IS a texture!", 360, 370, 10, GRAY);

View File

@@ -41,12 +41,12 @@ int main()
mouseTail[i].position = (Vector2){ 0, 0 };
mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 };
mouseTail[i].alpha = 1.0f;
mouseTail[i].size = (float)GetRandomValue(1, 30)/20;
mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f;
mouseTail[i].rotation = GetRandomValue(0, 360);
mouseTail[i].active = false;
}
float gravity = 3;
float gravity = 3.0f;
Texture2D smoke = LoadTexture("resources/smoke.png");
@@ -85,7 +85,7 @@ int main()
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
mouseTail[i].rotation += 5;
mouseTail[i].rotation += 5.0f;
}
}

View File

@@ -23,7 +23,7 @@ int main()
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
Vector2 position = { 350, 240 };
Vector2 position = { 350.0f, 240.0f };
Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
int currentFrame = 0;
//--------------------------------------------------------------------------------------

View File

@@ -6,8 +6,7 @@ in vec3 vertexNormal;
out vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
// NOTE: Add here your custom variables
@@ -15,5 +14,5 @@ void main()
{
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
@@ -18,23 +18,23 @@ void main()
{
for (int j = -3; j < 3; j++)
{
sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
sum += texture(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
}
}
if (texture2D(texture0, fragTexCoord).r < 0.3)
if (texture(texture0, fragTexCoord).r < 0.3)
{
tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord);
tc = sum*sum*0.012 + texture(texture0, fragTexCoord);
}
else
{
if (texture2D(texture0, fragTexCoord).r < 0.5)
if (texture(texture0, fragTexCoord).r < 0.5)
{
tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord);
tc = sum*sum*0.009 + texture(texture0, fragTexCoord);
}
else
{
tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord);
tc = sum*sum*0.0075 + texture(texture0, fragTexCoord);
}
}

View File

@@ -5,24 +5,24 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
void main()
{
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0];
vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0];
for (int i = 1; i < 3; i++)
{
tc += texture2D(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture2D(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
}
fragColor = vec4(tc, 1.0);

View File

@@ -5,20 +5,20 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
float hatchOffsetY = 5.0f;
float lumThreshold01 = 0.9f;
float lumThreshold02 = 0.7f;
float lumThreshold03 = 0.5f;
float lumThreshold04 = 0.3f;
float hatchOffsetY = 5.0;
float lumThreshold01 = 0.9;
float lumThreshold02 = 0.7;
float lumThreshold03 = 0.5;
float lumThreshold04 = 0.3;
void main()
{
vec3 tc = vec3(1.0, 1.0, 1.0);
float lum = length(texture2D(texture0, fragTexCoord).rgb);
float lum = length(texture(texture0, fragTexCoord).rgb);
if (lum < lumThreshold01)
{

View File

@@ -5,14 +5,14 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
float stitchingSize = 6.0f;
float stitchingSize = 6.0;
uniform int invert = 0;
@@ -35,11 +35,11 @@ vec4 PostFX(sampler2D tex, vec2 uv)
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
{
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
}
else
{
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
else c = vec4(0.0, 0.0, 0.0, 1.0);
}

View File

@@ -5,27 +5,27 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 color = texture2D(texture0, fragTexCoord);
vec4 color = texture(texture0, fragTexCoord);
color += texture2D(texture0, fragTexCoord + 0.001);
color += texture2D(texture0, fragTexCoord + 0.003);
color += texture2D(texture0, fragTexCoord + 0.005);
color += texture2D(texture0, fragTexCoord + 0.007);
color += texture2D(texture0, fragTexCoord + 0.009);
color += texture2D(texture0, fragTexCoord + 0.011);
color += texture(texture0, fragTexCoord + 0.001);
color += texture(texture0, fragTexCoord + 0.003);
color += texture(texture0, fragTexCoord + 0.005);
color += texture(texture0, fragTexCoord + 0.007);
color += texture(texture0, fragTexCoord + 0.009);
color += texture(texture0, fragTexCoord + 0.011);
color += texture2D(texture0, fragTexCoord - 0.001);
color += texture2D(texture0, fragTexCoord - 0.003);
color += texture2D(texture0, fragTexCoord - 0.005);
color += texture2D(texture0, fragTexCoord - 0.007);
color += texture2D(texture0, fragTexCoord - 0.009);
color += texture2D(texture0, fragTexCoord - 0.011);
color += texture(texture0, fragTexCoord - 0.001);
color += texture(texture0, fragTexCoord - 0.003);
color += texture(texture0, fragTexCoord - 0.005);
color += texture(texture0, fragTexCoord - 0.007);
color += texture(texture0, fragTexCoord - 0.009);
color += texture(texture0, fragTexCoord - 0.011);
color.rgb = vec3((color.r + color.g + color.b)/3.0);
color = color/9.5;

View File

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
@@ -13,7 +13,7 @@ const float PI = 3.1415926535;
void main()
{
float aperture = 178.0f;
float aperture = 178.0;
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
@@ -36,5 +36,5 @@ void main()
uv = fragTexCoord.xy;
}
fragColor = texture2D(texture0, uv);
fragColor = texture(texture0, uv);
}

View File

@@ -5,16 +5,16 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
vec4 base = texture(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
fragColor = vec4(gray, gray, gray, tintColor.a);
fragColor = vec4(gray, gray, gray, fragTintColor.a);
}

View File

@@ -6,7 +6,7 @@ in vec3 fragNormal;
// Diffuse data
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// Light attributes
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);

View File

@@ -6,8 +6,7 @@ in vec2 vertexTexCoord;
in vec3 vertexNormal;
// Projection and model data
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
uniform mat4 modelMatrix;
// Attributes to fragment shader
@@ -21,8 +20,8 @@ void main()
// Calculate view vector normal from model
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
fragNormal = normalize(normalMatrix * vertexNormal);
fragNormal = normalize(normalMatrix*vertexNormal);
// Calculate final vertex position
gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -5,15 +5,15 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
uniform float pixelWidth = 5.0f;
uniform float pixelHeight = 5.0f;
uniform float pixelWidth = 5.0;
uniform float pixelHeight = 5.0;
void main()
{
@@ -22,7 +22,7 @@ void main()
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
vec3 tc = texture2D(texture0, coord).rgb;
vec3 tc = texture(texture0, coord).rgb;
fragColor = vec4(tc, 1.0);
}

View File

@@ -5,16 +5,16 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
float gamma = 0.6f;
float numColors = 8.0f;
float gamma = 0.6;
float numColors = 8.0;
void main()
{
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
vec3 color = texture(texture0, fragTexCoord.xy).rgb;
color = pow(color, vec3(gamma, gamma, gamma));
color = color*numColors;

View File

@@ -5,13 +5,13 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec3 color = texture2D(texture0, fragTexCoord).rgb;
vec3 color = texture(texture0, fragTexCoord).rgb;
vec3 colors[3];
colors[0] = vec3(0.0, 0.0, 1.0);
colors[1] = vec3(1.0, 1.0, 0.0);

View File

@@ -5,12 +5,12 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
float offset = 0;
float frequency = 720/3.0;
float offset = 0.0;
float frequency = 720.0/3.0;
uniform float time;
@@ -21,7 +21,7 @@ void main (void)
float tval = 0; //time
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
vec4 color = texture2D(texture0, fragTexCoord);
vec4 color = texture(texture0, fragTexCoord);
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
@@ -35,7 +35,7 @@ void main (void)
float globalPos = (fragTexCoord.y + offset) * frequency;
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
vec4 color = texture2D(texture0, fragTexCoord);
vec4 color = texture(texture0, fragTexCoord);
fragColor = mix(vec4(0, 0.3, 0, 0), color, wavePos);
fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos);
}

View File

@@ -5,17 +5,17 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
uniform vec2 center = vec2(200.0, 200.0);
void main (void)
{
@@ -35,7 +35,7 @@ void main (void)
}
tc += center;
vec3 color = texture2D(texture0, tc/texSize).rgb;
vec3 color = texture(texture0, tc/texSize).rgb;
fragColor = vec4(color, 1.0);;
}

View File

@@ -5,15 +5,15 @@ in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
vec4 texelColor = texture(texture0, fragTexCoord);
// NOTE: Implement here your fragment shader code
fragColor = texelColor*tintColor;
fragColor = texelColor*fragTintColor;
}

View File

@@ -6,8 +6,7 @@ attribute vec3 vertexNormal;
varying vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
uniform mat4 mvpMatrix;
// NOTE: Add here your custom variables
@@ -17,5 +16,5 @@ void main()
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -4,7 +4,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,16 +5,16 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
gl_FragColor = vec4(gray, gray, gray, tintColor.a);
gl_FragColor = vec4(gray, gray, gray, fragTintColor.a);
}

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables

View File

@@ -5,7 +5,7 @@ precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
@@ -15,5 +15,5 @@ void main()
// NOTE: Implement here your fragment shader code
gl_FragColor = texelColor*tintColor;
gl_FragColor = texelColor*fragTintColor;
}

View File

@@ -309,8 +309,8 @@ void InitWindow(int width, int height, const char *title)
emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenInputCallback);
#endif
mousePosition.x = screenWidth/2;
mousePosition.y = screenHeight/2;
mousePosition.x = (float)screenWidth/2.0f;
mousePosition.y = (float)screenHeight/2.0f;
// raylib logo appearing animation (if enabled)
if (showLogo)
@@ -577,7 +577,7 @@ void Begin3dMode(Camera camera)
// Setup perspective projection
float aspect = (float)screenWidth/(float)screenHeight;
double top = 0.1f*tan(45.0f*PI / 360.0f);
double top = 0.1f*tan(45.0f*PI/360.0f);
double right = top*aspect;
// NOTE: zNear and zFar values are important when computing depth buffer values
@@ -608,7 +608,7 @@ void End3dMode(void)
// Set target FPS for the game
void SetTargetFPS(int fps)
{
targetTime = 1 / (double)fps;
targetTime = 1.0/(double)fps;
TraceLog(INFO, "Target time per frame: %02.03f milliseconds", (float)targetTime*1000);
}
@@ -625,7 +625,7 @@ float GetFrameTime(void)
// As we are operate quite a lot with frameTime,
// it could be no stable, so we round it before passing it around
// NOTE: There are still problems with high framerates (>500fps)
double roundedFrameTime = round(frameTime*10000)/10000;
double roundedFrameTime = round(frameTime*10000)/10000.0;
return (float)roundedFrameTime; // Time in seconds to run a frame
}
@@ -806,8 +806,8 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera)
// Calculate normalized device coordinates
// NOTE: y value is negative
float x = (2.0f * mousePosition.x) / GetScreenWidth() - 1.0f;
float y = 1.0f - (2.0f * mousePosition.y) / GetScreenHeight();
float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f;
float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight();
float z = 1.0f;
// Store values in a vector
@@ -880,7 +880,7 @@ Vector2 WorldToScreen(Vector3 position, Camera camera)
Vector3 ndcPos = { worldPos.x / worldPos.w, -worldPos.y / worldPos.w, worldPos.z / worldPos.z };
// Calculate 2d screen position vector
Vector2 screenPosition = { (ndcPos.x + 1.0f) / 2.0f * GetScreenWidth(), (ndcPos.y + 1.0f) / 2.0f * GetScreenHeight() };
Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
return screenPosition;
}
@@ -1963,7 +1963,7 @@ static void PollInputEvents(void)
int key = keysBuffer[i];
if (keyboardMode == 2)
if (keyboardMode == 2) // scancodes
{
// NOTE: If (key == 0x1b), depending on next key, it could be a special keymap code!
// Up -> 1b 5b 41 / Left -> 1b 5b 44 / Right -> 1b 5b 43 / Down -> 1b 5b 42
@@ -1998,10 +1998,14 @@ static void PollInputEvents(void)
// Detect ESC to stop program
if ((key == 0x1b) && (numKeysBuffer == 1)) windowShouldClose = true;
}
else if (keyboardMode == 1)
else if (keyboardMode == 1) // keycodes (K_MEDIUMRAW mode)
{
TraceLog(DEBUG, "Pressed key (keycode): 0x%02x", key);
// NOTE: Each key is 7-bits (high bit in the byte is 0 for down, 1 for up)
// TODO: Review (or rewrite) this code... not clear... replace by events!
int asciiKey = -1;
// Convert keycode to some recognized key (ASCII or GLFW3 equivalent)

View File

@@ -56,7 +56,7 @@ extern unsigned int whiteTexture;
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
static float GetHeightValue(Color pixel);
static VertexData LoadOBJ(const char *fileName);
static Mesh LoadOBJ(const char *fileName);
//----------------------------------------------------------------------------------
// Module Functions Definition
@@ -558,23 +558,23 @@ void DrawGizmo(Vector3 position)
Model LoadModel(const char *fileName)
{
Model model;
VertexData vData = { 0 };
Mesh mesh = { 0 };
// NOTE: Initialize default data for model in case loading fails, maybe a cube?
if (strcmp(GetExtension(fileName),"obj") == 0) vData = LoadOBJ(fileName);
if (strcmp(GetExtension(fileName),"obj") == 0) mesh = LoadOBJ(fileName);
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
// NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
if (vData.vertexCount == 0)
if (mesh.vertexCount == 0)
{
TraceLog(WARNING, "Model could not be loaded");
}
else
{
// NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
model = rlglLoadModel(vData); // Upload vertex data to GPU
model = rlglLoadModel(mesh); // Upload vertex data to GPU
// Now that vertex data is uploaded to GPU, we can free arrays
// NOTE 1: We don't need CPU vertex data on OpenGL 3.3 or ES2... for static meshes...
@@ -583,10 +583,10 @@ Model LoadModel(const char *fileName)
/*
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
free(mesh.vertices);
free(mesh.texcoords);
free(mesh.normals);
free(mesh.colors);
}
*/
}
@@ -595,7 +595,7 @@ Model LoadModel(const char *fileName)
}
// Load a 3d model (from vertex data)
Model LoadModelEx(VertexData data)
Model LoadModelEx(Mesh data)
{
Model model;
@@ -610,7 +610,7 @@ Model LoadModelEx(VertexData data)
// Load a heightmap image as a 3d model
Model LoadHeightmap(Image heightmap, float maxHeight)
{
VertexData vData;
Mesh mesh;
int mapX = heightmap.width;
int mapZ = heightmap.height;
@@ -621,12 +621,12 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
// TODO: Consider resolution when generating model data?
int numTriangles = (mapX-1)*(mapZ-1)*2; // One quad every four pixels
vData.vertexCount = numTriangles*3;
mesh.vertexCount = numTriangles*3;
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char)); // Not used...
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float
@@ -644,51 +644,51 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
//----------------------------------------------------------
// one triangle - 3 vertex
vData.vertices[vCounter] = x;
vData.vertices[vCounter + 1] = GetHeightValue(heightmapPixels[x + z*mapX])*scaleFactor;
vData.vertices[vCounter + 2] = z;
mesh.vertices[vCounter] = x;
mesh.vertices[vCounter + 1] = GetHeightValue(heightmapPixels[x + z*mapX])*scaleFactor;
mesh.vertices[vCounter + 2] = z;
vData.vertices[vCounter + 3] = x;
vData.vertices[vCounter + 4] = GetHeightValue(heightmapPixels[x + (z+1)*mapX])*scaleFactor;
vData.vertices[vCounter + 5] = z+1;
mesh.vertices[vCounter + 3] = x;
mesh.vertices[vCounter + 4] = GetHeightValue(heightmapPixels[x + (z+1)*mapX])*scaleFactor;
mesh.vertices[vCounter + 5] = z+1;
vData.vertices[vCounter + 6] = x+1;
vData.vertices[vCounter + 7] = GetHeightValue(heightmapPixels[(x+1) + z*mapX])*scaleFactor;
vData.vertices[vCounter + 8] = z;
mesh.vertices[vCounter + 6] = x+1;
mesh.vertices[vCounter + 7] = GetHeightValue(heightmapPixels[(x+1) + z*mapX])*scaleFactor;
mesh.vertices[vCounter + 8] = z;
// another triangle - 3 vertex
vData.vertices[vCounter + 9] = vData.vertices[vCounter + 6];
vData.vertices[vCounter + 10] = vData.vertices[vCounter + 7];
vData.vertices[vCounter + 11] = vData.vertices[vCounter + 8];
mesh.vertices[vCounter + 9] = mesh.vertices[vCounter + 6];
mesh.vertices[vCounter + 10] = mesh.vertices[vCounter + 7];
mesh.vertices[vCounter + 11] = mesh.vertices[vCounter + 8];
vData.vertices[vCounter + 12] = vData.vertices[vCounter + 3];
vData.vertices[vCounter + 13] = vData.vertices[vCounter + 4];
vData.vertices[vCounter + 14] = vData.vertices[vCounter + 5];
mesh.vertices[vCounter + 12] = mesh.vertices[vCounter + 3];
mesh.vertices[vCounter + 13] = mesh.vertices[vCounter + 4];
mesh.vertices[vCounter + 14] = mesh.vertices[vCounter + 5];
vData.vertices[vCounter + 15] = x+1;
vData.vertices[vCounter + 16] = GetHeightValue(heightmapPixels[(x+1) + (z+1)*mapX])*scaleFactor;
vData.vertices[vCounter + 17] = z+1;
mesh.vertices[vCounter + 15] = x+1;
mesh.vertices[vCounter + 16] = GetHeightValue(heightmapPixels[(x+1) + (z+1)*mapX])*scaleFactor;
mesh.vertices[vCounter + 17] = z+1;
vCounter += 18; // 6 vertex, 18 floats
// Fill texcoords array with data
//--------------------------------------------------------------
vData.texcoords[tcCounter] = (float)x / (mapX-1);
vData.texcoords[tcCounter + 1] = (float)z / (mapZ-1);
mesh.texcoords[tcCounter] = (float)x / (mapX-1);
mesh.texcoords[tcCounter + 1] = (float)z / (mapZ-1);
vData.texcoords[tcCounter + 2] = (float)x / (mapX-1);
vData.texcoords[tcCounter + 3] = (float)(z+1) / (mapZ-1);
mesh.texcoords[tcCounter + 2] = (float)x / (mapX-1);
mesh.texcoords[tcCounter + 3] = (float)(z+1) / (mapZ-1);
vData.texcoords[tcCounter + 4] = (float)(x+1) / (mapX-1);
vData.texcoords[tcCounter + 5] = (float)z / (mapZ-1);
mesh.texcoords[tcCounter + 4] = (float)(x+1) / (mapX-1);
mesh.texcoords[tcCounter + 5] = (float)z / (mapZ-1);
vData.texcoords[tcCounter + 6] = vData.texcoords[tcCounter + 4];
vData.texcoords[tcCounter + 7] = vData.texcoords[tcCounter + 5];
mesh.texcoords[tcCounter + 6] = mesh.texcoords[tcCounter + 4];
mesh.texcoords[tcCounter + 7] = mesh.texcoords[tcCounter + 5];
vData.texcoords[tcCounter + 8] = vData.texcoords[tcCounter + 2];
vData.texcoords[tcCounter + 9] = vData.texcoords[tcCounter + 3];
mesh.texcoords[tcCounter + 8] = mesh.texcoords[tcCounter + 2];
mesh.texcoords[tcCounter + 9] = mesh.texcoords[tcCounter + 3];
vData.texcoords[tcCounter + 10] = (float)(x+1) / (mapX-1);
vData.texcoords[tcCounter + 11] = (float)(z+1) / (mapZ-1);
mesh.texcoords[tcCounter + 10] = (float)(x+1) / (mapX-1);
mesh.texcoords[tcCounter + 11] = (float)(z+1) / (mapZ-1);
tcCounter += 12; // 6 texcoords, 12 floats
// Fill normals array with data
@@ -696,9 +696,9 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
// NOTE: Current Model implementation doe not use normals!
for (int i = 0; i < 18; i += 3)
{
vData.normals[nCounter + i] = 0.0f;
vData.normals[nCounter + i + 1] = 1.0f;
vData.normals[nCounter + i + 2] = 0.0f;
mesh.normals[nCounter + i] = 0.0f;
mesh.normals[nCounter + i + 1] = 1.0f;
mesh.normals[nCounter + i + 2] = 0.0f;
}
// TODO: Calculate normals in an efficient way
@@ -713,20 +713,20 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
// Fill color data
// NOTE: Not used any more... just one plain color defined at DrawModel()
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
// NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
Model model = rlglLoadModel(vData);
Model model = rlglLoadModel(mesh);
// Now that vertex data is uploaded to GPU, we can free arrays
// NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
free(mesh.vertices);
free(mesh.texcoords);
free(mesh.normals);
free(mesh.colors);
}
return model;
@@ -735,14 +735,14 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
// Load a map image as a 3d model (cubes based)
Model LoadCubicmap(Image cubicmap)
{
VertexData vData;
Mesh mesh;
Color *cubicmapPixels = GetImageData(cubicmap);
// Map cube size will be 1.0
float mapCubeSide = 1.0f;
int mapWidth = cubicmap.width * (int)mapCubeSide;
int mapHeight = cubicmap.height * (int)mapCubeSide;
int mapWidth = cubicmap.width*(int)mapCubeSide;
int mapHeight = cubicmap.height*(int)mapCubeSide;
// NOTE: Max possible number of triangles numCubes * (12 triangles by cube)
int maxTriangles = cubicmap.width*cubicmap.height*12;
@@ -753,11 +753,11 @@ Model LoadCubicmap(Image cubicmap)
float w = mapCubeSide;
float h = mapCubeSide;
float h2 = mapCubeSide * 1.5; // TODO: Review walls height...
float h2 = mapCubeSide*1.5f; // TODO: Review walls height...
Vector3 *mapVertices = (Vector3 *)malloc(maxTriangles * 3 * sizeof(Vector3));
Vector2 *mapTexcoords = (Vector2 *)malloc(maxTriangles * 3 * sizeof(Vector2));
Vector3 *mapNormals = (Vector3 *)malloc(maxTriangles * 3 * sizeof(Vector3));
Vector3 *mapVertices = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3));
Vector2 *mapTexcoords = (Vector2 *)malloc(maxTriangles*3*sizeof(Vector2));
Vector3 *mapNormals = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3));
// Define the 6 normals of the cube, we will combine them accordingly later...
Vector3 n1 = { 1.0f, 0.0f, 0.0f };
@@ -775,12 +775,12 @@ Model LoadCubicmap(Image cubicmap)
float height;
} RectangleF;
RectangleF rightTexUV = { 0, 0, 0.5, 0.5 };
RectangleF leftTexUV = { 0.5, 0, 0.5, 0.5 };
RectangleF frontTexUV = { 0, 0, 0.5, 0.5 };
RectangleF backTexUV = { 0.5, 0, 0.5, 0.5 };
RectangleF topTexUV = { 0, 0.5, 0.5, 0.5 };
RectangleF bottomTexUV = { 0.5, 0.5, 0.5, 0.5 };
RectangleF rightTexUV = { 0.0f, 0.0f, 0.5f, 0.5f };
RectangleF leftTexUV = { 0.5f, 0.0f, 0.5f, 0.5f };
RectangleF frontTexUV = { 0.0f, 0.0f, 0.5f, 0.5f };
RectangleF backTexUV = { 0.5f, 0.0f, 0.5f, 0.5f };
RectangleF topTexUV = { 0.0f, 0.5f, 0.5f, 0.5f };
RectangleF bottomTexUV = { 0.5f, 0.5f, 0.5f, 0.5f };
for (int z = 0; z < mapHeight; z += mapCubeSide)
{
@@ -1041,25 +1041,25 @@ Model LoadCubicmap(Image cubicmap)
}
// Move data from mapVertices temp arays to vertices float array
vData.vertexCount = vCounter;
mesh.vertexCount = vCounter;
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char)); // Not used...
// Fill color data
// NOTE: Not used any more... just one plain color defined at DrawModel()
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
int fCounter = 0;
// Move vertices data
for (int i = 0; i < vCounter; i++)
{
vData.vertices[fCounter] = mapVertices[i].x;
vData.vertices[fCounter + 1] = mapVertices[i].y;
vData.vertices[fCounter + 2] = mapVertices[i].z;
mesh.vertices[fCounter] = mapVertices[i].x;
mesh.vertices[fCounter + 1] = mapVertices[i].y;
mesh.vertices[fCounter + 2] = mapVertices[i].z;
fCounter += 3;
}
@@ -1068,9 +1068,9 @@ Model LoadCubicmap(Image cubicmap)
// Move normals data
for (int i = 0; i < nCounter; i++)
{
vData.normals[fCounter] = mapNormals[i].x;
vData.normals[fCounter + 1] = mapNormals[i].y;
vData.normals[fCounter + 2] = mapNormals[i].z;
mesh.normals[fCounter] = mapNormals[i].x;
mesh.normals[fCounter + 1] = mapNormals[i].y;
mesh.normals[fCounter + 2] = mapNormals[i].z;
fCounter += 3;
}
@@ -1079,8 +1079,8 @@ Model LoadCubicmap(Image cubicmap)
// Move texcoords data
for (int i = 0; i < tcCounter; i++)
{
vData.texcoords[fCounter] = mapTexcoords[i].x;
vData.texcoords[fCounter + 1] = mapTexcoords[i].y;
mesh.texcoords[fCounter] = mapTexcoords[i].x;
mesh.texcoords[fCounter + 1] = mapTexcoords[i].y;
fCounter += 2;
}
@@ -1090,18 +1090,18 @@ Model LoadCubicmap(Image cubicmap)
free(cubicmapPixels);
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
// NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
Model model = rlglLoadModel(vData);
Model model = rlglLoadModel(mesh);
// Now that vertex data is uploaded to GPU, we can free arrays
// NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
if (rlGetVersion() != OPENGL_11)
{
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
free(mesh.vertices);
free(mesh.texcoords);
free(mesh.normals);
free(mesh.colors);
}
return model;
@@ -1147,7 +1147,7 @@ void SetModelTexture(Model *model, Texture2D texture)
void DrawModel(Model model, Vector3 position, float scale, Color tint)
{
Vector3 vScale = { scale, scale, scale };
Vector3 rotationAxis = { 0, 0, 0 };
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
DrawModelEx(model, position, 0.0f, rotationAxis, vScale, tint);
}
@@ -1163,7 +1163,7 @@ void DrawModelEx(Model model, Vector3 position, float rotationAngle, Vector3 rot
void DrawModelWires(Model model, Vector3 position, float scale, Color color)
{
Vector3 vScale = { scale, scale, scale };
Vector3 rotationAxis = { 0, 0, 0 };
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
rlglDrawModel(model, position, 0.0f, rotationAxis, vScale, color, true);
}
@@ -1188,7 +1188,7 @@ void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size,
//Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 };
// NOTE: Billboard locked to axis-Y
Vector3 up = { 0, 1, 0 };
Vector3 up = { 0.0f, 1.0f, 0.0f };
/*
a-------b
| |
@@ -1336,18 +1336,28 @@ bool CheckCollisionBoxSphere(Vector3 minBBox, Vector3 maxBBox, Vector3 centerSph
return collision;
}
// Detect collision between ray and box
// Detect collision between ray and sphere
bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius)
{
bool collision = false;
// TODO: implement collision...
return collision;
}
// Detect collision between ray and bounding box
bool CheckCollisionRayBox(Ray ray, Vector3 minBBox, Vector3 maxBBox)
{
bool collision = false;
float t[8];
t[0] = (minBBox.x - ray.position.x) / ray.direction.x;
t[1] = (maxBBox.x - ray.position.x) / ray.direction.x;
t[2] = (minBBox.y - ray.position.y) / ray.direction.y;
t[3] = (maxBBox.y - ray.position.y) / ray.direction.y;
t[4] = (minBBox.z - ray.position.z) / ray.direction.z;
t[5] = (maxBBox.z - ray.position.z) / ray.direction.z;
t[0] = (minBBox.x - ray.position.x)/ray.direction.x;
t[1] = (maxBBox.x - ray.position.x)/ray.direction.x;
t[2] = (minBBox.y - ray.position.y)/ray.direction.y;
t[3] = (maxBBox.y - ray.position.y)/ray.direction.y;
t[4] = (minBBox.z - ray.position.z)/ray.direction.z;
t[5] = (maxBBox.z - ray.position.z)/ray.direction.z;
t[6] = fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
t[7] = fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
@@ -1359,6 +1369,32 @@ bool CheckCollisionRayBox(Ray ray, Vector3 minBBox, Vector3 maxBBox)
// TODO: Useful function to check collision area?
//BoundingBox GetCollisionArea(BoundingBox box1, BoundingBox box2)
// Calculate mesh bounding box limits
BoundingBox CalculateBoundingBox(Mesh mesh)
{
// Get min and max vertex to construct bounds (AABB)
Vector3 minVertex = mesh.vertices[0];
Vector3 maxVertex = mesh.vertices[0];
for (int i = 1; i < mesh.vertexCount; i++)
{
// TODO: Compare min and max with previous vertex
//minVertex = Vector3.Min(minVertex, mesh.vertices[i]);
//maxVertex = Vector3.Max(maxVertex, mesh.vertices[i]);
}
// NOTE: For OBB, transform mesh by model transform matrix
//minVertex = VectorTransform(meshMin, mesh.transform);
//maxVertex = VectorTransform(meshMax, mesh.transform);
// Create the bounding box
BoundingBox box;
box.min = minVertex;
box.max = maxVertex;
return box;
}
// Detect and resolve cubicmap collisions
// NOTE: player position (or camera) is modified inside this function
Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius)
@@ -1366,7 +1402,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
Color *cubicmapPixels = GetImageData(cubicmap);
// Detect the cell where the player is located
Vector3 impactDirection = { 0, 0, 0 };
Vector3 impactDirection = { 0.0f, 0.0f, 0.0f };
int locationCellX = 0;
int locationCellY = 0;
@@ -1389,7 +1425,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
{
playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1405,7 +1441,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
{
playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1421,7 +1457,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
{
playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1437,7 +1473,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
{
playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1452,7 +1488,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius)
{
playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 0};
impactDirection = (Vector3){ 1.0f, 0.0f, 0.0f };
}
}
}
@@ -1464,7 +1500,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius)
{
playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 1, 0, 0};
impactDirection = (Vector3){ 1.0f, 0.0f, 0.0f };
}
}
}
@@ -1476,7 +1512,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius)
{
playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 0, 0, 1};
impactDirection = (Vector3){ 0.0f, 0.0f, 1.0f };
}
}
}
@@ -1488,7 +1524,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius)
{
playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius);
impactDirection = (Vector3) { 0, 0, 1};
impactDirection = (Vector3){ 0.0f, 0.0f, 1.0f };
}
}
}
@@ -1512,7 +1548,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius / 3) &&
((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius / 3))
{
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1535,7 +1571,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius / 3) &&
((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius / 3))
{
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1558,7 +1594,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius / 3) &&
((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius / 3))
{
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1581,7 +1617,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius / 3) &&
((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius / 3))
{
impactDirection = (Vector3) { 1, 0, 1};
impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f };
}
}
}
@@ -1591,13 +1627,13 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
// Floor collision
if (playerPosition->y <= radius)
{
playerPosition->y = radius + 0.01;
playerPosition->y = radius + 0.01f;
impactDirection = (Vector3) { impactDirection.x, 1, impactDirection.z};
}
// Roof collision
else if (playerPosition->y >= 1.5 - radius)
else if (playerPosition->y >= (1.5f - radius))
{
playerPosition->y = (1.5 - radius) - 0.01;
playerPosition->y = (1.5f - radius) - 0.01f;
impactDirection = (Vector3) { impactDirection.x, 1, impactDirection.z};
}
@@ -1617,9 +1653,9 @@ static float GetHeightValue(Color pixel)
}
// Load OBJ mesh data
static VertexData LoadOBJ(const char *fileName)
static Mesh LoadOBJ(const char *fileName)
{
VertexData vData = { 0 };
Mesh mesh = { 0 };
char dataType;
char comments[200];
@@ -1636,7 +1672,7 @@ static VertexData LoadOBJ(const char *fileName)
if (objFile == NULL)
{
TraceLog(WARNING, "[%s] OBJ file could not be opened", fileName);
return vData;
return mesh;
}
// First reading pass: Get numVertex, numNormals, numTexCoords, numTriangles
@@ -1747,15 +1783,15 @@ static VertexData LoadOBJ(const char *fileName)
}
// At this point all vertex data (v, vt, vn) has been gathered on midVertices, midTexCoords, midNormals
// Now we can organize that data into our VertexData struct
// Now we can organize that data into our Mesh struct
vData.vertexCount = numTriangles*3;
mesh.vertexCount = numTriangles*3;
// Additional arrays to store vertex data as floats
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char));
mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float));
mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float));
mesh.colors = (unsigned char *)malloc(mesh.vertexCount*4*sizeof(unsigned char));
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float
@@ -1783,32 +1819,32 @@ static VertexData LoadOBJ(const char *fileName)
else if (numNormals == 0) fscanf(objFile, "%i/%i %i/%i %i/%i", &vNum[0], &vtNum[0], &vNum[1], &vtNum[1], &vNum[2], &vtNum[2]);
else fscanf(objFile, "%i/%i/%i %i/%i/%i %i/%i/%i", &vNum[0], &vtNum[0], &vnNum[0], &vNum[1], &vtNum[1], &vnNum[1], &vNum[2], &vtNum[2], &vnNum[2]);
vData.vertices[vCounter] = midVertices[vNum[0]-1].x;
vData.vertices[vCounter + 1] = midVertices[vNum[0]-1].y;
vData.vertices[vCounter + 2] = midVertices[vNum[0]-1].z;
mesh.vertices[vCounter] = midVertices[vNum[0]-1].x;
mesh.vertices[vCounter + 1] = midVertices[vNum[0]-1].y;
mesh.vertices[vCounter + 2] = midVertices[vNum[0]-1].z;
vCounter += 3;
vData.vertices[vCounter] = midVertices[vNum[1]-1].x;
vData.vertices[vCounter + 1] = midVertices[vNum[1]-1].y;
vData.vertices[vCounter + 2] = midVertices[vNum[1]-1].z;
mesh.vertices[vCounter] = midVertices[vNum[1]-1].x;
mesh.vertices[vCounter + 1] = midVertices[vNum[1]-1].y;
mesh.vertices[vCounter + 2] = midVertices[vNum[1]-1].z;
vCounter += 3;
vData.vertices[vCounter] = midVertices[vNum[2]-1].x;
vData.vertices[vCounter + 1] = midVertices[vNum[2]-1].y;
vData.vertices[vCounter + 2] = midVertices[vNum[2]-1].z;
mesh.vertices[vCounter] = midVertices[vNum[2]-1].x;
mesh.vertices[vCounter + 1] = midVertices[vNum[2]-1].y;
mesh.vertices[vCounter + 2] = midVertices[vNum[2]-1].z;
vCounter += 3;
if (numNormals > 0)
{
vData.normals[nCounter] = midNormals[vnNum[0]-1].x;
vData.normals[nCounter + 1] = midNormals[vnNum[0]-1].y;
vData.normals[nCounter + 2] = midNormals[vnNum[0]-1].z;
mesh.normals[nCounter] = midNormals[vnNum[0]-1].x;
mesh.normals[nCounter + 1] = midNormals[vnNum[0]-1].y;
mesh.normals[nCounter + 2] = midNormals[vnNum[0]-1].z;
nCounter += 3;
vData.normals[nCounter] = midNormals[vnNum[1]-1].x;
vData.normals[nCounter + 1] = midNormals[vnNum[1]-1].y;
vData.normals[nCounter + 2] = midNormals[vnNum[1]-1].z;
mesh.normals[nCounter] = midNormals[vnNum[1]-1].x;
mesh.normals[nCounter + 1] = midNormals[vnNum[1]-1].y;
mesh.normals[nCounter + 2] = midNormals[vnNum[1]-1].z;
nCounter += 3;
vData.normals[nCounter] = midNormals[vnNum[2]-1].x;
vData.normals[nCounter + 1] = midNormals[vnNum[2]-1].y;
vData.normals[nCounter + 2] = midNormals[vnNum[2]-1].z;
mesh.normals[nCounter] = midNormals[vnNum[2]-1].x;
mesh.normals[nCounter + 1] = midNormals[vnNum[2]-1].y;
mesh.normals[nCounter + 2] = midNormals[vnNum[2]-1].z;
nCounter += 3;
}
else
@@ -1817,17 +1853,17 @@ static VertexData LoadOBJ(const char *fileName)
Vector3 norm = VectorCrossProduct(VectorSubtract(midVertices[vNum[1]-1], midVertices[vNum[0]-1]), VectorSubtract(midVertices[vNum[2]-1], midVertices[vNum[0]-1]));
VectorNormalize(&norm);
vData.normals[nCounter] = norm.x;
vData.normals[nCounter + 1] = norm.y;
vData.normals[nCounter + 2] = norm.z;
mesh.normals[nCounter] = norm.x;
mesh.normals[nCounter + 1] = norm.y;
mesh.normals[nCounter + 2] = norm.z;
nCounter += 3;
vData.normals[nCounter] = norm.x;
vData.normals[nCounter + 1] = norm.y;
vData.normals[nCounter + 2] = norm.z;
mesh.normals[nCounter] = norm.x;
mesh.normals[nCounter + 1] = norm.y;
mesh.normals[nCounter + 2] = norm.z;
nCounter += 3;
vData.normals[nCounter] = norm.x;
vData.normals[nCounter + 1] = norm.y;
vData.normals[nCounter + 2] = norm.z;
mesh.normals[nCounter] = norm.x;
mesh.normals[nCounter + 1] = norm.y;
mesh.normals[nCounter + 2] = norm.z;
nCounter += 3;
}
@@ -1835,14 +1871,14 @@ static VertexData LoadOBJ(const char *fileName)
{
// NOTE: If using negative texture coordinates with a texture filter of GL_CLAMP_TO_EDGE doesn't work!
// NOTE: Texture coordinates are Y flipped upside-down
vData.texcoords[tcCounter] = midTexCoords[vtNum[0]-1].x;
vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[0]-1].y;
mesh.texcoords[tcCounter] = midTexCoords[vtNum[0]-1].x;
mesh.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[0]-1].y;
tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[1]-1].x;
vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[1]-1].y;
mesh.texcoords[tcCounter] = midTexCoords[vtNum[1]-1].x;
mesh.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[1]-1].y;
tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[2]-1].x;
vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[2]-1].y;
mesh.texcoords[tcCounter] = midTexCoords[vtNum[2]-1].x;
mesh.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[2]-1].y;
tcCounter += 2;
}
} break;
@@ -1853,19 +1889,19 @@ static VertexData LoadOBJ(const char *fileName)
fclose(objFile);
// Security check, just in case no normals or no texcoords defined in OBJ
if (numTexCoords == 0) for (int i = 0; i < (2*vData.vertexCount); i++) vData.texcoords[i] = 0.0f;
if (numTexCoords == 0) for (int i = 0; i < (2*mesh.vertexCount); i++) mesh.texcoords[i] = 0.0f;
// NOTE: We set all vertex colors to white
// NOTE: Not used any more... just one plain color defined at DrawModel()
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
for (int i = 0; i < (4*mesh.vertexCount); i++) mesh.colors[i] = 255;
// Now we can free temp mid* arrays
free(midVertices);
free(midNormals);
free(midTexCoords);
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
// NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
TraceLog(INFO, "[%s] Model loaded successfully in RAM (CPU)", fileName);
return vData;
return mesh;
}

View File

@@ -320,7 +320,7 @@ int GuiComboBox(Rectangle bounds, int comboNum, char **comboText, int comboActiv
{
ComboBoxState comboBoxState = COMBOBOX_UNACTIVE;
Rectangle comboBoxButton = bounds;
Rectangle click = { bounds.x + bounds.width + style[COMBOBOX_PADDING], bounds.y, style[COMBOBOX_BUTTON_WIDTH], bounds.height };
Rectangle click = { bounds.x + bounds.width + style[COMBOBOX_PADDING], bounds.y, style[COMBOBOX_BUTTON_WIDTH], style[COMBOBOX_BUTTON_HEIGHT] };
Vector2 mousePoint = GetMousePosition();
int textHeight = GetDefaultFont().size;
@@ -691,7 +691,7 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
}
else if (!CheckCollisionPointRec(mousePoint, labelBoxBound)) buttonSide = 0;
if(IsMouseButtonUp(MOUSE_LEFT_BUTTON))
if (IsMouseButtonUp(MOUSE_LEFT_BUTTON))
{
valueSpeed = false;
framesCounter = 0;
@@ -710,13 +710,13 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_DEFAULT_BUTTON_BORDER_COLOR]));
DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_LABEL_BORDER_COLOR]));
DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_LABEL_INSIDE_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_TEXT_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_TEXT_COLOR]));
} break;
case SPINNER_HOVER:
{
@@ -728,8 +728,8 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_DEFAULT_BUTTON_BORDER_COLOR]));
DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
}
else if (buttonSide == 2)
{
@@ -739,14 +739,14 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_HOVER_BUTTON_BORDER_COLOR]));
DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_HOVER_BUTTON_INSIDE_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR]));
}
DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_LABEL_BORDER_COLOR]));
DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_LABEL_INSIDE_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_TEXT_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_HOVER_TEXT_COLOR]));
} break;
case SPINNER_PRESSED:
{
@@ -758,8 +758,8 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_DEFAULT_BUTTON_BORDER_COLOR]));
DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
}
else if (buttonSide == 2)
{
@@ -769,16 +769,18 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_PRESSED_BUTTON_BORDER_COLOR]));
DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_PRESSED_BUTTON_INSIDE_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR]));
DrawText(FormatText("-"), leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText(FormatText("+"), style[GLOBAL_TEXT_FONTSIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR]));
DrawText(FormatText("+"), rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText(FormatText("-"), style[GLOBAL_TEXT_FONTSIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR]));
}
DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_LABEL_BORDER_COLOR]));
DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_LABEL_INSIDE_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - textHeight/2), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_TEXT_COLOR]));
DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[GLOBAL_TEXT_FONTSIZE]/2)), style[GLOBAL_TEXT_FONTSIZE], GetColor(style[SPINNER_PRESSED_TEXT_COLOR]));
} break;
default: break;
}
return value;
}
@@ -843,12 +845,12 @@ char *GuiTextBox(Rectangle bounds, char *text)
{
if (text[i] == '\0') break;
DrawText(FormatText("%c", text[i]), initPos, bounds.y + 5, style[TEXTBOX_TEXT_FONTSIZE], GetColor(style[TEXTBOX_TEXT_COLOR]));
DrawText(FormatText("%c", text[i]), initPos, bounds.y + style[TEXTBOX_TEXT_FONTSIZE], style[TEXTBOX_TEXT_FONTSIZE], GetColor(style[TEXTBOX_TEXT_COLOR]));
initPos += ((GetDefaultFont().charRecs[(int)text[i] - 32].width + 2));
}
if ((framesCounter/20)%2 && CheckCollisionPointRec(mousePoint, bounds)) DrawLine(initPos + 2, bounds.y, initPos + 2, bounds.y + 10 + 10, GetColor(style[TEXTBOX_LINE_COLOR]));
if ((framesCounter/20)%2 && CheckCollisionPointRec(mousePoint, bounds)) DrawLine(initPos + 2, bounds.y + 5, initPos + 2, bounds.y + 10 + 15, GetColor(style[TEXTBOX_LINE_COLOR]));
//--------------------------------------------------------------------
return text;

View File

@@ -308,17 +308,27 @@ typedef struct Camera {
Vector3 up;
} Camera;
// Bounding box type
typedef struct BoundingBox {
Vector3 min;
Vector3 max;
} BoundingBox;
// Vertex data definning a mesh
// NOTE: If using OpenGL 1.1, data loaded in CPU; if OpenGL 3.3+ data loaded in GPU (vaoId)
typedef struct VertexData {
int vertexCount;
float *vertices; // 3 components per vertex
float *texcoords; // 2 components per vertex
float *normals; // 3 components per vertex
unsigned char *colors; // 4 components per vertex
unsigned int vaoId;
unsigned int vboId[4];
} VertexData;
typedef struct Mesh {
int vertexCount; // num vertices
float *vertices; // vertex position (XYZ - 3 components per vertex)
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex)
float *texcoords2; // vertex second texture coordinates (useful for lightmaps)
float *normals; // vertex normals (XYZ - 3 components per vertex)
float *tangents; // vertex tangents (XYZ - 3 components per vertex)
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex)
BoundingBox bounds; // mesh limits defined by min and max points
unsigned int vaoId; // OpenGL Vertex Array Object id
unsigned int vboId[6]; // OpenGL Vertex Buffer Objects id (6 types of vertex data)
} Mesh;
// Shader type (generic shader)
typedef struct Shader {
@@ -336,8 +346,8 @@ typedef struct Shader {
int colorLoc; // Color attibute location point (vertex shader)
// Uniforms
int projectionLoc; // Projection matrix uniform location point (vertex shader)
int modelviewLoc; // ModelView matrix uniform location point (vertex shader)
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
int modelLoc; // Model transformation matrix uniform location point (vertex shader)
int viewLoc; // View transformation matrix uniform location point (vertex shader)
int tintColorLoc; // Color uniform location point (fragment shader)
@@ -349,7 +359,7 @@ typedef struct Shader {
// 3d Model type
typedef struct Model {
VertexData mesh;
Mesh mesh;
Matrix transform;
Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
Shader shader;
@@ -742,7 +752,7 @@ void DrawGizmo(Vector3 position);
// Model 3d Loading and Drawing Functions (Module: models)
//------------------------------------------------------------------------------------
Model LoadModel(const char *fileName); // Load a 3d model (.OBJ)
Model LoadModelEx(VertexData data); // Load a 3d model (from vertex data)
Model LoadModelEx(Mesh data); // Load a 3d model (from vertex data)
//Model LoadModelFromRES(const char *rresName, int resId); // TODO: Load a 3d model from rRES file (raylib Resource)
Model LoadHeightmap(Image heightmap, float maxHeight); // Load a heightmap image as a 3d model
Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)

View File

@@ -821,10 +821,10 @@ void rlDeleteBuffers(unsigned int id)
void rlClearColor(byte r, byte g, byte b, byte a)
{
// Color values clamp to 0.0f(0) and 1.0f(255)
float cr = (float)r / 255;
float cg = (float)g / 255;
float cb = (float)b / 255;
float ca = (float)a / 255;
float cr = (float)r/255;
float cg = (float)g/255;
float cb = (float)b/255;
float ca = (float)a/255;
glClearColor(cr, cg, cb, ca);
}
@@ -1100,24 +1100,24 @@ void rlglInitPostpro(void)
if (postproFbo.id > 0)
{
// Create a simple quad model to render fbo texture
VertexData quadData;
Mesh quad;
quadData.vertexCount = 6;
quad.vertexCount = 6;
float w = screenWidth;
float h = screenHeight;
float w = (float)screenWidth;
float h = (float)screenHeight;
float quadPositions[6*3] = { w, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, h, 0.0, 0, h, 0.0, w, h, 0.0, w, 0.0, 0.0 };
float quadTexcoords[6*2] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 };
float quadNormals[6*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 };
float quadPositions[6*3] = { w, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, h, 0.0f, 0.0f, h, 0.0f, w, h, 0.0f, w, 0.0f, 0.0f };
float quadTexcoords[6*2] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
float quadNormals[6*3] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f };
unsigned char quadColors[6*4] = { 255 };
quadData.vertices = quadPositions;
quadData.texcoords = quadTexcoords;
quadData.normals = quadNormals;
quadData.colors = quadColors;
quad.vertices = quadPositions;
quad.texcoords = quadTexcoords;
quad.normals = quadNormals;
quad.colors = quadColors;
postproQuad = rlglLoadModel(quadData);
postproQuad = rlglLoadModel(quad);
// NOTE: postproFbo.colorTextureId must be assigned to postproQuad model shader
}
@@ -1296,8 +1296,9 @@ void rlglDraw(void)
{
glUseProgram(currentShader.id);
glUniformMatrix4fv(currentShader.projectionLoc, 1, false, MatrixToFloat(projection));
glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, MatrixToFloat(modelview));
Matrix matMVP = MatrixMultiply(modelview, projection); // Create modelview-projection matrix
glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP));
glUniform1i(currentShader.mapDiffuseLoc, 0);
}
@@ -1520,14 +1521,14 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r
Matrix matModelView = MatrixMultiply(matModel, matView); // Transform to camera-space coordinates
// Calculate model-view-projection matrix (MVP)
//Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates
Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates
// NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
// TODO: Reduce number of matrices passed to shaders, use only matMVP
glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel));
glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView));
glUniformMatrix4fv(model.shader.projectionLoc, 1, false, MatrixToFloat(matProjection));
glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, MatrixToFloat(matModelView));
glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
// Apply color tinting to model
// NOTE: Just update one uniform on fragment shader
@@ -1666,7 +1667,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height)
// NOTE: Using global variables: screenWidth, screenHeight
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view)
{
Vector3 result = { 0, 0, 0 }; // Object coordinates
Vector3 result = { 0.0f, 0.0f, 0.0f }; // Object coordinates
//GLint viewport[4];
//glGetIntegerv(GL_VIEWPORT, viewport); // Not available on OpenGL ES 2.0
@@ -1697,11 +1698,11 @@ Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view)
quat.x = ((source.x - (float)x)/(float)width)*2.0f - 1.0f;
quat.y = ((source.y - (float)y)/(float)height)*2.0f - 1.0f;
quat.z = source.z*2.0f - 1.0f;
quat.w = 1.0;
quat.w = 1.0f;
QuaternionTransform(&quat, modelviewprojection);
if (quat.w != 0.0)
if (quat.w != 0.0f)
{
quat.x /= quat.w;
quat.y /= quat.w;
@@ -1981,7 +1982,7 @@ void rlglGenerateMipmaps(Texture2D texture)
}
// Load vertex data into a VAO (if supported) and VBO
Model rlglLoadModel(VertexData mesh)
Model rlglLoadModel(Mesh mesh)
{
Model model;
@@ -2170,7 +2171,7 @@ void *rlglReadTexturePixels(Texture2D texture)
// Render texture to fbo
glBindFramebuffer(GL_FRAMEBUFFER, fbo.id);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height);
@@ -2188,7 +2189,7 @@ void *rlglReadTexturePixels(Texture2D texture)
quad.transform = MatrixIdentity();
quad.shader = simpleShader;
DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE);
DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE);
pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char));
@@ -2247,13 +2248,13 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
shader.colorLoc = -1;
// Get handles to GLSL uniform locations (vertex shader)
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix");
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
// Get handles to GLSL uniform locations (fragment shader)
shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
shader.mapNormalLoc = -1; // It can be set later
shader.mapSpecularLoc = -1; // It can be set later
@@ -2738,40 +2739,39 @@ static Shader LoadDefaultShader(void)
"in vec2 vertexTexCoord; \n"
"in vec4 vertexColor; \n"
"out vec2 fragTexCoord; \n"
"out vec4 tintColor; \n"
"out vec4 fragTintColor; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
char vShaderStr[] = "#version 100 \n"
"attribute vec3 vertexPosition; \n"
"attribute vec2 vertexTexCoord; \n"
"attribute vec4 vertexColor; \n"
"varying vec2 fragTexCoord; \n"
"varying vec4 tintColor; \n"
"varying vec4 fragTintColor; \n"
#endif
"uniform mat4 projectionMatrix; \n"
"uniform mat4 modelviewMatrix; \n"
"uniform mat4 mvpMatrix; \n"
"void main() \n"
"{ \n"
" fragTexCoord = vertexTexCoord; \n"
" tintColor = vertexColor; \n"
" gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n"
" fragTintColor = vertexColor; \n"
" gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n"
"} \n";
// Fragment shader directly defined, no external file required
#if defined(GRAPHICS_API_OPENGL_33)
char fShaderStr[] = "#version 330 \n"
"in vec2 fragTexCoord; \n"
"in vec4 tintColor; \n"
"in vec4 fragTintColor; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
char fShaderStr[] = "#version 100 \n"
"precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
"varying vec2 fragTexCoord; \n"
"varying vec4 tintColor; \n"
"varying vec4 fragTintColor; \n"
#endif
"uniform sampler2D texture0; \n"
"void main() \n"
"{ \n"
" vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
" gl_FragColor = texelColor*tintColor; \n"
" gl_FragColor = texelColor*fragTintColor; \n"
"} \n";
shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
@@ -2788,10 +2788,10 @@ static Shader LoadDefaultShader(void)
shader.normalLoc = -1;
// Get handles to GLSL uniform locations (vertex shader)
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix");
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
// Get handles to GLSL uniform locations (fragment shader)
shader.tintColorLoc = -1;
@@ -2831,12 +2831,11 @@ static Shader LoadSimpleShader(void)
"attribute vec3 vertexNormal; \n"
"varying vec2 fragTexCoord; \n"
#endif
"uniform mat4 projectionMatrix; \n"
"uniform mat4 modelviewMatrix; \n"
"uniform mat4 mvpMatrix; \n"
"void main() \n"
"{ \n"
" fragTexCoord = vertexTexCoord; \n"
" gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n"
" gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n"
"} \n";
// Fragment shader directly defined, no external file required
@@ -2849,11 +2848,11 @@ static Shader LoadSimpleShader(void)
"varying vec2 fragTexCoord; \n"
#endif
"uniform sampler2D texture0; \n"
"uniform vec4 tintColor; \n"
"uniform vec4 fragTintColor; \n"
"void main() \n"
"{ \n"
" vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
" gl_FragColor = texelColor*tintColor; \n"
" gl_FragColor = texelColor*fragTintColor; \n"
"} \n";
shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
@@ -2870,13 +2869,13 @@ static Shader LoadSimpleShader(void)
shader.colorLoc = -1;
// Get handles to GLSL uniform locations (vertex shader)
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix");
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
// Get handles to GLSL uniform locations (fragment shader)
shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
shader.mapNormalLoc = -1; // It can be set later
shader.mapSpecularLoc = -1; // It can be set later
@@ -3240,19 +3239,19 @@ static pixel *GenNextMipmap(pixel *srcData, int srcWidth, int srcHeight)
int x2, y2;
pixel prow, pcol;
int width = srcWidth / 2;
int height = srcHeight / 2;
int width = srcWidth/2;
int height = srcHeight/2;
pixel *mipmap = (pixel *)malloc(width*height*sizeof(pixel));
// Scaling algorithm works perfectly (box-filter)
for (int y = 0; y < height; y++)
{
y2 = 2 * y;
y2 = 2*y;
for (int x = 0; x < width; x++)
{
x2 = 2 * x;
x2 = 2*x;
prow.r = (srcData[y2*srcWidth + x2].r + srcData[y2*srcWidth + x2 + 1].r)/2;
prow.g = (srcData[y2*srcWidth + x2].g + srcData[y2*srcWidth + x2 + 1].g)/2;

View File

@@ -131,17 +131,22 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
} TextureFormat;
// VertexData type
// Mesh with vertex data type
// NOTE: If using OpenGL 1.1, data loaded in CPU; if OpenGL 3.3+ data loaded in GPU (vaoId)
typedef struct VertexData {
int vertexCount;
float *vertices; // 3 components per vertex
float *texcoords; // 2 components per vertex
float *normals; // 3 components per vertex
unsigned char *colors;
unsigned int vaoId;
unsigned int vboId[4];
} VertexData;
typedef struct Mesh {
int vertexCount; // num vertices
float *vertices; // vertex position (XYZ - 3 components per vertex)
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex)
float *texcoords2; // vertex second texture coordinates (useful for lightmaps)
float *normals; // vertex normals (XYZ - 3 components per vertex)
float *tangents; // vertex tangents (XYZ - 3 components per vertex)
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex)
BoundingBox bounds; // mesh limits defined by min and max points
unsigned int vaoId; // OpenGL Vertex Array Object id
unsigned int vboId[6]; // OpenGL Vertex Buffer Objects id (6 types of vertex data)
} Mesh;
// Shader type
typedef struct Shader {
@@ -159,8 +164,8 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
int colorLoc; // Color attibute location point (vertex shader)
// Uniforms
int projectionLoc; // Projection matrix uniform location point (vertex shader)
int modelviewLoc; // ModelView matrix uniform location point (vertex shader)
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
int modelLoc; // Model transformation matrix uniform location point (vertex shader)
int viewLoc; // View transformation matrix uniform location point (vertex shader)
int tintColorLoc; // Color uniform location point (fragment shader)
@@ -179,7 +184,7 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
// 3d Model type
typedef struct Model {
VertexData mesh;
Mesh mesh;
Matrix transform;
Texture2D texture;
Shader shader;
@@ -254,7 +259,7 @@ void rlglGenerateMipmaps(Texture2D texture); // Gene
void rlglInitPostpro(void); // Initialize postprocessing system
void rlglDrawPostpro(void); // Draw with postprocessing shader
Model rlglLoadModel(VertexData mesh); // Upload vertex data into GPU and provided VAO/VBO ids
Model rlglLoadModel(Mesh mesh); // Upload vertex data into GPU and provided VAO/VBO ids
void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color color, bool wires);
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates

View File

@@ -269,14 +269,14 @@ SpriteFont LoadSpriteFont(const char *fileName)
spriteFont.texture = LoadTextureFromImage(image); // Convert loaded image to OpenGL texture
spriteFont.size = spriteFont.charRecs[0].height;
defaultFont.charOffsets = (Vector2 *)malloc(defaultFont.numChars*sizeof(Vector2));
defaultFont.charAdvanceX = (int *)malloc(defaultFont.numChars*sizeof(int));
spriteFont.charOffsets = (Vector2 *)malloc(spriteFont.numChars*sizeof(Vector2));
spriteFont.charAdvanceX = (int *)malloc(spriteFont.numChars*sizeof(int));
for (int i = 0; i < defaultFont.numChars; i++)
for (int i = 0; i < spriteFont.numChars; i++)
{
// NOTE: On image based fonts (XNA style), character offsets and xAdvance are not required (set to 0)
defaultFont.charOffsets[i] = (Vector2){ 0.0f, 0.0f };
defaultFont.charAdvanceX[i] = 0;
spriteFont.charOffsets[i] = (Vector2){ 0.0f, 0.0f };
spriteFont.charAdvanceX[i] = 0;
}
}
else
@@ -627,7 +627,7 @@ static SpriteFont LoadRBMF(const char *fileName)
char charsDataType; // Char data type provided
} rbmfInfoHeader;
SpriteFont spriteFont;
SpriteFont spriteFont = { 0 };
rbmfInfoHeader rbmfHeader;
unsigned int *rbmfFileData = NULL;
@@ -695,6 +695,8 @@ static SpriteFont LoadRBMF(const char *fileName)
// Get characters data using rbmfCharWidthData, rbmfHeader.charHeight, charsDivisor, rbmfHeader.numChars
spriteFont.charValues = (int *)malloc(spriteFont.numChars*sizeof(int));
spriteFont.charRecs = (Rectangle *)malloc(spriteFont.numChars*sizeof(Rectangle));
spriteFont.charOffsets = (Vector2 *)malloc(spriteFont.numChars*sizeof(Vector2));
spriteFont.charAdvanceX = (int *)malloc(spriteFont.numChars*sizeof(int));
int currentLine = 0;
int currentPosX = charsDivisor;
@@ -709,6 +711,10 @@ static SpriteFont LoadRBMF(const char *fileName)
spriteFont.charRecs[i].width = (int)rbmfCharWidthData[i];
spriteFont.charRecs[i].height = (int)rbmfHeader.charHeight;
// NOTE: On image based fonts (XNA style), character offsets and xAdvance are not required (set to 0)
spriteFont.charOffsets[i] = (Vector2){ 0.0f, 0.0f };
spriteFont.charAdvanceX[i] = 0;
testPosX += (spriteFont.charRecs[i].width + charsDivisor);
if (testPosX > spriteFont.texture.width)