Merge branch 'raysan5:master' into dynamic-font-atlas
This commit is contained in:
commit
7b27628dfc
32 changed files with 248 additions and 571 deletions
|
|
@ -45,7 +45,6 @@ cmake_dependent_option(SUPPORT_GIF_RECORDING "Allow automatic gif recording of c
|
||||||
cmake_dependent_option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" OFF CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" OFF CUSTOMIZE_BUILD OFF)
|
||||||
cmake_dependent_option(SUPPORT_EVENTS_WAITING "Wait for events passively (sleeping while no events) instead of polling them actively every frame" OFF CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_EVENTS_WAITING "Wait for events passively (sleeping while no events) instead of polling them actively every frame" OFF CUSTOMIZE_BUILD OFF)
|
||||||
cmake_dependent_option(SUPPORT_WINMM_HIGHRES_TIMER "Setting a higher resolution can improve the accuracy of time-out intervals in wait functions" OFF CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_WINMM_HIGHRES_TIMER "Setting a higher resolution can improve the accuracy of time-out intervals in wait functions" OFF CUSTOMIZE_BUILD OFF)
|
||||||
cmake_dependent_option(SUPPORT_DATA_STORAGE "Support for persistent data storage" ON CUSTOMIZE_BUILD ON)
|
|
||||||
cmake_dependent_option(SUPPORT_COMPRESSION_API "Support for compression API" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_COMPRESSION_API "Support for compression API" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
||||||
# rshapes.c
|
# rshapes.c
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ raylib is also available via multiple [package managers](https://github.com/rays
|
||||||
- [Working for Web (HTML5)](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5))
|
- [Working for Web (HTML5)](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5))
|
||||||
- [Working anywhere with CMake](https://github.com/raysan5/raylib/wiki/Working-with-CMake)
|
- [Working anywhere with CMake](https://github.com/raysan5/raylib/wiki/Working-with-CMake)
|
||||||
|
|
||||||
*Note that Wiki is open for edit, if you find some issue while building raylib for your target platform, feel free to edit the Wiki or open and issue related to it.*
|
*Note that the Wiki is open for edit, if you find some issues while building raylib for your target platform, feel free to edit the Wiki or open an issue related to it.*
|
||||||
|
|
||||||
#### Setup raylib with multiple IDEs
|
#### Setup raylib with multiple IDEs
|
||||||
|
|
||||||
|
|
@ -109,14 +109,14 @@ raylib has been developed on Windows platform using [Notepad++](https://notepad-
|
||||||
|
|
||||||
[Projects directory](https://github.com/raysan5/raylib/tree/master/projects) contains several ready-to-use **project templates** to build raylib and code examples with multiple IDEs.
|
[Projects directory](https://github.com/raysan5/raylib/tree/master/projects) contains several ready-to-use **project templates** to build raylib and code examples with multiple IDEs.
|
||||||
|
|
||||||
*Note that there are lots of IDEs supported, some of the provided templates could require some review, please, if you find some issue with some template or you think they could be improved, feel free to send a PR or open a related issue.*
|
*Note that there are lots of IDEs supported, some of the provided templates could require some review, so please, if you find some issue with a template or you think they could be improved, feel free to send a PR or open a related issue.*
|
||||||
|
|
||||||
learning and docs
|
learning and docs
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
raylib is designed to be learned using [the examples](https://github.com/raysan5/raylib/tree/master/examples) as the main reference. There is no standard API documentation but there is a [**cheatsheet**](https://www.raylib.com/cheatsheet/cheatsheet.html) containing all the functions available on the library and a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.
|
raylib is designed to be learned using [the examples](https://github.com/raysan5/raylib/tree/master/examples) as the main reference. There is no standard API documentation but there is a [**cheatsheet**](https://www.raylib.com/cheatsheet/cheatsheet.html) containing all the functions available on the library a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.
|
||||||
|
|
||||||
Some additional documentation about raylib design can be found in raylib GitHub Wiki. Here the more relevant links:
|
Some additional documentation about raylib design can be found in raylib GitHub Wiki. Here are the relevant links:
|
||||||
|
|
||||||
- [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html)
|
- [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html)
|
||||||
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
|
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
|
||||||
|
|
|
||||||
12
ROADMAP.md
12
ROADMAP.md
|
|
@ -1,19 +1,19 @@
|
||||||
# raylib roadmap
|
# raylib roadmap
|
||||||
|
|
||||||
Here it is a wish-list with features and ideas to improve the library. Note that features listed here are usually long term improvements or just describe a route to follow for the library. There are also some additional places to look for raylib improvements of ideas:
|
Here it is a wishlist with features and ideas to improve the library. Note that features listed here are usually long term improvements or just describe a route to follow for the library. There are also some additional places to look for raylib improvements and ideas:
|
||||||
|
|
||||||
- [GitHub Issues](https://github.com/raysan5/raylib/issues) has several open issues for possible improvements or bugs to fix.
|
- [GitHub Issues](https://github.com/raysan5/raylib/issues) has several open issues for possible improvements or bugs to fix.
|
||||||
- [raylib source code](https://github.com/raysan5/raylib/tree/master/src) has multiple *TODO* comments around code with pending things to review or improve.
|
- [raylib source code](https://github.com/raysan5/raylib/tree/master/src) has multiple *TODO* comments around code with pending things to review or improve.
|
||||||
- [raylib wishlist](https://github.com/raysan5/raylib/discussions/1502) is open to everyone to ask for improvements, feel free to check and comment.
|
- raylib wishlists discussions (https://github.com/raysan5/raylib/discussions/1502, https://github.com/raysan5/raylib/discussions/2272) are open to everyone to ask for improvements, feel free to check and comment.
|
||||||
|
|
||||||
_Current version of raylib is complete and functional but, as always, there is lot of room for improvement._
|
_Current version of raylib is complete and functional but there is always room for improvements._
|
||||||
|
|
||||||
**raylib 4.x**
|
**raylib 4.x**
|
||||||
- [ ] Redesign camera module (more flexible) ([#1143](https://github.com/raysan5/raylib/issues/1143))
|
- [ ] Redesign camera module (more flexible) ([#1143](https://github.com/raysan5/raylib/issues/1143), https://github.com/raysan5/raylib/discussions/2507)
|
||||||
- [ ] Redesign gestures system, improve touch inputs management
|
- [ ] Redesign gestures system, improve touch inputs management
|
||||||
- [ ] Better documentation and improved examples
|
- [ ] Better documentation and improved examples
|
||||||
- [ ] Focus on HTML5 and embedded platforms
|
- [ ] Focus on HTML5 ([raylib 5k gamejam](https://itch.io/jam/raylib-5k-gamejam)) and embedded platforms (RPI and similar SOCs)
|
||||||
- [ ] Additional support libraries: [raygui](https://github.com/raysan5/raygui), [rres](https://github.com/raysan5/rres)...
|
- [x] Additional support libraries: [raygui](https://github.com/raysan5/raygui), [rres](https://github.com/raysan5/rres)
|
||||||
|
|
||||||
**raylib 4.0**
|
**raylib 4.0**
|
||||||
- [x] Improved consistency and coherency in raylib API
|
- [x] Improved consistency and coherency in raylib API
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ if (${CUSTOMIZE_BUILD})
|
||||||
define_if("raylib" SUPPORT_BUSY_WAIT_LOOP)
|
define_if("raylib" SUPPORT_BUSY_WAIT_LOOP)
|
||||||
define_if("raylib" SUPPORT_EVENTS_WAITING)
|
define_if("raylib" SUPPORT_EVENTS_WAITING)
|
||||||
define_if("raylib" SUPPORT_WINMM_HIGHRES_TIMER)
|
define_if("raylib" SUPPORT_WINMM_HIGHRES_TIMER)
|
||||||
define_if("raylib" SUPPORT_DATA_STORAGE)
|
|
||||||
define_if("raylib" SUPPORT_COMPRESSION_API)
|
define_if("raylib" SUPPORT_COMPRESSION_API)
|
||||||
define_if("raylib" SUPPORT_QUADS_DRAW_MODE)
|
define_if("raylib" SUPPORT_QUADS_DRAW_MODE)
|
||||||
define_if("raylib" SUPPORT_IMAGE_EXPORT)
|
define_if("raylib" SUPPORT_IMAGE_EXPORT)
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,6 @@ CORE = \
|
||||||
core/core_storage_values \
|
core/core_storage_values \
|
||||||
core/core_vr_simulator \
|
core/core_vr_simulator \
|
||||||
core/core_loading_thread \
|
core/core_loading_thread \
|
||||||
core/core_quat_conversion \
|
|
||||||
core/core_window_flags \
|
core/core_window_flags \
|
||||||
core/core_split_screen \
|
core/core_split_screen \
|
||||||
core/core_smooth_pixelperfect \
|
core/core_smooth_pixelperfect \
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,6 @@ CORE = \
|
||||||
core/core_storage_values \
|
core/core_storage_values \
|
||||||
core/core_vr_simulator \
|
core/core_vr_simulator \
|
||||||
core/core_loading_thread \
|
core/core_loading_thread \
|
||||||
core/core_quat_conversion \
|
|
||||||
core/core_window_flags \
|
core/core_window_flags \
|
||||||
core/core_split_screen \
|
core/core_split_screen \
|
||||||
core/core_smooth_pixelperfect \
|
core/core_smooth_pixelperfect \
|
||||||
|
|
@ -594,9 +593,6 @@ core/core_vr_simulator: core/core_vr_simulator.c
|
||||||
core/core_loading_thread: core/core_loading_thread.c
|
core/core_loading_thread: core/core_loading_thread.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s USE_PTHREADS=1
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s USE_PTHREADS=1
|
||||||
|
|
||||||
core/core_quat_conversion: core/core_quat_conversion.c
|
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
|
||||||
|
|
||||||
core/core_window_flags: core/core_window_flags.c
|
core/core_window_flags: core/core_window_flags.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ Examples using raylib core platform functionality like window creation, inputs,
|
||||||
| 20 | [core_storage_values](core/core_storage_values.c) | <img src="core/core_storage_values.png" alt="core_storage_values" width="200"> | ray | |
|
| 20 | [core_storage_values](core/core_storage_values.c) | <img src="core/core_storage_values.png" alt="core_storage_values" width="200"> | ray | |
|
||||||
| 21 | [core_vr_simulator](core/core_vr_simulator.c) | <img src="core/core_vr_simulator.png" alt="core_vr_simulator" width="200"> | ray | ⭐️ |
|
| 21 | [core_vr_simulator](core/core_vr_simulator.c) | <img src="core/core_vr_simulator.png" alt="core_vr_simulator" width="200"> | ray | ⭐️ |
|
||||||
| 22 | [core_loading_thread](core/core_loading_thread.c) | <img src="core/core_loading_thread.png" alt="core_loading_thread" width="200"> | ray | |
|
| 22 | [core_loading_thread](core/core_loading_thread.c) | <img src="core/core_loading_thread.png" alt="core_loading_thread" width="200"> | ray | |
|
||||||
| 23 | [core/core_quat_conversion](core/core_quat_conversion.c) | <img src="core/core_quat_conversion.png" alt="core_quat_conversion" width="200"> | [Chris Camacho](https://github.com/codifies) | |
|
|
||||||
| 24 | [core/core_window_flags](core/core_window_flags.c) | <img src="core/core_window_flags.png" alt="core_window_flags" width="200"> | ray | |
|
| 24 | [core/core_window_flags](core/core_window_flags.c) | <img src="core/core_window_flags.png" alt="core_window_flags" width="200"> | ray | |
|
||||||
|
|
||||||
### category: shapes
|
### category: shapes
|
||||||
|
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - quat conversions
|
|
||||||
*
|
|
||||||
* Generally you should really stick to eulers OR quats...
|
|
||||||
* This tests that various conversions are equivalent.
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
*
|
|
||||||
* Example contributed by Chris Camacho (@chriscamacho) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-2021 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
//------------------------------------------------------------------------------------
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
const int screenWidth = 800;
|
|
||||||
const int screenHeight = 450;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - quat conversions");
|
|
||||||
|
|
||||||
Camera3D camera = { 0 };
|
|
||||||
camera.position = (Vector3){ 0.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 a cylinder model for testing
|
|
||||||
Model model = LoadModelFromMesh(GenMeshCylinder(0.2f, 1.0f, 32));
|
|
||||||
|
|
||||||
// Generic quaternion for operations
|
|
||||||
Quaternion q1 = { 0 };
|
|
||||||
|
|
||||||
// Transform matrices required to draw 4 cylinders
|
|
||||||
Matrix m1 = { 0 };
|
|
||||||
Matrix m2 = { 0 };
|
|
||||||
Matrix m3 = { 0 };
|
|
||||||
Matrix m4 = { 0 };
|
|
||||||
|
|
||||||
// Generic vectors for rotations
|
|
||||||
Vector3 v1 = { 0 };
|
|
||||||
Vector3 v2 = { 0 };
|
|
||||||
|
|
||||||
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
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
if (v2.x < 0) v2.x += PI*2;
|
|
||||||
if (v2.y < 0) v2.y += PI*2;
|
|
||||||
if (v2.z < 0) v2.z += PI*2;
|
|
||||||
|
|
||||||
if (!IsKeyDown(KEY_SPACE))
|
|
||||||
{
|
|
||||||
v1.x += 0.01f;
|
|
||||||
v1.y += 0.03f;
|
|
||||||
v1.z += 0.05f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v1.x > PI*2) v1.x -= PI*2;
|
|
||||||
if (v1.y > PI*2) v1.y -= PI*2;
|
|
||||||
if (v1.z > PI*2) v1.z -= PI*2;
|
|
||||||
|
|
||||||
q1 = QuaternionFromEuler(v1.x, v1.y, v1.z);
|
|
||||||
m1 = MatrixRotateZYX(v1);
|
|
||||||
m2 = QuaternionToMatrix(q1);
|
|
||||||
|
|
||||||
q1 = QuaternionFromMatrix(m1);
|
|
||||||
m3 = QuaternionToMatrix(q1);
|
|
||||||
|
|
||||||
v2 = QuaternionToEuler(q1); // Angles returned in radians
|
|
||||||
|
|
||||||
m4 = MatrixRotateZYX(v2);
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
BeginMode3D(camera);
|
|
||||||
|
|
||||||
model.transform = m1;
|
|
||||||
DrawModel(model, (Vector3){ -1, 0, 0 }, 1.0f, RED);
|
|
||||||
|
|
||||||
model.transform = m2;
|
|
||||||
DrawModel(model, (Vector3){ 1, 0, 0 }, 1.0f, RED);
|
|
||||||
|
|
||||||
model.transform = m3;
|
|
||||||
DrawModel(model, (Vector3){ 0, 0, 0 }, 1.0f, RED);
|
|
||||||
|
|
||||||
model.transform = m4;
|
|
||||||
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
|
||||||
|
|
||||||
EndMode3D();
|
|
||||||
|
|
||||||
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
|
||||||
DrawText(TextFormat("%2.3f", v1.y), 20, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
|
||||||
DrawText(TextFormat("%2.3f", v1.z), 20, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
|
||||||
|
|
||||||
DrawText(TextFormat("%2.3f", v2.x), 200, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
|
||||||
DrawText(TextFormat("%2.3f", v2.y), 200, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
|
||||||
DrawText(TextFormat("%2.3f", v2.z), 200, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
|
||||||
|
|
||||||
EndDrawing();
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
UnloadModel(model); // Unload model data (mesh and materials)
|
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
|
|
@ -11,12 +11,20 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include <stdlib.h> // Required for: calloc(), free()
|
||||||
|
|
||||||
|
#define STORAGE_DATA_FILE "storage.data" // Storage file
|
||||||
|
|
||||||
// NOTE: Storage positions must start with 0, directly related to file memory layout
|
// NOTE: Storage positions must start with 0, directly related to file memory layout
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STORAGE_POSITION_SCORE = 0,
|
STORAGE_POSITION_SCORE = 0,
|
||||||
STORAGE_POSITION_HISCORE = 1
|
STORAGE_POSITION_HISCORE = 1
|
||||||
} StorageData;
|
} StorageData;
|
||||||
|
|
||||||
|
// Persistent storage functions
|
||||||
|
static bool SaveStorageValue(unsigned int position, int value);
|
||||||
|
static int LoadStorageValue(unsigned int position);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
@ -87,4 +95,97 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save integer value to storage file (to defined position)
|
||||||
|
// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
|
||||||
|
bool SaveStorageValue(unsigned int position, int value)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
unsigned int dataSize = 0;
|
||||||
|
unsigned int newDataSize = 0;
|
||||||
|
unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize);
|
||||||
|
unsigned char *newFileData = NULL;
|
||||||
|
|
||||||
|
if (fileData != NULL)
|
||||||
|
{
|
||||||
|
if (dataSize <= (position*sizeof(int)))
|
||||||
|
{
|
||||||
|
// Increase data size up to position and store value
|
||||||
|
newDataSize = (position + 1)*sizeof(int);
|
||||||
|
newFileData = (unsigned char *)RL_REALLOC(fileData, newDataSize);
|
||||||
|
|
||||||
|
if (newFileData != NULL)
|
||||||
|
{
|
||||||
|
// RL_REALLOC succeded
|
||||||
|
int *dataPtr = (int *)newFileData;
|
||||||
|
dataPtr[position] = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// RL_REALLOC failed
|
||||||
|
TraceLog(LOG_WARNING, "FILEIO: [%s] Failed to realloc data (%u), position in bytes (%u) bigger than actual file size", STORAGE_DATA_FILE, dataSize, position*sizeof(int));
|
||||||
|
|
||||||
|
// We store the old size of the file
|
||||||
|
newFileData = fileData;
|
||||||
|
newDataSize = dataSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Store the old size of the file
|
||||||
|
newFileData = fileData;
|
||||||
|
newDataSize = dataSize;
|
||||||
|
|
||||||
|
// Replace value on selected position
|
||||||
|
int *dataPtr = (int *)newFileData;
|
||||||
|
dataPtr[position] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
success = SaveFileData(STORAGE_DATA_FILE, newFileData, newDataSize);
|
||||||
|
RL_FREE(newFileData);
|
||||||
|
|
||||||
|
TraceLog(LOG_INFO, "FILEIO: [%s] Saved storage value: %i", STORAGE_DATA_FILE, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TraceLog(LOG_INFO, "FILEIO: [%s] File created successfully", STORAGE_DATA_FILE);
|
||||||
|
|
||||||
|
dataSize = (position + 1)*sizeof(int);
|
||||||
|
fileData = (unsigned char *)RL_MALLOC(dataSize);
|
||||||
|
int *dataPtr = (int *)fileData;
|
||||||
|
dataPtr[position] = value;
|
||||||
|
|
||||||
|
success = SaveFileData(STORAGE_DATA_FILE, fileData, dataSize);
|
||||||
|
UnloadFileData(fileData);
|
||||||
|
|
||||||
|
TraceLog(LOG_INFO, "FILEIO: [%s] Saved storage value: %i", STORAGE_DATA_FILE, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load integer value from storage file (from defined position)
|
||||||
|
// NOTE: If requested position could not be found, value 0 is returned
|
||||||
|
int LoadStorageValue(unsigned int position)
|
||||||
|
{
|
||||||
|
int value = 0;
|
||||||
|
unsigned int dataSize = 0;
|
||||||
|
unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize);
|
||||||
|
|
||||||
|
if (fileData != NULL)
|
||||||
|
{
|
||||||
|
if (dataSize < (position*4)) TraceLog(LOG_WARNING, "FILEIO: [%s] Failed to find storage position: %i", STORAGE_DATA_FILE, position);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int *dataPtr = (int *)fileData;
|
||||||
|
value = dataPtr[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
UnloadFileData(fileData);
|
||||||
|
|
||||||
|
TraceLog(LOG_INFO, "FILEIO: [%s] Loaded storage value: %i", STORAGE_DATA_FILE, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Load models gltf
|
* raylib [models] example - loading gltf
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 3.5 (www.raylib.com)
|
* This example has been created using raylib 4.2 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* 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
|
* Copyright (c) 2022 Ramon Santamaria (@raysan5)
|
||||||
* 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)
|
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define MAX_GLTF_MODELS 8
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
@ -30,7 +21,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - model");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - loading gltf");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
@ -40,18 +31,8 @@ int main(void)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
// Load some models
|
// Loaf gltf model
|
||||||
Model model[MAX_GLTF_MODELS] = { 0 };
|
Model model = LoadModel("resources/models/gltf/robot.glb");
|
||||||
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");
|
|
||||||
model[3] = LoadModel("resources/models/gltf/BoxAnimated.glb");
|
|
||||||
model[4] = LoadModel("resources/models/gltf/AnimatedTriangle.gltf");
|
|
||||||
model[5] = LoadModel("resources/models/gltf/AnimatedMorphCube.glb");
|
|
||||||
model[6] = LoadModel("resources/models/gltf/vertex_colored_object.glb");
|
|
||||||
model[7] = LoadModel("resources/models/gltf/girl.glb");
|
|
||||||
|
|
||||||
int currentModel = 0;
|
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
|
|
@ -66,18 +47,6 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update our camera with inputs
|
UpdateCamera(&camera); // Update our camera with inputs
|
||||||
|
|
||||||
if (IsKeyReleased(KEY_RIGHT))
|
|
||||||
{
|
|
||||||
currentModel++;
|
|
||||||
if (currentModel == MAX_GLTF_MODELS) currentModel = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsKeyReleased(KEY_LEFT))
|
|
||||||
{
|
|
||||||
currentModel--;
|
|
||||||
if (currentModel < 0) currentModel = MAX_GLTF_MODELS - 1;
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -88,7 +57,7 @@ int main(void)
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
DrawModel(model[currentModel], position, 1.0f, WHITE);
|
DrawModel(model, position, 1.0f, WHITE);
|
||||||
DrawGrid(10, 1.0f); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
@ -99,8 +68,8 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
for (int i = 0; i < MAX_GLTF_MODELS; i++) UnloadModel(model[i]); // Unload models
|
UnloadModel(model); // Unload model and meshes/material
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
| resource | author | licence | notes |
|
| resource | author | licence | notes |
|
||||||
| :------------------- | :---------: | :------ | :---- |
|
| :------------------- | :---------: | :------ | :---- |
|
||||||
| models/obj/castle.obj,<br>models/castle_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/castle.obj,<br>models/obj/castle_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/bridge.obj,<br>models/bridge_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/bridge.obj,<br>models/obj/bridge_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/house.obj,<br>models/house_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/house.obj,<br>models/obj/house_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/market.obj,<br>models/market_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/market.obj,<br>models/obj/market_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/turret.obj,<br>models/turret_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/turret.obj,<br>models/obj/turret_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/well.obj,<br>models/well_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
| models/obj/well.obj,<br>models/obj/well_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
|
||||||
| models/obj/cube.obj,<br>models/cube_diffuse.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
|
| models/obj/cube.obj,<br>models/obj/cube_diffuse.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
|
||||||
| models/obj/plane.gltf,<br>models/gltf/plane/plane.bin,<br>models/gltf/plane/plane_diffuse.png | [GiaHanLam](https://sketchfab.com/GiaHanLam) | [CC-BY](https://creativecommons.org/licenses/by/4.0/) | Used by: [`models_yaw_pitch_roll.c`](https://github.com/raysan5/raylib/blob/master/examples/models/models_yaw_pitch_roll.c)
|
| models/obj/plane.obj,<br>models/obj/plane_diffuse.png | [GiaHanLam](https://sketchfab.com/GiaHanLam) | [CC-BY](https://creativecommons.org/licenses/by/4.0/) | Used by: [`models_yaw_pitch_roll.c`](https://github.com/raysan5/raylib/blob/master/examples/models/models_yaw_pitch_roll.c)
|
||||||
| models/iqm/guy.iqm,<br>models/iqm/guyanim.iqm,<br>models/iqm/guytex.png,<br>models/iqm/guy.blend | [@culacant](https://github.com/culacant) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
|
| models/iqm/guy.iqm,<br>models/iqm/guyanim.iqm,<br>models/iqm/guytex.png,<br>models/iqm/guy.blend | [@culacant](https://github.com/culacant) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
|
||||||
| models/iqm/vertex_colored_object.iqm | ❔ | ❔ | - |
|
| models/gltf/robot.glb,<br>models/gltf/robot.blend | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
|
||||||
| models/gltf/... | _various_ | Check [LICENSE](https://github.com/raysan5/raylib/blob/master/examples/models/resources/models/gltf/LICENSE) | - |
|
|
||||||
| models/vox/chr_knight.vox | ❔ | ❔ | - |
|
| models/vox/chr_knight.vox | ❔ | ❔ | - |
|
||||||
| models/vox/chr_sword.vox | ❔ | ❔ | - |
|
| models/vox/chr_sword.vox | ❔ | ❔ | - |
|
||||||
| models/vox/monu9.vox | ❔ | ❔ | - |
|
| models/vox/monu9.vox | ❔ | ❔ | - |
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,118 +0,0 @@
|
||||||
{
|
|
||||||
"scene" : 0,
|
|
||||||
"scenes" : [
|
|
||||||
{
|
|
||||||
"nodes" : [ 0 ]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"nodes" : [
|
|
||||||
{
|
|
||||||
"mesh" : 0,
|
|
||||||
"rotation" : [ 0.0, 0.0, 0.0, 1.0 ]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"meshes" : [
|
|
||||||
{
|
|
||||||
"primitives" : [ {
|
|
||||||
"attributes" : {
|
|
||||||
"POSITION" : 1
|
|
||||||
},
|
|
||||||
"indices" : 0
|
|
||||||
} ]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"animations": [
|
|
||||||
{
|
|
||||||
"samplers" : [
|
|
||||||
{
|
|
||||||
"input" : 2,
|
|
||||||
"interpolation" : "LINEAR",
|
|
||||||
"output" : 3
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"channels" : [ {
|
|
||||||
"sampler" : 0,
|
|
||||||
"target" : {
|
|
||||||
"node" : 0,
|
|
||||||
"path" : "rotation"
|
|
||||||
}
|
|
||||||
} ]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"buffers" : [
|
|
||||||
{
|
|
||||||
"uri" : "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=",
|
|
||||||
"byteLength" : 44
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"uri" : "data:application/octet-stream;base64,AAAAAAAAgD4AAAA/AABAPwAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAD0/TQ/9P00PwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAPT9ND/0/TS/AAAAAAAAAAAAAAAAAACAPw==",
|
|
||||||
"byteLength" : 100
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"bufferViews" : [
|
|
||||||
{
|
|
||||||
"buffer" : 0,
|
|
||||||
"byteOffset" : 0,
|
|
||||||
"byteLength" : 6,
|
|
||||||
"target" : 34963
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"buffer" : 0,
|
|
||||||
"byteOffset" : 8,
|
|
||||||
"byteLength" : 36,
|
|
||||||
"target" : 34962
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"buffer" : 1,
|
|
||||||
"byteOffset" : 0,
|
|
||||||
"byteLength" : 100
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"accessors" : [
|
|
||||||
{
|
|
||||||
"bufferView" : 0,
|
|
||||||
"byteOffset" : 0,
|
|
||||||
"componentType" : 5123,
|
|
||||||
"count" : 3,
|
|
||||||
"type" : "SCALAR",
|
|
||||||
"max" : [ 2 ],
|
|
||||||
"min" : [ 0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bufferView" : 1,
|
|
||||||
"byteOffset" : 0,
|
|
||||||
"componentType" : 5126,
|
|
||||||
"count" : 3,
|
|
||||||
"type" : "VEC3",
|
|
||||||
"max" : [ 1.0, 1.0, 0.0 ],
|
|
||||||
"min" : [ 0.0, 0.0, 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bufferView" : 2,
|
|
||||||
"byteOffset" : 0,
|
|
||||||
"componentType" : 5126,
|
|
||||||
"count" : 5,
|
|
||||||
"type" : "SCALAR",
|
|
||||||
"max" : [ 1.0 ],
|
|
||||||
"min" : [ 0.0 ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bufferView" : 2,
|
|
||||||
"byteOffset" : 20,
|
|
||||||
"componentType" : 5126,
|
|
||||||
"count" : 5,
|
|
||||||
"type" : "VEC4",
|
|
||||||
"max" : [ 0.0, 0.0, 1.0, 1.0 ],
|
|
||||||
"min" : [ 0.0, 0.0, 0.0, -0.707 ]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"asset" : {
|
|
||||||
"version" : "2.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
|
@ -1,23 +1,2 @@
|
||||||
Rigged Figure model has been created by Cesium (https://cesium.com/cesiumjs/),
|
robot.glb model by @Quaternius (https://www.patreon.com/quaternius)
|
||||||
and licensed as Creative Commons Attribution 4.0 International License.
|
Licensed under CC0 1.0 Universal (CC0 1.0) - Public Domain Dedication (https://creativecommons.org/publicdomain/zero/1.0/)
|
||||||
|
|
||||||
Box Animated model has been created by Cesium (https://cesium.com/cesiumjs/)
|
|
||||||
and is licensed as Creative Commons Attribution 4.0 International License
|
|
||||||
|
|
||||||
Avocado model is provided by Microsoft
|
|
||||||
and licensed as CC0 Universal Public Domain
|
|
||||||
|
|
||||||
Animated Morph Cube model is provided by Microsoft
|
|
||||||
and licensed as CC0 Universal Public Domain
|
|
||||||
|
|
||||||
Animated Triangle model is licensed as CC0 Universal Public Domain
|
|
||||||
|
|
||||||
Gearbox Assy model has been provided by Okino Computer Graphics, using Okino Polytrans Software.
|
|
||||||
no license information was provided
|
|
||||||
|
|
||||||
Girl model has been provided by Hristo Stamenov (https://thatonegamedev.com/)
|
|
||||||
and licensed as CC0 Universal Public Domain
|
|
||||||
|
|
||||||
Check for details on CC0: https://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
Check for details on CC4: http://creativecommons.org/licenses/by/4.0/
|
|
||||||
GLTF sample models for testing are taken from: https://github.com/KhronosGroup/glTF-Sample-Models/
|
|
||||||
Binary file not shown.
BIN
examples/models/resources/models/gltf/raylib_logo_3d.glb
Normal file
BIN
examples/models/resources/models/gltf/raylib_logo_3d.glb
Normal file
Binary file not shown.
Binary file not shown.
BIN
examples/models/resources/models/gltf/robot.blend
Normal file
BIN
examples/models/resources/models/gltf/robot.blend
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue