diff options
| author | raysan5 <[email protected]> | 2021-07-29 21:57:50 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-07-29 21:57:50 +0200 |
| commit | 8b7f43f89b88c75f7353fe85f7cb6465ad6be7b5 (patch) | |
| tree | 2b3be572cedb63e66a51a83d42e6708bd354195b /examples | |
| parent | 58e9a0894f65a50004e637f7db72bd12da809cd9 (diff) | |
| download | raylib-8b7f43f89b88c75f7353fe85f7cb6465ad6be7b5.tar.gz raylib-8b7f43f89b88c75f7353fe85f7cb6465ad6be7b5.zip | |
WARNING: BREAKING CHANGE: rlgl complete decoupling from raylib -WIP-
rlgl has been redesigned to avoid any dependency to `raylib` or `raymath`, all functions using some of those libs have been reviewed.
- REMOVED: `Texture2D`, `Shader` structs dependency
- REMOVED: `Vector3`, `Matrix` structs dependency
- REMOVED: raymath functions dependency, all required math is implemented in rlgl
- ADDED: `rlMatrix` custom rlgl type
- ADDED: `utils.c`: `rlMatrixFromMatrix()` and `rlMatrixToMatrix()` for a safe conversion between raylib<->rlgl matrix types
- ADDED: `rl` prefix to all `rlgl` structs
- Other small tweaks here and there
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/others/rlgl_standalone.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/examples/others/rlgl_standalone.c b/examples/others/rlgl_standalone.c index 0a5cb509..a069d029 100644 --- a/examples/others/rlgl_standalone.c +++ b/examples/others/rlgl_standalone.c @@ -50,8 +50,11 @@ #define RLGL_IMPLEMENTATION #define RLGL_STANDALONE -#define RLGL_SUPPORT_TRACELOG -#include "rlgl.h" // OpenGL 1.1 immediate-mode style coding +#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2 + +#define RAYMATH_STANDALONE +#define RAYMATH_HEADER_ONLY +#include "raymath.h" // Vector3, Quaternion and Matrix functionality #if defined(__EMSCRIPTEN__) #define GLFW_INCLUDE_ES2 @@ -65,6 +68,9 @@ #define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) #define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray +//---------------------------------------------------------------------------------- +// Structures Definition +//---------------------------------------------------------------------------------- // Color, 4 components, R8G8B8A8 (32bit) typedef struct Color { unsigned char r; // Color red value @@ -73,6 +79,21 @@ typedef struct Color { unsigned char a; // Color alpha value } Color; +#if !defined(RAYMATH_STANDALONE) +// Vector2, 2 components +typedef struct Vector2 { + float x; // Vector x component + float y; // Vector y component +} Vector2; + +// Vector3, 3 components +typedef struct Vector3 { + float x; // Vector x component + float y; // Vector y component + float z; // Vector z component +} Vector3; +#endif + // Camera type, defines a camera position/orientation in 3d space typedef struct Camera { Vector3 position; // Camera position @@ -94,6 +115,24 @@ static void DrawCube(Vector3 position, float width, float height, float length, static void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); static void DrawRectangleV(Vector2 position, Vector2 size, Color color); +// NOTE: We used raymath to get this functionality but it can be implemented here +//static rlMatrix MatrixIdentity(void); +//static rlMatrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); +//static rlMatrix MatrixPerspective(double fovy, double aspect, double near, double far); +//static rlMatrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); + +rlMatrix rlMatrixFromMatrix(Matrix mat) +{ + rlMatrix result = { + mat.m0, mat.m4, mat.m8, mat.m12, // Matrix first row (4 comat.mponents) + mat.m1, mat.m5, mat.m9, mat.m13, // Matrix second row (4 comat.mponents) + mat.m2, mat.m6, mat.m10, mat.m14, // Matrix third row (4 comat.mponents) + mat.m3, mat.m7, mat.m11, mat.m15, // Matrix fourth row (4 comat.mponents) + }; + + return result; +} + //---------------------------------------------------------------------------------- // Main Entry point //---------------------------------------------------------------------------------- @@ -187,8 +226,8 @@ int main(void) Matrix matProj = MatrixPerspective((double)(camera.fovy*DEG2RAD), (double)screenWidth/(double)screenHeight, 0.01, 1000.0); Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); - rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader) - rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader) + rlSetMatrixModelview(rlMatrixFromMatrix(matView)); // Set internal modelview matrix (default shader) + rlSetMatrixProjection(rlMatrixFromMatrix(matProj)); // Set internal projection matrix (default shader) DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE); @@ -205,8 +244,8 @@ int main(void) matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); matView = MatrixIdentity(); - rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader) - rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader) + rlSetMatrixModelview(rlMatrixFromMatrix(matView)); // Set internal modelview matrix (default shader) + rlSetMatrixProjection(rlMatrixFromMatrix(matProj)); // Set internal projection matrix (default shader) #else // Let rlgl generate and multiply matrix internally |
