diff --git a/examples/models/models_first_person_maze.cpp b/examples/models/models_first_person_maze.cpp index fafbe72..80a99aa 100644 --- a/examples/models/models_first_person_maze.cpp +++ b/examples/models/models_first_person_maze.cpp @@ -11,8 +11,6 @@ #include "raylib-cpp.hpp" -#include // Required for: free() - int main(void) { // Initialization @@ -26,13 +24,13 @@ int main(void) raylib::Camera camera({ 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f); raylib::Image imMap("resources/cubicmap.png"); // Load cubicmap image (RAM) - raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM) - raylib::Mesh mesh = raylib::Mesh::Cubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f }); + raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM) + Mesh mesh = raylib::Mesh::Cubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f }); raylib::Model model(mesh); // NOTE: By default each cube is mapped to one part of texture atlas raylib::Texture texture("resources/cubicmap_atlas.png"); // Load map texture - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture + model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture // Get map image data to be used for collision detection Color *mapPixels = imMap.LoadColors(); @@ -96,11 +94,11 @@ int main(void) camera.BeginMode3D(); model.Draw(mapPosition); // Draw maze map - // DrawCubeV(playerPosition, (Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player + // playerPosition.DrawCube((Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player camera.EndMode3D(); - cubicmap.Draw((Vector2){ GetScreenWidth() - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE); + cubicmap.Draw((Vector2){ static_cast(GetScreenWidth() - cubicmap.width*4 - 20), 20 }, 0.0f, 4.0f, WHITE); DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); // Draw player position radar @@ -114,24 +112,10 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- - free(mapPixels); // Unload color array - /** - * TODO: Fix double freeing of Mesh, possibly from UnloadModel() unloading meshes in Model.hpp? - * - * INFO: TEXTURE: [ID 4] Unloaded texture data from VRAM (GPU) - * INFO: VAO: [ID 2] Unloaded vertex data from VRAM (GPU) - * INFO: MODEL: Unloaded model (and meshes) from RAM and VRAM - * double free or corruption (!prev) - */ - mesh.vboId = NULL; // This shouldn't be needed, but currently is. + UnloadImageColors(mapPixels); // Unload color array - //UnloadTexture(cubicmap); // Unload cubicmap texture - //UnloadTexture(texture); // Unload map texture - //UnloadModel(model); // Unload map model - - //CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------------- return 0; } diff --git a/include/Mesh.hpp b/include/Mesh.hpp index 41e86a0..2337857 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -58,68 +58,70 @@ class Mesh : public ::Mesh { /** * Generate polygonal mesh */ - static Mesh Poly(int sides, float radius) { + static ::Mesh Poly(int sides, float radius) { return ::GenMeshPoly(sides, radius); } + /** * Generate plane mesh (with subdivisions) */ - static Mesh Plane(float width, float length, int resX, int resZ) { + static ::Mesh Plane(float width, float length, int resX, int resZ) { return ::GenMeshPlane(width, length, resX, resZ); } /** * Generate cuboid mesh */ - static Mesh Cube(float width, float height, float length) { + static ::Mesh Cube(float width, float height, float length) { return ::GenMeshCube(width, height, length); } + /** * Generate sphere mesh (standard sphere) */ - static Mesh Sphere(float radius, int rings, int slices) { + static ::Mesh Sphere(float radius, int rings, int slices) { return ::GenMeshSphere(radius, rings, slices); } /** * Generate half-sphere mesh (no bottom cap) */ - static Mesh HemiSphere(float radius, int rings, int slices) { + static ::Mesh HemiSphere(float radius, int rings, int slices) { return ::GenMeshHemiSphere(radius, rings, slices); } /** * Generate cylinder mesh */ - static Mesh Cylinder(float radius, float height, int slices) { + static ::Mesh Cylinder(float radius, float height, int slices) { return ::GenMeshCylinder(radius, height, slices); } /** * Generate torus mesh */ - static Mesh Torus(float radius, float size, int radSeg, int sides) { + static ::Mesh Torus(float radius, float size, int radSeg, int sides) { return ::GenMeshTorus(radius, size, radSeg, sides); } /** * Generate trefoil knot mesh */ - static Mesh Knot(float radius, float size, int radSeg, int sides) { + static ::Mesh Knot(float radius, float size, int radSeg, int sides) { return ::GenMeshKnot(radius, size, radSeg, sides); } /** * Generate heightmap mesh from image data */ - static Mesh Heightmap(::Image heightmap, ::Vector3 size) { + static ::Mesh Heightmap(::Image heightmap, ::Vector3 size) { return ::GenMeshHeightmap(heightmap, size); } /** * Generate cubes-based map mesh from image data */ - static Mesh Cubicmap(::Image cubicmap, ::Vector3 cubeSize) { + static ::Mesh Cubicmap(::Image cubicmap, ::Vector3 cubeSize) { return ::GenMeshCubicmap(cubicmap, cubeSize); } diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 9e2ad89..46c894e 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -235,10 +235,12 @@ class Vector3 : public ::Vector3 { ::DrawLine3D(*this, endPos, color); return *this; } + inline Vector3& DrawPoint3D(::Color color) { ::DrawPoint3D(*this, color); return *this; } + inline Vector3& DrawCircle3D( float radius, Vector3 rotationAxis, @@ -252,6 +254,7 @@ class Vector3 : public ::Vector3 { ::DrawCube(*this, width, height, length, color); return *this; } + inline Vector3& DrawCube(::Vector3 size, ::Color color) { ::DrawCubeV(*this, size, color); return *this; @@ -261,6 +264,7 @@ class Vector3 : public ::Vector3 { ::DrawCubeWires(*this, width, height, length, color); return *this; } + inline Vector3& DrawCubeWires(::Vector3 size, ::Color color) { ::DrawCubeWiresV(*this, size, color); return *this;