Reviewed some examples and warnings

This commit is contained in:
Ray 2023-11-08 20:09:32 +01:00
parent bee6d7f065
commit 040b945fef
9 changed files with 76 additions and 106 deletions

View file

@ -941,7 +941,7 @@ shaders/shaders_deferred_render: shaders/shaders_deferred_render.c
--preload-file shaders/resources/shaders/glsl330/gbuffer.vs@resources/shaders/glsl330/gbuffer.vs \ --preload-file shaders/resources/shaders/glsl330/gbuffer.vs@resources/shaders/glsl330/gbuffer.vs \
--preload-file shaders/resources/shaders/glsl330/gbuffer.fs@resources/shaders/glsl330/gbuffer.fs \ --preload-file shaders/resources/shaders/glsl330/gbuffer.fs@resources/shaders/glsl330/gbuffer.fs \
--preload-file shaders/resources/shaders/glsl330/deferred_shading.fs@resources/shaders/glsl330/deferred_shading.fs \ --preload-file shaders/resources/shaders/glsl330/deferred_shading.fs@resources/shaders/glsl330/deferred_shading.fs \
--preload-file shaders/resources/shaders/glsl330/deferred_shading.fs@resources/shaders/glsl330/deferred_shading.fs \ --preload-file shaders/resources/shaders/glsl330/deferred_shading.fs@resources/shaders/glsl330/deferred_shading.fs
shaders/shaders_eratosthenes: shaders/shaders_eratosthenes.c shaders/shaders_eratosthenes: shaders/shaders_eratosthenes.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \

View file

@ -104,7 +104,7 @@ int main(void)
bool SaveStorageValue(unsigned int position, int value) bool SaveStorageValue(unsigned int position, int value)
{ {
bool success = false; bool success = false;
unsigned int dataSize = 0; int dataSize = 0;
unsigned int newDataSize = 0; unsigned int newDataSize = 0;
unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize); unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize);
unsigned char *newFileData = NULL; unsigned char *newFileData = NULL;
@ -172,7 +172,7 @@ bool SaveStorageValue(unsigned int position, int value)
int LoadStorageValue(unsigned int position) int LoadStorageValue(unsigned int position)
{ {
int value = 0; int value = 0;
unsigned int dataSize = 0; int dataSize = 0;
unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize); unsigned char *fileData = LoadFileData(STORAGE_DATA_FILE, &dataSize);
if (fileData != NULL) if (fileData != NULL)

View file

@ -48,7 +48,7 @@ int main(void)
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
// Load animation data // Load animation data
unsigned int animsCount = 0; int animsCount = 0;
ModelAnimation *anims = LoadModelAnimations("resources/models/iqm/guyanim.iqm", &animsCount); ModelAnimation *anims = LoadModelAnimations("resources/models/iqm/guyanim.iqm", &animsCount);
int animFrameCounter = 0; int animFrameCounter = 0;

View file

@ -44,7 +44,7 @@ int main(void)
Model model = LoadModel("resources/models/gltf/robot.glb"); Model model = LoadModel("resources/models/gltf/robot.glb");
// Load gltf model animations // Load gltf model animations
unsigned int animsCount = 0; int animsCount = 0;
unsigned int animIndex = 0; unsigned int animIndex = 0;
unsigned int animCurrentFrame = 0; unsigned int animCurrentFrame = 0;
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animsCount); ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animsCount);

View file

@ -50,7 +50,7 @@ int main(void)
Model model = LoadModel(modelFileName); // Load the bind-pose model mesh and basic data Model model = LoadModel(modelFileName); // Load the bind-pose model mesh and basic data
// Load animations // Load animations
unsigned int animsCount = 0; int animsCount = 0;
int animFrameCounter = 0, animId = 0; int animFrameCounter = 0, animId = 0;
ModelAnimation *anims = LoadModelAnimations(modelFileName, &animsCount); // Load skeletal animation data ModelAnimation *anims = LoadModelAnimations(modelFileName, &animsCount); // Load skeletal animation data

View file

@ -67,9 +67,6 @@ int main(void)
// On pause, we draw a blinking message // On pause, we draw a blinking message
if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY); if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY);
DrawCircle(400.5f, 300.5f, 50.0f, BLACK);
DrawCircle(528.0f, 172.0f, 26.0f, BLACK);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();

View file

@ -2,7 +2,7 @@
* *
* raylib [shapes] example - splines drawing * raylib [shapes] example - splines drawing
* *
* Example originally created with raylib 4.6-dev, last time updated with raylib 4.6-dev * Example originally created with raylib 5.0, last time updated with raylib 5.0
* *
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software * BSD-like license that allows static linking with closed source software
@ -17,7 +17,7 @@
#define MAX_SPLINE_POINTS 32 #define MAX_SPLINE_POINTS 32
// Bezier spline control points // Cubic Bezier spline control points
// NOTE: Every segment has two control points // NOTE: Every segment has two control points
typedef struct { typedef struct {
Vector2 start; Vector2 start;
@ -26,10 +26,10 @@ typedef struct {
// Spline types // Spline types
typedef enum { typedef enum {
SPLINE_LINEAR = 0, SPLINE_LINEAR = 0, // Linear
SPLINE_BASIS, // B-Spline SPLINE_BASIS, // B-Spline
SPLINE_CATMULLROM, SPLINE_CATMULLROM, // Catmull-Rom
SPLINE_BEZIER SPLINE_BEZIER // Cubic Bezier
} SplineType; } SplineType;
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------

View file

@ -38,7 +38,7 @@ int main(void)
const char msg[50] = "Signed Distance Fields"; const char msg[50] = "Signed Distance Fields";
// Loading file to memory // Loading file to memory
unsigned int fileSize = 0; int fileSize = 0;
unsigned char *fileData = LoadFileData("resources/anonymous_pro_bold.ttf", &fileSize); unsigned char *fileData = LoadFileData("resources/anonymous_pro_bold.ttf", &fileSize);
// Default font generation from TTF font // Default font generation from TTF font

View file

@ -13,7 +13,6 @@
* *
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#include "raymath.h" #include "raymath.h"
@ -43,12 +42,8 @@ static Vector2 *curveSelectedPoint = NULL;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static void UpdateOptions(void);
static void UpdateCurve(void);
static void DrawCurve(void);
static void DrawTexturedCurve(void); static void DrawTexturedCurve(void);
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
@ -81,9 +76,31 @@ int main()
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCurve(); // Curve config options
UpdateOptions(); if (IsKeyPressed(KEY_SPACE)) showCurve = !showCurve;
if (IsKeyPressed(KEY_EQUAL)) curveWidth += 2;
if (IsKeyPressed(KEY_MINUS)) curveWidth -= 2;
if (curveWidth < 2) curveWidth = 2;
// Update segments
if (IsKeyPressed(KEY_LEFT)) curveSegments -= 2;
if (IsKeyPressed(KEY_RIGHT)) curveSegments += 2;
if (curveSegments < 2) curveSegments = 2;
// Update curve logic
// If the mouse is not down, we are not editing the curve so clear the selection
if (!IsMouseButtonDown(MOUSE_LEFT_BUTTON)) curveSelectedPoint = NULL;
// If a point was selected, move it
if (curveSelectedPoint) *curveSelectedPoint = Vector2Add(*curveSelectedPoint, GetMouseDelta());
// The mouse is down, and nothing was selected, so see if anything was picked
Vector2 mouse = GetMousePosition();
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) curveSelectedPoint = &curveStartPosition;
else if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) curveSelectedPoint = &curveStartPositionTangent;
else if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) curveSelectedPoint = &curveEndPosition;
else if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) curveSelectedPoint = &curveEndPositionTangent;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -92,9 +109,29 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexturedCurve(); DrawTexturedCurve(); // Draw a textured Spline Cubic Bezier
DrawCurve();
// Draw spline for reference
if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE);
// Draw the various control points and highlight where the mouse is
DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE);
DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f));
DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE);
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW);
DrawCircleV(curveStartPosition, 5, RED);
if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) DrawCircleV(curveStartPositionTangent, 7, YELLOW);
DrawCircleV(curveStartPositionTangent, 5, MAROON);
if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) DrawCircleV(curveEndPosition, 7, YELLOW);
DrawCircleV(curveEndPosition, 5, GREEN);
if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) DrawCircleV(curveEndPositionTangent, 7, YELLOW);
DrawCircleV(curveEndPositionTangent, 5, DARKGREEN);
// Draw usage info
DrawText("Drag points to move curve, press SPACE to show/hide base curve", 10, 10, 10, DARKGRAY); DrawText("Drag points to move curve, press SPACE to show/hide base curve", 10, 10, 10, DARKGRAY);
DrawText(TextFormat("Curve width: %2.0f (Use + and - to adjust)", curveWidth), 10, 30, 10, DARKGRAY); DrawText(TextFormat("Curve width: %2.0f (Use + and - to adjust)", curveWidth), 10, 30, 10, DARKGRAY);
DrawText(TextFormat("Curve segments: %d (Use LEFT and RIGHT to adjust)", curveSegments), 10, 50, 10, DARKGRAY); DrawText(TextFormat("Curve segments: %d (Use LEFT and RIGHT to adjust)", curveSegments), 10, 50, 10, DARKGRAY);
@ -116,54 +153,8 @@ int main()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Definition // Module Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static void DrawCurve(void)
{
if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE);
// Draw the various control points and highlight where the mouse is
DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE);
DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f));
DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE);
Vector2 mouse = GetMousePosition();
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW);
DrawCircleV(curveStartPosition, 5, RED);
if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) DrawCircleV(curveStartPositionTangent, 7, YELLOW);
DrawCircleV(curveStartPositionTangent, 5, MAROON);
if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) DrawCircleV(curveEndPosition, 7, YELLOW);
DrawCircleV(curveEndPosition, 5, GREEN);
if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) DrawCircleV(curveEndPositionTangent, 7, YELLOW);
DrawCircleV(curveEndPositionTangent, 5, DARKGREEN);
}
static void UpdateCurve(void)
{
// If the mouse is not down, we are not editing the curve so clear the selection
if (!IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{
curveSelectedPoint = NULL;
return;
}
// If a point was selected, move it
if (curveSelectedPoint)
{
*curveSelectedPoint = Vector2Add(*curveSelectedPoint, GetMouseDelta());
return;
}
// The mouse is down, and nothing was selected, so see if anything was picked
Vector2 mouse = GetMousePosition();
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) curveSelectedPoint = &curveStartPosition;
else if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) curveSelectedPoint = &curveStartPositionTangent;
else if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) curveSelectedPoint = &curveEndPosition;
else if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) curveSelectedPoint = &curveEndPositionTangent;
}
// Draw textured curve using Spline Cubic Bezier
static void DrawTexturedCurve(void) static void DrawTexturedCurve(void)
{ {
const float step = 1.0f/curveSegments; const float step = 1.0f/curveSegments;
@ -180,11 +171,11 @@ static void DrawTexturedCurve(void)
for (int i = 1; i <= curveSegments; i++) for (int i = 1; i <= curveSegments; i++)
{ {
// Segment the curve t = step*(float)i;
t = step*i;
float a = powf(1 - t, 3); float a = powf(1.0f - t, 3);
float b = 3*powf(1 - t, 2)*t; float b = 3.0f*powf(1.0f - t, 2)*t;
float c = 3*(1 - t)*powf(t, 2); float c = 3.0f*(1.0f - t)*powf(t, 2);
float d = powf(t, 3); float d = powf(t, 3);
// Compute the endpoint for this segment // Compute the endpoint for this segment
@ -217,7 +208,6 @@ static void DrawTexturedCurve(void)
// Draw the segment as a quad // Draw the segment as a quad
rlSetTexture(texRoad.id); rlSetTexture(texRoad.id);
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(255,255,255,255); rlColor4ub(255,255,255,255);
rlNormal3f(0.0f, 0.0f, 1.0f); rlNormal3f(0.0f, 0.0f, 1.0f);
@ -232,7 +222,6 @@ static void DrawTexturedCurve(void)
rlTexCoord2f(0, v); rlTexCoord2f(0, v);
rlVertex2f(currentNegNormal.x, currentNegNormal.y); rlVertex2f(currentNegNormal.x, currentNegNormal.y);
rlEnd(); rlEnd();
// The current step is the start of the next step // The current step is the start of the next step
@ -242,19 +231,3 @@ static void DrawTexturedCurve(void)
} }
} }
static void UpdateOptions(void)
{
if (IsKeyPressed(KEY_SPACE)) showCurve = !showCurve;
// Update with
if (IsKeyPressed(KEY_EQUAL)) curveWidth += 2;
if (IsKeyPressed(KEY_MINUS)) curveWidth -= 2;
if (curveWidth < 2) curveWidth = 2;
// Update segments
if (IsKeyPressed(KEY_LEFT)) curveSegments -= 2;
if (IsKeyPressed(KEY_RIGHT)) curveSegments += 2;
if (curveSegments < 2) curveSegments = 2;
}