summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2021-10-15 11:25:28 +0200
committerRay <[email protected]>2021-10-15 11:25:28 +0200
commit226c0e362c6784edf7e86e94624da655d185b259 (patch)
tree69134e53b92f1ee85485742deeb4b018165838e7
parent84edd226127d7594b6667d666a3f46cf597f9013 (diff)
parent2a6bd973bdfe92e9f8506feb766d3351c0802d94 (diff)
downloadraylib-226c0e362c6784edf7e86e94624da655d185b259.tar.gz
raylib-226c0e362c6784edf7e86e94624da655d185b259.zip
Merge branch 'master' of https://github.com/raysan5/raylib
-rw-r--r--SPONSORS.md34
-rw-r--r--examples/README.md18
-rw-r--r--examples/build.zig86
-rw-r--r--examples/models/models_loading_gltf.c33
-rw-r--r--examples/models/models_loading_vox.c135
-rw-r--r--examples/models/models_yaw_pitch_roll.c1
-rw-r--r--src/rmodels.c2
7 files changed, 200 insertions, 109 deletions
diff --git a/SPONSORS.md b/SPONSORS.md
index c308a513..d128414e 100644
--- a/SPONSORS.md
+++ b/SPONSORS.md
@@ -4,18 +4,11 @@
The following people is currently [**sponsoring raylib**](https://github.com/sponsors/raysan5) with a generous donation to allow improving and growing the project!
-Note that Sponsors donations vary between sponsors, I just decided not to make any distinction while listing them.
-
- Eric J. ([@ProfJski](https://github.com/ProfJski))
- - devdad ([@devdad](https://github.com/devdad))
- Zach Geis ([@zacgeis](https://github.com/zacgeis))
- minirop ([@minirop](https://github.com/minirop))
- Daniel Gómez ([@Koocachookies](https://github.com/Koocachookies))
- - Sergio ([@anidealgift](https://github.com/anidealgift))
- Marc Agüera ([@maguera93](https://github.com/maguera93))
- - Pau Fernández ([@pauek](https://github.com/pauek))
- - Snowminx ([@Gamerfiend](https://github.com/Gamerfiend))
- - NimbusFox ([@NimbusFox](https://github.com/NimbusFox))
- Robin Mattheussen ([@romatthe](https://github.com/romatthe))
- Grant Haywood ([@cinterloper](https://github.com/cinterloper))
- Terry Nguyen ([@terrehbyte](https://github.com/terrehbyte))
@@ -25,10 +18,17 @@ Note that Sponsors donations vary between sponsors, I just decided not to make a
- cob ([@majorcob](https://github.com/majorcob))
- Samuel Batista ([@gamedevsam](https://github.com/gamedevsam))
- Merlyn Morgan-Graham ([@kavika13](https://github.com/kavika13))
- - Toby4213 ([@Toby4213](https://github.com/Toby4213))
- linus ([@hochbaum](https://github.com/hochbaum))
- Nawarian ([@nawarian](https://github.com/nawarian) - [thephp.website](https://thephp.website/))
-
+ - kenzie ([@sme-ek](https://github.com/sme-ek))
+ - Allan Regush ([@AllanRegush](https://github.com/AllanRegush))
+ - Jeffery Myers ([@JeffM2501](https://github.com/ProfJski))
+ - Ryan Roden-Corrent ([@rcorre](https://github.com/ProfJski))
+ - michaelfiber ([@michaelfiber](https://github.com/ProfJski))
+ - Nikhilesh S ([@nikki93](https://github.com/ProfJski))
+ - kevinabraun ([@kevinabraun](https://github.com/ProfJski))
+ - Matthew Owens ([@MatthewOwens](https://github.com/ProfJski))
+ - Tim Eilers ([@eilerstim](https://github.com/ProfJski))
### Past raylib GitHub Sponsors
@@ -49,10 +49,20 @@ The following people has **sponsored raylib** in the past, allowing the project
- James Ghawaly ([@jghawaly](https://github.com/jghawaly))
- jack ([@Jack-Ji](https://github.com/Jack-Ji))
- Guido Offermans ([@jghawaly](https://github.com/GuidoOffermans))
+ - devdad ([@devdad](https://github.com/devdad))
+ - Pau Fernández ([@pauek](https://github.com/pauek))
+ - Sergio ([@anidealgift](https://github.com/anidealgift))
+ - Snowminx ([@Gamerfiend](https://github.com/Gamerfiend))
+ - NimbusFox ([@NimbusFox](https://github.com/NimbusFox))
+ - Shylie ([@Shylie](https://github.com/Shylie))
+ - Livio Dal Maso ([@Humeur](https://github.com/Humeur))
+ - Diego Vaccher ([@denny0754](https://github.com/denny0754))
+ - Ricardo Alcantara ([@ricardoalcantara](https://github.com/ricardoalcantara))
+ - Toby4213 ([@Toby4213](https://github.com/Toby4213))
### Notes for Current/Past raylib Sponsor
- - **If you are not on the list, feel free to send a PR to add you if desired.**
- - **If you want your personal webpage listed along your GitHub account, feel free to send a PR to add it.**
- - **If you prefer not to listed in this list, feel free to send a PR to remove it.**
+ - If you are not on the list, feel free to send a PR to be added (if desired).
+ - If you want your personal webpage or project listed, feel free to send a PR to be added.
+ - If you prefer not to be in this list, feel free to send a PR to be remove.
diff --git a/examples/README.md b/examples/README.md
index ddf69fe5..14d566b2 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -1,3 +1,21 @@
+## Building the Examples
+
+The examples assume you have already built the `raylib` library in `../src`.
+
+### With GNU make
+
+- `make` builds all examples
+- `make [module]` builds all examples for a particular module (e.g `make core`)
+
+### With Zig
+
+The [Zig](https://ziglang.org/) toolchain can compile `C` and `C++` in addition to `Zig`.
+You may find it easier to use than other toolchains, especially when it comes to cross-compiling.
+
+- `zig build` to compile all examples
+- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
+- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
+
## EXAMPLES LIST
### category: core
diff --git a/examples/build.zig b/examples/build.zig
new file mode 100644
index 00000000..c05808bf
--- /dev/null
+++ b/examples/build.zig
@@ -0,0 +1,86 @@
+const std = @import("std");
+const builtin = @import("builtin");
+
+fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step {
+ // Standard release options allow the person running `zig build` to select
+ // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
+ const mode = b.standardReleaseOptions();
+
+ const all = b.step(module, "All " ++ module ++ " examples");
+ const dir = try std.fs.cwd().openDir(
+ module,
+ .{ .iterate = true },
+ );
+ var iter = dir.iterate();
+ while (try iter.next()) |entry| {
+ if (entry.kind != .File) continue;
+ const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
+ const name = entry.name[0..extension_idx];
+ const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
+
+ // zig's mingw headers do not include pthread.h
+ if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
+
+ const exe = b.addExecutable(name, path);
+ exe.setTarget(target);
+ exe.setBuildMode(mode);
+ exe.linkLibC();
+ exe.addObjectFile(switch (target.getOsTag()) {
+ .windows => "../src/raylib.lib",
+ .linux => "../src/libraylib.a",
+ else => @panic("Unsupported OS"),
+ });
+
+ exe.addIncludeDir("../src");
+ exe.addIncludeDir("../src/external");
+ exe.addIncludeDir("../src/external/glfw/include");
+
+ switch (exe.target.toTarget().os.tag) {
+ .windows => {
+ exe.linkSystemLibrary("winmm");
+ exe.linkSystemLibrary("gdi32");
+ exe.linkSystemLibrary("opengl32");
+ exe.addIncludeDir("external/glfw/deps/mingw");
+ },
+ .linux => {
+ exe.linkSystemLibrary("GL");
+ exe.linkSystemLibrary("rt");
+ exe.linkSystemLibrary("dl");
+ exe.linkSystemLibrary("m");
+ exe.linkSystemLibrary("X11");
+ },
+ else => {
+ @panic("Unsupported OS");
+ },
+ }
+
+ exe.setOutputDir(module);
+
+ var run = exe.run();
+ run.step.dependOn(&b.addInstallArtifact(exe).step);
+ run.cwd = module;
+ b.step(name, name).dependOn(&run.step);
+ all.dependOn(&exe.step);
+ }
+ return all;
+}
+
+pub fn build(b: *std.build.Builder) !void {
+ // Standard target options allows the person running `zig build` to choose
+ // what target to build for. Here we do not override the defaults, which
+ // means any target is allowed, and the default is native. Other options
+ // for restricting supported target set are available.
+ const target = b.standardTargetOptions(.{});
+
+ const all = b.getInstallStep();
+
+ all.dependOn(try add_module("audio", b, target));
+ all.dependOn(try add_module("core", b, target));
+ all.dependOn(try add_module("models", b, target));
+ all.dependOn(try add_module("others", b, target));
+ all.dependOn(try add_module("physics", b, target));
+ all.dependOn(try add_module("shaders", b, target));
+ all.dependOn(try add_module("shapes", b, target));
+ all.dependOn(try add_module("text", b, target));
+ all.dependOn(try add_module("textures", b, target));
+}
diff --git a/examples/models/models_loading_gltf.c b/examples/models/models_loading_gltf.c
index 5ef5fc5a..fe79afec 100644
--- a/examples/models/models_loading_gltf.c
+++ b/examples/models/models_loading_gltf.c
@@ -1,27 +1,24 @@
/*******************************************************************************************
*
-* raylib [models] example - Load 3d gltf model
+* raylib [models] example - Load models gltf
*
* This example has been created using raylib 3.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
+* NOTE: To export a model from Blender, make sure it is not posed, the vertices need to be
+* in the same position as they would be in edit mode.
+* Also make sure the scale parameter of your models is set to 0.0,
+* scaling can be applied from the export menu.
+*
* Example contributed by Hristo Stamenov (@object71) and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2021 Hristo Stamenov (@object71) and Ramon Santamaria (@raysan5)
*
-********************************************************************************************
-*
-* To export a model from blender, make sure it is not posed, the vertices need to be in the
-* same position as they would be in edit mode.
-* and that the scale of your models is set to 0. Scaling can be done from the export menu.
-*
********************************************************************************************/
#include "raylib.h"
-#include <stdlib.h>
-
-#define MAX_MODELS 8
+#define MAX_GLTF_MODELS 8
int main(void)
{
@@ -40,8 +37,8 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
- Model model[MAX_MODELS] = { 0 };
-
+ // Load some models
+ Model model[MAX_GLTF_MODELS] = { 0 };
model[0] = LoadModel("resources/models/gltf/raylib_32x32.glb");
model[1] = LoadModel("resources/models/gltf/rigged_figure.glb");
model[2] = LoadModel("resources/models/gltf/GearboxAssy.glb");
@@ -65,19 +62,20 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera); // Update our camera with inputs
if (IsKeyReleased(KEY_RIGHT))
{
currentModel++;
- if (currentModel == MAX_MODELS) currentModel = 0;
+ if (currentModel == MAX_GLTF_MODELS) currentModel = 0;
}
if (IsKeyReleased(KEY_LEFT))
{
currentModel--;
- if (currentModel < 0) currentModel = MAX_MODELS - 1;
+ if (currentModel < 0) currentModel = MAX_GLTF_MODELS - 1;
}
+ //----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
@@ -87,8 +85,7 @@ int main(void)
BeginMode3D(camera);
- DrawModelEx(model[currentModel], position, (Vector3){ 0.0f, 1.0f, 0.0f }, 180.0f, (Vector3){ 2.0f, 2.0f, 2.0f }, WHITE);
-
+ DrawModel(model[currentModel], position, 1.0f, WHITE);
DrawGrid(10, 1.0f); // Draw a grid
EndMode3D();
@@ -99,7 +96,7 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
- for (int i = 0; i < MAX_MODELS; i++) UnloadModel(model[i]); // Unload models
+ for (int i = 0; i < MAX_GLTF_MODELS; i++) UnloadModel(model[i]); // Unload models
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/models/models_loading_vox.c b/examples/models/models_loading_vox.c
index 909ff452..c693861e 100644
--- a/examples/models/models_loading_vox.c
+++ b/examples/models/models_loading_vox.c
@@ -1,32 +1,21 @@
/*******************************************************************************************
*
-* raylib [models] example - magicavoxel loader and viewer
+* raylib [models] example - Load models vox (MagicaVoxel)
*
-* This example has been created using raylib 3.8 (www.raylib.com)
+* This example has been created using raylib 4.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Example contributed by Johann Nadalutti (@procfxgen)
+* Example contributed by Johann Nadalutti (@procfxgen) and reviewed by Ramon Santamaria (@raysan5)
*
-* Copyright (c) 2021 Johann Nadalutti (@procfxgen)
+* Copyright (c) 2021 Johann Nadalutti (@procfxgen) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
-#include "raymath.h"
-#include <string.h>
-
-
-// VOX Files to load and view
-
-#define NUM_VOX_FILES 3
-
-const char* szVoxFiles[] = {
- "resources/models/vox/chr_knight.vox",
- "resources/models/vox/chr_sword.vox",
- "resources/models/vox/monu9.vox"
-};
+#include "raymath.h" // Required for: MatrixTranslate()
+#define MAX_VOX_FILES 3
int main(void)
{
@@ -34,101 +23,94 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
+
+ const char *voxFileNames[] = {
+ "resources/models/vox/chr_knight.vox",
+ "resources/models/vox/chr_sword.vox",
+ "resources/models/vox/monu9.vox"
+ };
InitWindow(screenWidth, screenHeight, "raylib [models] example - magicavoxel loading");
+
+ // Define the camera to look into our 3d world
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
// Load MagicaVoxel files
- Model models[NUM_VOX_FILES] = { 0 };
+ Model models[MAX_VOX_FILES] = { 0 };
- for (int i = 0; i < NUM_VOX_FILES; i++)
+ for (int i = 0; i < MAX_VOX_FILES; i++)
{
- // Load MagicaVoxel File and build model
- double t0, t1;
- t0 = GetTime() * 1000.0;
-
- models[i] = LoadModel(szVoxFiles[i]);
-
- t1 = GetTime() * 1000.0;
- //TraceLog(LOG_INFO, TextFormat("Vox <%s> loaded in %f ms", GetFileName(szVoxFiles[i]), t1 - t0));
-
- // Compute model's center matrix
- BoundingBox bb = GetModelBoundingBox(models[i]);
- Vector3 center;
- center.x = bb.min.x + (((bb.max.x - bb.min.x) / 2));
- center.z = bb.min.z + (((bb.max.z - bb.min.z) / 2));
-
- Matrix matP = MatrixTranslate(-center.x, 0, -center.z);
- models[i].transform = matP;
+ // Load VOX file and measure time
+ double t0 = GetTime()*1000.0;
+ models[i] = LoadModel(voxFileNames[i]);
+ double t1 = GetTime()*1000.0;
+
+ TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
+
+ // Compute model translation matrix to center model on draw position (0, 0 , 0)
+ BoundingBox bb = GetModelBoundingBox(models[i]);
+ Vector3 center = { 0 };
+ center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
+ center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
+
+ Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
+ models[i].transform = matTranslate;
}
-
- // Define the camera to look into our 3d world
- Camera camera = { { 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
-
- // Model drawing position
- Vector3 position = { 0.0f, 0.0f, 0.0f };
-
int currentModel = 0;
-
-
SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
-
//--------------------------------------------------------------------------------------
+
// Main game loop
- //--------------------------------------------------------------------------------------
while (!WindowShouldClose()) // Detect window close button or ESC key
{
- //--------------------------------------------------------------------------------------
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera); // Update internal camera and our camera
+ UpdateCamera(&camera); // Update our camera to orbit
- if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
- {
- currentModel = (currentModel + 1) % NUM_VOX_FILES; // Cycle between models
- }
+ // Cycle between models on mouse click
+ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1)%MAX_VOX_FILES;
+ // Cycle between models on key pressed
if (IsKeyPressed(KEY_RIGHT))
{
currentModel++;
- if (currentModel >= NUM_VOX_FILES) currentModel = 0;
+ if (currentModel >= MAX_VOX_FILES) currentModel = 0;
}
else if (IsKeyPressed(KEY_LEFT))
{
currentModel--;
- if (currentModel < 0) currentModel = NUM_VOX_FILES - 1;
+ if (currentModel < 0) currentModel = MAX_VOX_FILES - 1;
}
-
//----------------------------------------------------------------------------------
+
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
- ClearBackground(RAYWHITE);
+ ClearBackground(RAYWHITE);
+
+ // Draw 3D model
+ BeginMode3D(camera);
- //Display model
- BeginMode3D(camera);
+ DrawModel(models[currentModel], (Vector3){ 0, 0, 0 }, 1.0f, WHITE);
+ DrawGrid(10, 1.0);
- Vector3 rotAxis = { 1,0,0 };
- Vector3 scale = { 1,1,1 };
+ EndMode3D();
-
- DrawModelEx(models[currentModel], position, rotAxis, 0, scale, WHITE);
- //DrawModelWiresEx(models[currentModel], position, rotAxis, -90.0f, scale, BLACK);
-
- DrawGrid(10, 1.0);
-
- EndMode3D();
-
- //Display debug infos
- DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
- DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
- DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
-
- DrawText(GetFileName(szVoxFiles[currentModel]), 100, 10, 20, DARKBLUE);
+ // Display info
+ DrawRectangle(10, 400, 310, 30, Fade(SKYBLUE, 0.5f));
+ DrawRectangleLines(10, 400, 310, 30, Fade(DARKBLUE, 0.5f));
+ DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
+ DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -136,9 +118,8 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
-
// Unload models data (GPU VRAM)
- for (int i = 0; i < NUM_VOX_FILES; i++) UnloadModel(models[i]);
+ for (int i = 0; i < MAX_VOX_FILES; i++) UnloadModel(models[i]);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c
index 5731c4df..19d5edc7 100644
--- a/examples/models/models_yaw_pitch_roll.c
+++ b/examples/models/models_yaw_pitch_roll.c
@@ -79,7 +79,6 @@ int main(void)
model.transform = MatrixRotateXYZ((Vector3){ DEG2RAD*pitch, DEG2RAD*yaw, DEG2RAD*roll });
//----------------------------------------------------------------------------------
-
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
diff --git a/src/rmodels.c b/src/rmodels.c
index 1b6c659f..1536e53e 100644
--- a/src/rmodels.c
+++ b/src/rmodels.c
@@ -79,7 +79,7 @@
#define VOX_FREE RL_FREE
#define VOX_LOADER_IMPLEMENTATION
- #include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
+ #include "external/vox_loader.h" // VOX file format loading (MagikaVoxel)
#endif
#if defined(SUPPORT_MESH_GENERATION)