mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 11:28:17 +00:00
EXAMPLES: Format tweaks
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Mixed audio processing
|
* raylib [audio] example - mixed audio processing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
@@ -45,7 +45,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
{
|
{
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Playing spatialized 3D sound
|
* raylib [audio] example - spatialized 3D sound
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@@ -31,9 +31,9 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Playing spatialized 3D sound");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
Sound sound = LoadSound("resources/coin.wav");
|
Sound sound = LoadSound("resources/coin.wav");
|
||||||
@@ -45,9 +45,9 @@ int main(void)
|
|||||||
.fovy = 60,
|
.fovy = 60,
|
||||||
.projection = CAMERA_PERSPECTIVE
|
.projection = CAMERA_PERSPECTIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
DisableCursor();
|
DisableCursor();
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadSound(sound);
|
UnloadSound(sound);
|
||||||
CloseAudioDevice(); // Close audio device
|
CloseAudioDevice(); // Close audio device
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@@ -100,23 +100,23 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo
|
|||||||
// Calculate direction vector and distance between listener and sound source
|
// Calculate direction vector and distance between listener and sound source
|
||||||
Vector3 direction = Vector3Subtract(position, listener.position);
|
Vector3 direction = Vector3Subtract(position, listener.position);
|
||||||
float distance = Vector3Length(direction);
|
float distance = Vector3Length(direction);
|
||||||
|
|
||||||
// Apply logarithmic distance attenuation and clamp between 0-1
|
// Apply logarithmic distance attenuation and clamp between 0-1
|
||||||
float attenuation = 1.0f/(1.0f + (distance/maxDist));
|
float attenuation = 1.0f/(1.0f + (distance/maxDist));
|
||||||
attenuation = Clamp(attenuation, 0.0f, 1.0f);
|
attenuation = Clamp(attenuation, 0.0f, 1.0f);
|
||||||
|
|
||||||
// Calculate normalized vectors for spatial positioning
|
// Calculate normalized vectors for spatial positioning
|
||||||
Vector3 normalizedDirection = Vector3Normalize(direction);
|
Vector3 normalizedDirection = Vector3Normalize(direction);
|
||||||
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
||||||
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
||||||
|
|
||||||
// Reduce volume for sounds behind the listener
|
// Reduce volume for sounds behind the listener
|
||||||
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
||||||
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
||||||
|
|
||||||
// Set stereo panning based on sound position relative to listener
|
// Set stereo panning based on sound position relative to listener
|
||||||
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
||||||
|
|
||||||
// Apply final sound properties
|
// Apply final sound properties
|
||||||
SetSoundVolume(sound, attenuation);
|
SetSoundVolume(sound, attenuation);
|
||||||
SetSoundPan(sound, pan);
|
SetSoundPan(sound, pan);
|
||||||
|
@@ -53,7 +53,7 @@ int main(void)
|
|||||||
|
|
||||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||||
bool pause = false; // Music playing paused
|
bool pause = false; // Music playing paused
|
||||||
|
|
||||||
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
||||||
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ int main(void)
|
|||||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||||
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get normalized time played for current music stream
|
// Get normalized time played for current music stream
|
||||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ int main(void)
|
|||||||
|
|
||||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
||||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
||||||
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ int main ()
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
|
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
|
||||||
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
|
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
|
||||||
|
|
||||||
// Translate based on mouse right click
|
// Translate based on mouse right click
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ int main ()
|
|||||||
// Set the offset to where the mouse is
|
// Set the offset to where the mouse is
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
|
|
||||||
// Set the target to match, so that the camera maps the world space point
|
// Set the target to match, so that the camera maps the world space point
|
||||||
// under the cursor to the screen space point under the cursor at any zoom
|
// under the cursor to the screen space point under the cursor at any zoom
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ int main ()
|
|||||||
// Set the offset to where the mouse is
|
// Set the offset to where the mouse is
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
|
|
||||||
// Set the target to match, so that the camera maps the world space point
|
// Set the target to match, so that the camera maps the world space point
|
||||||
// under the cursor to the screen space point under the cursor at any zoom
|
// under the cursor to the screen space point under the cursor at any zoom
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ int main ()
|
|||||||
|
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
|
|
||||||
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
||||||
// just so we have something in the XY plane
|
// just so we have something in the XY plane
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
rlTranslatef(0, 25*50, 0);
|
rlTranslatef(0, 25*50, 0);
|
||||||
@@ -121,19 +121,19 @@ int main ()
|
|||||||
|
|
||||||
// Draw a reference circle
|
// Draw a reference circle
|
||||||
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
|
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
// Draw mouse reference
|
// Draw mouse reference
|
||||||
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
|
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
|
||||||
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
|
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
|
||||||
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
||||||
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
|
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
|
||||||
|
|
||||||
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
|
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
|
||||||
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
|
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
|
||||||
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
|
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -137,7 +137,7 @@ int main(void)
|
|||||||
|
|
||||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
|
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
|
||||||
DrawRectangleRec(playerRect, RED);
|
DrawRectangleRec(playerRect, RED);
|
||||||
|
|
||||||
DrawCircleV(player.position, 5.0f, GOLD);
|
DrawCircleV(player.position, 5.0f, GOLD);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* Addapted from the core_3d_camera_split_screen example:
|
* Addapted from the core_3d_camera_split_screen example:
|
||||||
* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
|
* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
@@ -81,9 +81,9 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginTextureMode(screenCamera1);
|
BeginTextureMode(screenCamera1);
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode2D(camera1);
|
BeginMode2D(camera1);
|
||||||
|
|
||||||
// Draw full scene with first camera
|
// Draw full scene with first camera
|
||||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||||
{
|
{
|
||||||
@@ -106,17 +106,17 @@ int main(void)
|
|||||||
DrawRectangleRec(player1, RED);
|
DrawRectangleRec(player1, RED);
|
||||||
DrawRectangleRec(player2, BLUE);
|
DrawRectangleRec(player2, BLUE);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||||
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
|
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginTextureMode(screenCamera2);
|
BeginTextureMode(screenCamera2);
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode2D(camera2);
|
BeginMode2D(camera2);
|
||||||
|
|
||||||
// Draw full scene with second camera
|
// Draw full scene with second camera
|
||||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||||
{
|
{
|
||||||
@@ -138,21 +138,21 @@ int main(void)
|
|||||||
|
|
||||||
DrawRectangleRec(player1, RED);
|
DrawRectangleRec(player1, RED);
|
||||||
DrawRectangleRec(player2, BLUE);
|
DrawRectangleRec(player2, BLUE);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||||
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
|
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||||
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||||
|
|
||||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
@@ -127,7 +127,7 @@ int main(void)
|
|||||||
UpdateCameraPro(&camera,
|
UpdateCameraPro(&camera,
|
||||||
(Vector3){
|
(Vector3){
|
||||||
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
||||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
||||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
||||||
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
||||||
0.0f // Move up-down
|
0.0f // Move up-down
|
||||||
|
@@ -51,7 +51,7 @@ int main(void)
|
|||||||
|
|
||||||
// Build a flipped rectangle the size of the split view to use for drawing later
|
// Build a flipped rectangle the size of the split view to use for drawing later
|
||||||
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
|
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
|
||||||
|
|
||||||
// Grid data
|
// Grid data
|
||||||
int count = 5;
|
int count = 5;
|
||||||
float spacing = 4;
|
float spacing = 4;
|
||||||
@@ -98,9 +98,9 @@ int main(void)
|
|||||||
// Draw Player1 view to the render texture
|
// Draw Player1 view to the render texture
|
||||||
BeginTextureMode(screenPlayer1);
|
BeginTextureMode(screenPlayer1);
|
||||||
ClearBackground(SKYBLUE);
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
BeginMode3D(cameraPlayer1);
|
BeginMode3D(cameraPlayer1);
|
||||||
|
|
||||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||||
|
|
||||||
@@ -116,20 +116,20 @@ int main(void)
|
|||||||
// Draw a cube at each player's position
|
// Draw a cube at each player's position
|
||||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||||
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
|
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
// Draw Player2 view to the render texture
|
||||||
BeginTextureMode(screenPlayer2);
|
BeginTextureMode(screenPlayer2);
|
||||||
ClearBackground(SKYBLUE);
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
BeginMode3D(cameraPlayer2);
|
BeginMode3D(cameraPlayer2);
|
||||||
|
|
||||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||||
|
|
||||||
@@ -145,21 +145,21 @@ int main(void)
|
|||||||
// Draw a cube at each player's position
|
// Draw a cube at each player's position
|
||||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||||
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
|
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||||
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||||
|
|
||||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ int main(void)
|
|||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
player.speed = 0;
|
player.speed = 0;
|
||||||
player.canJump = false;
|
player.canJump = false;
|
||||||
|
|
||||||
// Define environment elements (platforms)
|
// Define environment elements (platforms)
|
||||||
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
|
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
|
||||||
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
||||||
@@ -70,13 +70,13 @@ int main(void)
|
|||||||
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
|
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
|
||||||
camera.rotation = 0.0f;
|
camera.rotation = 0.0f;
|
||||||
camera.zoom = 1.0f;
|
camera.zoom = 1.0f;
|
||||||
|
|
||||||
// Automation events
|
// Automation events
|
||||||
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
|
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
|
||||||
SetAutomationEventList(&aelist);
|
SetAutomationEventList(&aelist);
|
||||||
bool eventRecording = false;
|
bool eventRecording = false;
|
||||||
bool eventPlaying = false;
|
bool eventPlaying = false;
|
||||||
|
|
||||||
unsigned int frameCounter = 0;
|
unsigned int frameCounter = 0;
|
||||||
unsigned int playFrameCounter = 0;
|
unsigned int playFrameCounter = 0;
|
||||||
unsigned int currentPlayFrame = 0;
|
unsigned int currentPlayFrame = 0;
|
||||||
@@ -90,7 +90,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
float deltaTime = 0.015f;//GetFrameTime();
|
float deltaTime = 0.015f;//GetFrameTime();
|
||||||
|
|
||||||
// Dropped files logic
|
// Dropped files logic
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
@@ -102,14 +102,14 @@ int main(void)
|
|||||||
{
|
{
|
||||||
UnloadAutomationEventList(aelist);
|
UnloadAutomationEventList(aelist);
|
||||||
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
|
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
|
||||||
|
|
||||||
eventRecording = false;
|
eventRecording = false;
|
||||||
|
|
||||||
// Reset scene state to play
|
// Reset scene state to play
|
||||||
eventPlaying = true;
|
eventPlaying = true;
|
||||||
playFrameCounter = 0;
|
playFrameCounter = 0;
|
||||||
currentPlayFrame = 0;
|
currentPlayFrame = 0;
|
||||||
|
|
||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
player.speed = 0;
|
player.speed = 0;
|
||||||
player.canJump = false;
|
player.canJump = false;
|
||||||
@@ -174,7 +174,7 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Events playing
|
// Events playing
|
||||||
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
||||||
// that can be set by the played event... but some other inputs could be affected
|
// that can be set by the played event... but some other inputs could be affected
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (eventPlaying)
|
if (eventPlaying)
|
||||||
@@ -228,7 +228,7 @@ int main(void)
|
|||||||
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
||||||
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Events management
|
// Events management
|
||||||
if (IsKeyPressed(KEY_S)) // Toggle events recording
|
if (IsKeyPressed(KEY_S)) // Toggle events recording
|
||||||
{
|
{
|
||||||
@@ -238,12 +238,12 @@ int main(void)
|
|||||||
{
|
{
|
||||||
StopAutomationEventRecording();
|
StopAutomationEventRecording();
|
||||||
eventRecording = false;
|
eventRecording = false;
|
||||||
|
|
||||||
ExportAutomationEventList(aelist, "automation.rae");
|
ExportAutomationEventList(aelist, "automation.rae");
|
||||||
|
|
||||||
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
|
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetAutomationEventBaseFrame(180);
|
SetAutomationEventBaseFrame(180);
|
||||||
StartAutomationEventRecording();
|
StartAutomationEventRecording();
|
||||||
@@ -293,7 +293,7 @@ int main(void)
|
|||||||
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
|
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
// Draw game controls
|
// Draw game controls
|
||||||
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
|
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
|
||||||
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
|
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
|
||||||
@@ -323,7 +323,7 @@ int main(void)
|
|||||||
|
|
||||||
if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
|
if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@@ -39,7 +39,7 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
|
||||||
|
|
||||||
// Custom timming variables
|
// Custom timming variables
|
||||||
@@ -48,11 +48,11 @@ int main(void)
|
|||||||
double updateDrawTime = 0.0; // Update + Draw time
|
double updateDrawTime = 0.0; // Update + Draw time
|
||||||
double waitTime = 0.0; // Wait time (if target fps required)
|
double waitTime = 0.0; // Wait time (if target fps required)
|
||||||
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
|
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
|
||||||
|
|
||||||
float timeCounter = 0.0f; // Accumulative time counter (seconds)
|
float timeCounter = 0.0f; // Accumulative time counter (seconds)
|
||||||
float position = 0.0f; // Circle position
|
float position = 0.0f; // Circle position
|
||||||
bool pause = false; // Pause control flag
|
bool pause = false; // Pause control flag
|
||||||
|
|
||||||
int targetFPS = 60; // Our initial target fps
|
int targetFPS = 60; // Our initial target fps
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -64,12 +64,12 @@ int main(void)
|
|||||||
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
||||||
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
|
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
|
||||||
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
|
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
|
||||||
|
|
||||||
if (targetFPS < 0) targetFPS = 0;
|
if (targetFPS < 0) targetFPS = 0;
|
||||||
|
|
||||||
if (!pause)
|
if (!pause)
|
||||||
@@ -91,12 +91,12 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
|
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
|
||||||
|
|
||||||
DrawCircle((int)position, GetScreenHeight()/2 - 25, 50, RED);
|
DrawCircle((int)position, GetScreenHeight()/2 - 25, 50, RED);
|
||||||
|
|
||||||
DrawText(TextFormat("%03.0f ms", timeCounter*1000.0f), (int)position - 40, GetScreenHeight()/2 - 100, 20, MAROON);
|
DrawText(TextFormat("%03.0f ms", timeCounter*1000.0f), (int)position - 40, GetScreenHeight()/2 - 100, 20, MAROON);
|
||||||
DrawText(TextFormat("PosX: %03.0f", position), (int)position - 50, GetScreenHeight()/2 + 40, 20, BLACK);
|
DrawText(TextFormat("PosX: %03.0f", position), (int)position - 50, GetScreenHeight()/2 + 40, 20, BLACK);
|
||||||
|
|
||||||
DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, DARKGRAY);
|
DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, DARKGRAY);
|
||||||
DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
|
DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
|
||||||
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
|
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
|
||||||
@@ -108,18 +108,18 @@ int main(void)
|
|||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
||||||
// Events polling, screen buffer swap and frame time control must be managed by the user
|
// Events polling, screen buffer swap and frame time control must be managed by the user
|
||||||
|
|
||||||
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
|
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
|
||||||
|
|
||||||
currentTime = GetTime();
|
currentTime = GetTime();
|
||||||
updateDrawTime = currentTime - previousTime;
|
updateDrawTime = currentTime - previousTime;
|
||||||
|
|
||||||
if (targetFPS > 0) // We want a fixed frame rate
|
if (targetFPS > 0) // We want a fixed frame rate
|
||||||
{
|
{
|
||||||
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
|
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
|
||||||
if (waitTime > 0.0)
|
if (waitTime > 0.0)
|
||||||
{
|
{
|
||||||
WaitTime((float)waitTime);
|
WaitTime((float)waitTime);
|
||||||
currentTime = GetTime();
|
currentTime = GetTime();
|
||||||
|
@@ -13,12 +13,10 @@
|
|||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
//------------------------------------------------------------------------------------
|
||||||
{
|
// Module functions declaration
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
//------------------------------------------------------------------------------------
|
||||||
Vector2 pos = (Vector2){x - size.x/2, y - size.y/2 };
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
@@ -31,10 +29,20 @@ int main(void)
|
|||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
||||||
SetWindowMinSize(450, 450);
|
SetWindowMinSize(450, 450);
|
||||||
|
|
||||||
|
int logicalGridDescY = 120;
|
||||||
|
int logicalGridLabelY = logicalGridDescY + 30;
|
||||||
|
int logicalGridTop = logicalGridLabelY + 30;
|
||||||
|
int logicalGridBottom = logicalGridTop + 80;
|
||||||
|
int pixelGridTop = logicalGridBottom - 20;
|
||||||
|
int pixelGridBottom = pixelGridTop + 80;
|
||||||
|
int pixelGridLabelY = pixelGridBottom + 30;
|
||||||
|
int pixelGridDescY = pixelGridLabelY + 30;
|
||||||
|
int cellSize = 50;
|
||||||
|
float cellSizePx = (float)cellSize;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -44,67 +52,60 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
int monitorCount = GetMonitorCount();
|
int monitorCount = GetMonitorCount();
|
||||||
if (monitorCount > 1 && IsKeyPressed(KEY_N)) {
|
|
||||||
SetWindowMonitor((GetCurrentMonitor() + 1) % monitorCount);
|
if ((monitorCount > 1) && IsKeyPressed(KEY_N))
|
||||||
|
{
|
||||||
|
SetWindowMonitor((GetCurrentMonitor() + 1)%monitorCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentMonitor = GetCurrentMonitor();
|
int currentMonitor = GetCurrentMonitor();
|
||||||
|
Vector2 dpiScale = GetWindowScaleDPI();
|
||||||
|
cellSizePx = ((float)cellSize)/dpiScale.x;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
Vector2 dpiScale = GetWindowScaleDPI();
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
int windowCenter = GetScreenWidth() / 2;
|
int windowCenter = GetScreenWidth()/2;
|
||||||
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
||||||
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 16, LIGHTGRAY);
|
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, LIGHTGRAY);
|
||||||
|
|
||||||
const int logicalGridDescY = 120;
|
|
||||||
const int logicalGridLabelY = logicalGridDescY + 30;
|
|
||||||
const int logicalGridTop = logicalGridLabelY + 30;
|
|
||||||
const int logicalGridBottom = logicalGridTop + 80;
|
|
||||||
const int pixelGridTop = logicalGridBottom - 20;
|
|
||||||
const int pixelGridBottom = pixelGridTop + 80;
|
|
||||||
const int pixelGridLabelY = pixelGridBottom + 30;
|
|
||||||
const int pixelGridDescY = pixelGridLabelY + 30;
|
|
||||||
|
|
||||||
const int cellSize = 50;
|
|
||||||
const float cellSizePx = ((float)cellSize) / dpiScale.x;
|
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
||||||
|
|
||||||
bool odd = true;
|
bool odd = true;
|
||||||
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
|
||||||
if (odd) {
|
{
|
||||||
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
||||||
}
|
|
||||||
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY);
|
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
|
||||||
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
odd = true;
|
odd = true;
|
||||||
const int minTextSpace = 30;
|
const int minTextSpace = 30;
|
||||||
int last_text_x = -minTextSpace;
|
int lastTextX = -minTextSpace;
|
||||||
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
|
||||||
int x = (int)(((float)i) / dpiScale.x);
|
{
|
||||||
if (odd) {
|
int x = (int)(((float)i)/dpiScale.x);
|
||||||
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
||||||
}
|
|
||||||
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
||||||
if (x - last_text_x >= minTextSpace) {
|
|
||||||
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 12, LIGHTGRAY);
|
if ((x - lastTextX) >= minTextSpace)
|
||||||
last_text_x = x;
|
{
|
||||||
|
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
|
||||||
|
lastTextX = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
||||||
|
|
||||||
{
|
const char *text = "Can you see this?";
|
||||||
const char *text = "Can you see this?";
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3);
|
Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
|
||||||
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5};
|
DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -117,3 +118,13 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module functions definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
||||||
|
{
|
||||||
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
||||||
|
Vector2 pos = (Vector2){ x - size.x/2, y - size.y/2 };
|
||||||
|
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
||||||
|
}
|
||||||
|
@@ -52,7 +52,7 @@ int main(void)
|
|||||||
isCursorHidden = 0;
|
isCursorHidden = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ballPosition = GetMousePosition();
|
ballPosition = GetMousePosition();
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
|
||||||
|
@@ -54,7 +54,7 @@ int main(void)
|
|||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = 0; i < tCount; ++i)
|
for (int i = 0; i < tCount; ++i)
|
||||||
{
|
{
|
||||||
// Make sure point is not (0, 0) as this means there is no touch for it
|
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
* Example originally created with raylib 5.0, last time updated with raylib 5.0
|
* Example originally created with raylib 5.0, last time updated with raylib 5.0
|
||||||
*
|
*
|
||||||
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
||||||
* lighter by oblerion (@oblerion) and
|
* lighter by oblerion (@oblerion) and
|
||||||
* reviewed by Ramon Santamaria (@raysan5) and
|
* reviewed by Ramon Santamaria (@raysan5) and
|
||||||
* improved by danilwhale (@danilwhale)
|
* improved by danilwhale (@danilwhale)
|
||||||
*
|
*
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires linking with pthreads library on MinGW,
|
* NOTE: This example requires linking with pthreads library on MinGW,
|
||||||
* it can be accomplished passing -static parameter to compiler
|
* it can be accomplished passing -static parameter to compiler
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 3.0
|
* Example originally created with raylib 2.5, last time updated with raylib 3.0
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Generates a random sequence
|
* raylib [core] example - generate random sequence
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
@@ -43,7 +43,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - Generates a random sequence");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random sequence");
|
||||||
|
|
||||||
int rectCount = 20;
|
int rectCount = 20;
|
||||||
float rectSize = (float)screenWidth/rectCount;
|
float rectSize = (float)screenWidth/rectCount;
|
||||||
@@ -118,8 +118,8 @@ int main(void)
|
|||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
static Color GenerateRandomColor()
|
static Color GenerateRandomColor()
|
||||||
{
|
{
|
||||||
Color color = {
|
Color color = {
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
GetRandomValue(0, 255),
|
GetRandomValue(0, 255),
|
||||||
255
|
255
|
||||||
@@ -138,20 +138,20 @@ static ColorRect *GenerateRandomColorRectSequence(float rectCount, float rectWid
|
|||||||
for (int i = 0; i < rectCount; i++)
|
for (int i = 0; i < rectCount; i++)
|
||||||
{
|
{
|
||||||
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
|
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
|
||||||
|
|
||||||
rectangles[i].c = GenerateRandomColor();
|
rectangles[i].c = GenerateRandomColor();
|
||||||
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
|
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRandomSequence(seq);
|
UnloadRandomSequence(seq);
|
||||||
|
|
||||||
return rectangles;
|
return rectangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
||||||
{
|
{
|
||||||
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
|
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
|
||||||
|
|
||||||
for (int i1 = 0; i1 < rectCount; i1++)
|
for (int i1 = 0; i1 < rectCount; i1++)
|
||||||
{
|
{
|
||||||
ColorRect *r1 = &rectangles[i1];
|
ColorRect *r1 = &rectangles[i1];
|
||||||
@@ -166,16 +166,16 @@ static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
|||||||
r2->r.height = tmp.r.height;
|
r2->r.height = tmp.r.height;
|
||||||
r2->r.y = tmp.r.y;
|
r2->r.y = tmp.r.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRandomSequence(seq);
|
UnloadRandomSequence(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
|
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
|
||||||
{
|
{
|
||||||
int spaceSize = MeasureText(" ", fontSize);
|
int spaceSize = MeasureText(" ", fontSize);
|
||||||
int pressSize = MeasureText("Press", fontSize);
|
int pressSize = MeasureText("Press", fontSize);
|
||||||
int keySize = MeasureText(key, fontSize);
|
int keySize = MeasureText(key, fontSize);
|
||||||
int textSize = MeasureText(text, fontSize);
|
int textSize = MeasureText(text, fontSize);
|
||||||
int textSizeCurrent = 0;
|
int textSizeCurrent = 0;
|
||||||
|
|
||||||
DrawText("Press", posX, posY, fontSize, color);
|
DrawText("Press", posX, posY, fontSize, color);
|
||||||
|
@@ -30,9 +30,9 @@ int main(void)
|
|||||||
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
||||||
|
|
||||||
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
unsigned int framesCounter = 0; // Variable used to count frames
|
unsigned int framesCounter = 0; // Variable used to count frames
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
|
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
|
||||||
* reviewed by Ramon Santamaria (@raysan5)
|
* reviewed by Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
|
@@ -127,7 +127,7 @@ int main(void)
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndVrStereoMode();
|
EndVrStereoMode();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
BeginShaderMode(distortion);
|
BeginShaderMode(distortion);
|
||||||
|
@@ -86,7 +86,7 @@ int main(void)
|
|||||||
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
||||||
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK); // Clear screen background
|
ClearBackground(BLACK); // Clear screen background
|
||||||
|
|
||||||
|
@@ -26,9 +26,9 @@ int main()
|
|||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close");
|
||||||
|
|
||||||
SetExitKey(KEY_NULL); // Disable KEY_ESCAPE to close window, X-button still works
|
SetExitKey(KEY_NULL); // Disable KEY_ESCAPE to close window, X-button still works
|
||||||
|
|
||||||
bool exitWindowRequested = false; // Flag to request window to exit
|
bool exitWindowRequested = false; // Flag to request window to exit
|
||||||
bool exitWindow = false; // Flag to set window to exit
|
bool exitWindow = false; // Flag to set window to exit
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ int main()
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Detect if X-button or KEY_ESCAPE have been pressed to close window
|
// Detect if X-button or KEY_ESCAPE have been pressed to close window
|
||||||
if (WindowShouldClose() || IsKeyPressed(KEY_ESCAPE)) exitWindowRequested = true;
|
if (WindowShouldClose() || IsKeyPressed(KEY_ESCAPE)) exitWindowRequested = true;
|
||||||
|
|
||||||
if (exitWindowRequested)
|
if (exitWindowRequested)
|
||||||
{
|
{
|
||||||
// A request for close window has been issued, we can save data before closing
|
// A request for close window has been issued, we can save data before closing
|
||||||
// or just show a message asking for confirmation
|
// or just show a message asking for confirmation
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_Y)) exitWindow = true;
|
if (IsKeyPressed(KEY_Y)) exitWindow = true;
|
||||||
else if (IsKeyPressed(KEY_N)) exitWindowRequested = false;
|
else if (IsKeyPressed(KEY_N)) exitWindowRequested = false;
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ int main(void)
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
|
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
|
||||||
|
|
||||||
DrawText(TextFormat("Cube position in screen space coordinates: [%i, %i]", (int)cubeScreenPosition.x, (int)cubeScreenPosition.y), 10, 10, 20, LIME);
|
DrawText(TextFormat("Cube position in screen space coordinates: [%i, %i]", (int)cubeScreenPosition.x, (int)cubeScreenPosition.y), 10, 10, 20, LIME);
|
||||||
DrawText("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);
|
DrawText("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);
|
||||||
|
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
*
|
*
|
||||||
********************************************************************************************
|
********************************************************************************************
|
||||||
*
|
*
|
||||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
* 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 and the scale of your models is
|
* in the same position as they would be in edit mode and the scale of your models is
|
||||||
* set to 0. Scaling can be done from the export menu.
|
* set to 0. Scaling can be done from the export menu.
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
@@ -85,17 +85,17 @@ int main(void)
|
|||||||
DrawGrid(10, 1.0f); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
// Draw order matters!
|
// Draw order matters!
|
||||||
if (distanceStatic > distanceRotating)
|
if (distanceStatic > distanceRotating)
|
||||||
{
|
{
|
||||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
* raylib [core] example - Using bones as socket for calculating the positioning of something
|
* raylib [core] example - Using bones as socket for calculating the positioning of something
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
*
|
*
|
||||||
* Example contributed by iP (@ipzaur) and reviewed by Ramon Santamaria (@raysan5)
|
* Example contributed by iP (@ipzaur) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
@@ -51,7 +51,7 @@ int main(void)
|
|||||||
LoadModel("resources/models/gltf/greenman_sword.glb"), // Index for the sword model is the same as BONE_SOCKET_HAND_R
|
LoadModel("resources/models/gltf/greenman_sword.glb"), // Index for the sword model is the same as BONE_SOCKET_HAND_R
|
||||||
LoadModel("resources/models/gltf/greenman_shield.glb") // Index for the shield model is the same as BONE_SOCKET_HAND_L
|
LoadModel("resources/models/gltf/greenman_shield.glb") // Index for the shield model is the same as BONE_SOCKET_HAND_L
|
||||||
};
|
};
|
||||||
|
|
||||||
bool showEquip[3] = { true, true, true }; // Toggle on/off equip
|
bool showEquip[3] = { true, true, true }; // Toggle on/off equip
|
||||||
|
|
||||||
// Load gltf model animations
|
// Load gltf model animations
|
||||||
@@ -63,7 +63,7 @@ int main(void)
|
|||||||
// indices of bones for sockets
|
// indices of bones for sockets
|
||||||
int boneSocketIndex[BONE_SOCKETS] = { -1, -1, -1 };
|
int boneSocketIndex[BONE_SOCKETS] = { -1, -1, -1 };
|
||||||
|
|
||||||
// search bones for sockets
|
// search bones for sockets
|
||||||
for (int i = 0; i < characterModel.boneCount; i++)
|
for (int i = 0; i < characterModel.boneCount; i++)
|
||||||
{
|
{
|
||||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hat"))
|
if (TextIsEqual(characterModel.bones[i].name, "socket_hat"))
|
||||||
@@ -71,13 +71,13 @@ int main(void)
|
|||||||
boneSocketIndex[BONE_SOCKET_HAT] = i;
|
boneSocketIndex[BONE_SOCKET_HAT] = i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_R"))
|
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_R"))
|
||||||
{
|
{
|
||||||
boneSocketIndex[BONE_SOCKET_HAND_R] = i;
|
boneSocketIndex[BONE_SOCKET_HAND_R] = i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_L"))
|
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_L"))
|
||||||
{
|
{
|
||||||
boneSocketIndex[BONE_SOCKET_HAND_L] = i;
|
boneSocketIndex[BONE_SOCKET_HAND_L] = i;
|
||||||
@@ -99,7 +99,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||||
|
|
||||||
// Rotate character
|
// Rotate character
|
||||||
if (IsKeyDown(KEY_F)) angle = (angle + 1)%360;
|
if (IsKeyDown(KEY_F)) angle = (angle + 1)%360;
|
||||||
else if (IsKeyDown(KEY_H)) angle = (360 + angle - 1)%360;
|
else if (IsKeyDown(KEY_H)) angle = (360 + angle - 1)%360;
|
||||||
@@ -112,7 +112,7 @@ int main(void)
|
|||||||
if (IsKeyPressed(KEY_ONE)) showEquip[BONE_SOCKET_HAT] = !showEquip[BONE_SOCKET_HAT];
|
if (IsKeyPressed(KEY_ONE)) showEquip[BONE_SOCKET_HAT] = !showEquip[BONE_SOCKET_HAT];
|
||||||
if (IsKeyPressed(KEY_TWO)) showEquip[BONE_SOCKET_HAND_R] = !showEquip[BONE_SOCKET_HAND_R];
|
if (IsKeyPressed(KEY_TWO)) showEquip[BONE_SOCKET_HAND_R] = !showEquip[BONE_SOCKET_HAND_R];
|
||||||
if (IsKeyPressed(KEY_THREE)) showEquip[BONE_SOCKET_HAND_L] = !showEquip[BONE_SOCKET_HAND_L];
|
if (IsKeyPressed(KEY_THREE)) showEquip[BONE_SOCKET_HAND_L] = !showEquip[BONE_SOCKET_HAND_L];
|
||||||
|
|
||||||
// Update model animation
|
// Update model animation
|
||||||
ModelAnimation anim = modelAnimations[animIndex];
|
ModelAnimation anim = modelAnimations[animIndex];
|
||||||
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
|
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
|
||||||
@@ -140,7 +140,7 @@ int main(void)
|
|||||||
Transform *transform = &anim.framePoses[animCurrentFrame][boneSocketIndex[i]];
|
Transform *transform = &anim.framePoses[animCurrentFrame][boneSocketIndex[i]];
|
||||||
Quaternion inRotation = characterModel.bindPose[boneSocketIndex[i]].rotation;
|
Quaternion inRotation = characterModel.bindPose[boneSocketIndex[i]].rotation;
|
||||||
Quaternion outRotation = transform->rotation;
|
Quaternion outRotation = transform->rotation;
|
||||||
|
|
||||||
// Calculate socket rotation (angle between bone in initial pose and same bone in current animation frame)
|
// Calculate socket rotation (angle between bone in initial pose and same bone in current animation frame)
|
||||||
Quaternion rotate = QuaternionMultiply(outRotation, QuaternionInvert(inRotation));
|
Quaternion rotate = QuaternionMultiply(outRotation, QuaternionInvert(inRotation));
|
||||||
Matrix matrixTransform = QuaternionToMatrix(rotate);
|
Matrix matrixTransform = QuaternionToMatrix(rotate);
|
||||||
@@ -148,7 +148,7 @@ int main(void)
|
|||||||
matrixTransform = MatrixMultiply(matrixTransform, MatrixTranslate(transform->translation.x, transform->translation.y, transform->translation.z));
|
matrixTransform = MatrixMultiply(matrixTransform, MatrixTranslate(transform->translation.x, transform->translation.y, transform->translation.z));
|
||||||
// Transform the socket using the transform of the character (angle and translate)
|
// Transform the socket using the transform of the character (angle and translate)
|
||||||
matrixTransform = MatrixMultiply(matrixTransform, characterModel.transform);
|
matrixTransform = MatrixMultiply(matrixTransform, characterModel.transform);
|
||||||
|
|
||||||
// Draw mesh at socket position with socket angle rotation
|
// Draw mesh at socket position with socket angle rotation
|
||||||
DrawMesh(equipModel[i].meshes[0], equipModel[i].materials[1], matrixTransform);
|
DrawMesh(equipModel[i].meshes[0], equipModel[i].materials[1], matrixTransform);
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModelAnimations(modelAnimations, animsCount);
|
UnloadModelAnimations(modelAnimations, animsCount);
|
||||||
UnloadModel(characterModel); // Unload character model and meshes/material
|
UnloadModel(characterModel); // Unload character model and meshes/material
|
||||||
|
|
||||||
// Unload equipment model and meshes/material
|
// Unload equipment model and meshes/material
|
||||||
for (int i = 0; i < BONE_SOCKETS; i++) UnloadModel(equipModel[i]);
|
for (int i = 0; i < BONE_SOCKETS; i++) UnloadModel(equipModel[i]);
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ int main(void)
|
|||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
// Load texture to be applied to the cubes sides
|
// Load texture to be applied to the cubes sides
|
||||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ int main(void)
|
|||||||
DrawCubeTexture(texture, (Vector3){ -2.0f, 2.0f, 0.0f }, 2.0f, 4.0f, 2.0f, WHITE);
|
DrawCubeTexture(texture, (Vector3){ -2.0f, 2.0f, 0.0f }, 2.0f, 4.0f, 2.0f, WHITE);
|
||||||
|
|
||||||
// Draw cube with an applied texture, but only a defined rectangle piece of the texture
|
// Draw cube with an applied texture, but only a defined rectangle piece of the texture
|
||||||
DrawCubeTextureRec(texture, (Rectangle){ 0.0f, texture.height/2.0f, texture.width/2.0f, texture.height/2.0f },
|
DrawCubeTextureRec(texture, (Rectangle){ 0.0f, texture.height/2.0f, texture.width/2.0f, texture.height/2.0f },
|
||||||
(Vector3){ 2.0f, 1.0f, 0.0f }, 2.0f, 2.0f, 2.0f, WHITE);
|
(Vector3){ 2.0f, 1.0f, 0.0f }, 2.0f, 2.0f, 2.0f, WHITE);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
@@ -85,7 +85,7 @@ int main(void)
|
|||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texture); // Unload texture
|
UnloadTexture(texture); // Unload texture
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, f
|
|||||||
rlSetTexture(texture.id);
|
rlSetTexture(texture.id);
|
||||||
|
|
||||||
// We calculate the normalized texture coordinates for the desired texture-source-rectangle
|
// We calculate the normalized texture coordinates for the desired texture-source-rectangle
|
||||||
// It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
|
// It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
|
||||||
rlBegin(RL_QUADS);
|
rlBegin(RL_QUADS);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
* raylib [core] example - Doing skinning on the gpu using a vertex shader
|
* raylib [core] example - Doing skinning on the gpu using a vertex shader
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
*
|
*
|
||||||
* Example contributed by Daniel Holden (@orangeduck) and reviewed by Ramon Santamaria (@raysan5)
|
* Example contributed by Daniel Holden (@orangeduck) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024-2025 Daniel Holden (@orangeduck)
|
* Copyright (c) 2024-2025 Daniel Holden (@orangeduck)
|
||||||
*
|
*
|
||||||
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
|
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
@@ -49,13 +49,13 @@ int main(void)
|
|||||||
|
|
||||||
// Load gltf model
|
// Load gltf model
|
||||||
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
|
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
|
||||||
|
|
||||||
// Load skinning shader
|
// Load skinning shader
|
||||||
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||||
|
|
||||||
characterModel.materials[1].shader = skinningShader;
|
characterModel.materials[1].shader = skinningShader;
|
||||||
|
|
||||||
// Load gltf model animations
|
// Load gltf model animations
|
||||||
int animsCount = 0;
|
int animsCount = 0;
|
||||||
unsigned int animIndex = 0;
|
unsigned int animIndex = 0;
|
||||||
@@ -75,7 +75,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||||
|
|
||||||
// Select current animation
|
// Select current animation
|
||||||
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
|
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
|
||||||
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
|
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
|
||||||
@@ -94,12 +94,12 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
// Draw character mesh, pose calculation is done in shader (GPU skinning)
|
// Draw character mesh, pose calculation is done in shader (GPU skinning)
|
||||||
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
|
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY);
|
DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY);
|
||||||
@@ -113,7 +113,7 @@ int main(void)
|
|||||||
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
|
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
|
||||||
UnloadModel(characterModel); // Unload model and meshes/material
|
UnloadModel(characterModel); // Unload model and meshes/material
|
||||||
UnloadShader(skinningShader); // Unload GPU skinning shader
|
UnloadShader(skinningShader); // Unload GPU skinning shader
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ int main(void)
|
|||||||
// Load gltf model
|
// Load gltf model
|
||||||
Model model = LoadModel("resources/models/gltf/robot.glb");
|
Model model = LoadModel("resources/models/gltf/robot.glb");
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
// Load gltf model animations
|
// Load gltf model animations
|
||||||
int animsCount = 0;
|
int animsCount = 0;
|
||||||
unsigned int animIndex = 0;
|
unsigned int animIndex = 0;
|
||||||
|
@@ -47,7 +47,7 @@ int main(void)
|
|||||||
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
|
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
|
||||||
models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
|
models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
|
||||||
models[8] = LoadModelFromMesh(GenMeshCustom());
|
models[8] = LoadModelFromMesh(GenMeshCustom());
|
||||||
|
|
||||||
// NOTE: Generated meshes could be exported using ExportMesh()
|
// NOTE: Generated meshes could be exported using ExportMesh()
|
||||||
|
|
||||||
// Set checked texture as default diffuse component for all models material
|
// Set checked texture as default diffuse component for all models material
|
||||||
|
@@ -137,7 +137,7 @@ int main(void)
|
|||||||
RayCollision meshHitInfo = { 0 };
|
RayCollision meshHitInfo = { 0 };
|
||||||
for (int m = 0; m < tower.meshCount; m++)
|
for (int m = 0; m < tower.meshCount; m++)
|
||||||
{
|
{
|
||||||
// NOTE: We consider the model.transform for the collision check but
|
// NOTE: We consider the model.transform for the collision check but
|
||||||
// it can be checked against any transform Matrix, used when checking against same
|
// it can be checked against any transform Matrix, used when checking against same
|
||||||
// model drawn multiple times with multiple transforms
|
// model drawn multiple times with multiple transforms
|
||||||
meshHitInfo = GetRayCollisionMesh(ray, tower.meshes[m], tower.transform);
|
meshHitInfo = GetRayCollisionMesh(ray, tower.meshes[m], tower.transform);
|
||||||
@@ -145,7 +145,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Save the closest hit mesh
|
// Save the closest hit mesh
|
||||||
if ((!collision.hit) || (collision.distance > meshHitInfo.distance)) collision = meshHitInfo;
|
if ((!collision.hit) || (collision.distance > meshHitInfo.distance)) collision = meshHitInfo;
|
||||||
|
|
||||||
break; // Stop once one mesh collision is detected, the colliding mesh is m
|
break; // Stop once one mesh collision is detected, the colliding mesh is m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ int main()
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - point rendering");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - point rendering");
|
||||||
|
|
||||||
Camera camera = {
|
Camera camera = {
|
||||||
@@ -50,10 +50,10 @@ int main()
|
|||||||
bool useDrawModelPoints = true;
|
bool useDrawModelPoints = true;
|
||||||
bool numPointsChanged = false;
|
bool numPointsChanged = false;
|
||||||
int numPoints = 1000;
|
int numPoints = 1000;
|
||||||
|
|
||||||
Mesh mesh = GenMeshPoints(numPoints);
|
Mesh mesh = GenMeshPoints(numPoints);
|
||||||
Model model = LoadModelFromMesh(mesh);
|
Model model = LoadModelFromMesh(mesh);
|
||||||
|
|
||||||
//SetTargetFPS(60);
|
//SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -114,14 +114,14 @@ int main()
|
|||||||
.b = mesh.colors[i*4 + 2],
|
.b = mesh.colors[i*4 + 2],
|
||||||
.a = mesh.colors[i*4 + 3],
|
.a = mesh.colors[i*4 + 3],
|
||||||
};
|
};
|
||||||
|
|
||||||
DrawPoint3D(pos, color);
|
DrawPoint3D(pos, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a unit sphere for reference
|
// Draw a unit sphere for reference
|
||||||
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
|
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// Draw UI text
|
// Draw UI text
|
||||||
@@ -129,12 +129,12 @@ int main()
|
|||||||
DrawText("Up - increase points", 20, 70, 20, WHITE);
|
DrawText("Up - increase points", 20, 70, 20, WHITE);
|
||||||
DrawText("Down - decrease points", 20, 100, 20, WHITE);
|
DrawText("Down - decrease points", 20, 100, 20, WHITE);
|
||||||
DrawText("Space - drawing function", 20, 130, 20, WHITE);
|
DrawText("Space - drawing function", 20, 130, 20, WHITE);
|
||||||
|
|
||||||
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
|
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
|
||||||
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
|
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ int main()
|
|||||||
// Generate a spherical point cloud
|
// Generate a spherical point cloud
|
||||||
static Mesh GenMeshPoints(int numPoints)
|
static Mesh GenMeshPoints(int numPoints)
|
||||||
{
|
{
|
||||||
Mesh mesh = {
|
Mesh mesh = {
|
||||||
.triangleCount = 1,
|
.triangleCount = 1,
|
||||||
.vertexCount = numPoints,
|
.vertexCount = numPoints,
|
||||||
.vertices = (float *)MemAlloc(numPoints*3*sizeof(float)),
|
.vertices = (float *)MemAlloc(numPoints*3*sizeof(float)),
|
||||||
@@ -164,13 +164,13 @@ static Mesh GenMeshPoints(int numPoints)
|
|||||||
float theta = ((float)PI*rand())/RAND_MAX;
|
float theta = ((float)PI*rand())/RAND_MAX;
|
||||||
float phi = (2.0f*PI*rand())/RAND_MAX;
|
float phi = (2.0f*PI*rand())/RAND_MAX;
|
||||||
float r = (10.0f*rand())/RAND_MAX;
|
float r = (10.0f*rand())/RAND_MAX;
|
||||||
|
|
||||||
mesh.vertices[i*3 + 0] = r*sinf(theta)*cosf(phi);
|
mesh.vertices[i*3 + 0] = r*sinf(theta)*cosf(phi);
|
||||||
mesh.vertices[i*3 + 1] = r*sinf(theta)*sinf(phi);
|
mesh.vertices[i*3 + 1] = r*sinf(theta)*sinf(phi);
|
||||||
mesh.vertices[i*3 + 2] = r*cosf(theta);
|
mesh.vertices[i*3 + 2] = r*cosf(theta);
|
||||||
|
|
||||||
Color color = ColorFromHSV(r*360.0f, 1.0f, 1.0f);
|
Color color = ColorFromHSV(r*360.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
mesh.colors[i*4 + 0] = color.r;
|
mesh.colors[i*4 + 0] = color.r;
|
||||||
mesh.colors[i*4 + 1] = color.g;
|
mesh.colors[i*4 + 1] = color.g;
|
||||||
mesh.colors[i*4 + 2] = color.b;
|
mesh.colors[i*4 + 2] = color.b;
|
||||||
@@ -179,6 +179,6 @@ static Mesh GenMeshPoints(int numPoints)
|
|||||||
|
|
||||||
// Upload mesh data from CPU (RAM) to GPU (VRAM) memory
|
// Upload mesh data from CPU (RAM) to GPU (VRAM) memory
|
||||||
UploadMesh(&mesh, false);
|
UploadMesh(&mesh, false);
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ int main(void)
|
|||||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
char skyboxFileName[256] = { 0 };
|
char skyboxFileName[256] = { 0 };
|
||||||
|
|
||||||
if (useHDR)
|
if (useHDR)
|
||||||
{
|
{
|
||||||
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
|
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
|
||||||
@@ -116,7 +116,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Unload current cubemap texture to load new one
|
// Unload current cubemap texture to load new one
|
||||||
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
||||||
|
|
||||||
if (useHDR)
|
if (useHDR)
|
||||||
{
|
{
|
||||||
// Load HDR panorama (sphere) texture
|
// Load HDR panorama (sphere) texture
|
||||||
@@ -124,7 +124,7 @@ int main(void)
|
|||||||
|
|
||||||
// Generate cubemap from panorama texture
|
// Generate cubemap from panorama texture
|
||||||
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
||||||
|
|
||||||
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
|
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -223,7 +223,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
|
|||||||
};
|
};
|
||||||
|
|
||||||
rlViewport(0, 0, size, size); // Set viewport to current fbo dimensions
|
rlViewport(0, 0, size, size); // Set viewport to current fbo dimensions
|
||||||
|
|
||||||
// Activate and enable texture for drawing to cubemap faces
|
// Activate and enable texture for drawing to cubemap faces
|
||||||
rlActiveTextureSlot(0);
|
rlActiveTextureSlot(0);
|
||||||
rlEnableTexture(panorama.id);
|
rlEnableTexture(panorama.id);
|
||||||
@@ -232,7 +232,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
|
|||||||
{
|
{
|
||||||
// Set the view matrix for the current cube face
|
// Set the view matrix for the current cube face
|
||||||
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
||||||
|
|
||||||
// Select the current cubemap face attachment for the fbo
|
// Select the current cubemap face attachment for the fbo
|
||||||
// WARNING: This function by default enables->attach->disables fbo!!!
|
// WARNING: This function by default enables->attach->disables fbo!!!
|
||||||
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0);
|
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0);
|
||||||
|
@@ -32,7 +32,7 @@ int main(void)
|
|||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - tesseract view");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - tesseract view");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
|
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
|
||||||
@@ -43,16 +43,16 @@ int main(void)
|
|||||||
|
|
||||||
// Find the coordinates by setting XYZW to +-1
|
// Find the coordinates by setting XYZW to +-1
|
||||||
Vector4 tesseract[16] = {
|
Vector4 tesseract[16] = {
|
||||||
{ 1, 1, 1, 1 }, { 1, 1, 1, -1 },
|
{ 1, 1, 1, 1 }, { 1, 1, 1, -1 },
|
||||||
{ 1, 1, -1, 1 }, { 1, 1, -1, -1 },
|
{ 1, 1, -1, 1 }, { 1, 1, -1, -1 },
|
||||||
{ 1, -1, 1, 1 }, { 1, -1, 1, -1 },
|
{ 1, -1, 1, 1 }, { 1, -1, 1, -1 },
|
||||||
{ 1, -1, -1, 1 }, { 1, -1, -1, -1 },
|
{ 1, -1, -1, 1 }, { 1, -1, -1, -1 },
|
||||||
{ -1, 1, 1, 1 }, { -1, 1, 1, -1 },
|
{ -1, 1, 1, 1 }, { -1, 1, 1, -1 },
|
||||||
{ -1, 1, -1, 1 }, { -1, 1, -1, -1 },
|
{ -1, 1, -1, 1 }, { -1, 1, -1, -1 },
|
||||||
{ -1, -1, 1, 1 }, { -1, -1, 1, -1 },
|
{ -1, -1, 1, 1 }, { -1, -1, 1, -1 },
|
||||||
{ -1, -1, -1, 1 }, { -1, -1, -1, -1 },
|
{ -1, -1, -1, 1 }, { -1, -1, -1, -1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
Vector3 transformed[16] = { 0 };
|
Vector3 transformed[16] = { 0 };
|
||||||
float wValues[16] = { 0 };
|
float wValues[16] = { 0 };
|
||||||
@@ -66,7 +66,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
rotation = DEG2RAD*45.0f*GetTime();
|
rotation = DEG2RAD*45.0f*GetTime();
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
Vector4 p = tesseract[i];
|
Vector4 p = tesseract[i];
|
||||||
@@ -92,9 +92,9 @@ int main(void)
|
|||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,7 @@ int main()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Pick a color with a hue depending on cube position for the rainbow color effect
|
// Pick a color with a hue depending on cube position for the rainbow color effect
|
||||||
// NOTE: This function is quite costly to be done per cube and frame,
|
// NOTE: This function is quite costly to be done per cube and frame,
|
||||||
// pre-catching the results into a separate array could improve performance
|
// pre-catching the results into a separate array could improve performance
|
||||||
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);
|
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);
|
||||||
|
|
||||||
|
@@ -30,18 +30,18 @@
|
|||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
|
||||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
#include "glad_gles2.h" // Required for: OpenGL functionality
|
#include "glad_gles2.h" // Required for: OpenGL functionality
|
||||||
#define glGenVertexArrays glGenVertexArraysOES
|
#define glGenVertexArrays glGenVertexArraysOES
|
||||||
#define glBindVertexArray glBindVertexArrayOES
|
#define glBindVertexArray glBindVertexArrayOES
|
||||||
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||||
#define GLSL_VERSION 100
|
#define GLSL_VERSION 100
|
||||||
#else
|
#else
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#define GL_SILENCE_DEPRECATION // Silence Opengl API deprecation warnings
|
#define GL_SILENCE_DEPRECATION // Silence Opengl API deprecation warnings
|
||||||
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
|
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
|
||||||
#include <OpenGL/gl3ext.h> // OpenGL 3 extensions library for OSX
|
#include <OpenGL/gl3ext.h> // OpenGL 3 extensions library for OSX
|
||||||
#else
|
#else
|
||||||
#include "glad.h" // Required for: OpenGL functionality
|
#include "glad.h" // Required for: OpenGL functionality
|
||||||
#endif
|
#endif
|
||||||
#define GLSL_VERSION 330
|
#define GLSL_VERSION 330
|
||||||
#endif
|
#endif
|
||||||
@@ -71,7 +71,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib - point particles");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - point particles");
|
||||||
|
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/point_particle.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/point_particle.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/point_particle.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/point_particle.fs", GLSL_VERSION));
|
||||||
@@ -86,13 +86,13 @@ int main(void)
|
|||||||
{
|
{
|
||||||
particles[i].x = (float)GetRandomValue(20, screenWidth - 20);
|
particles[i].x = (float)GetRandomValue(20, screenWidth - 20);
|
||||||
particles[i].y = (float)GetRandomValue(50, screenHeight - 20);
|
particles[i].y = (float)GetRandomValue(50, screenHeight - 20);
|
||||||
|
|
||||||
// Give each particle a slightly different period. But don't spread it to much.
|
// Give each particle a slightly different period. But don't spread it to much.
|
||||||
// This way the particles line up every so often and you get a glimps of what is going on.
|
// This way the particles line up every so often and you get a glimps of what is going on.
|
||||||
particles[i].period = (float)GetRandomValue(10, 30)/10.0f;
|
particles[i].period = (float)GetRandomValue(10, 30)/10.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a plain OpenGL vertex buffer with the data and an vertex array object
|
// Create a plain OpenGL vertex buffer with the data and an vertex array object
|
||||||
// that feeds the data from the buffer into the vertexPosition shader attribute.
|
// that feeds the data from the buffer into the vertexPosition shader attribute.
|
||||||
GLuint vao = 0;
|
GLuint vao = 0;
|
||||||
GLuint vbo = 0;
|
GLuint vbo = 0;
|
||||||
@@ -125,13 +125,13 @@ int main(void)
|
|||||||
|
|
||||||
DrawRectangle(10, 10, 210, 30, MAROON);
|
DrawRectangle(10, 10, 210, 30, MAROON);
|
||||||
DrawText(TextFormat("%zu particles in one vertex buffer", MAX_PARTICLES), 20, 20, 10, RAYWHITE);
|
DrawText(TextFormat("%zu particles in one vertex buffer", MAX_PARTICLES), 20, 20, 10, RAYWHITE);
|
||||||
|
|
||||||
rlDrawRenderBatchActive(); // Draw iternal buffers data (previous draw calls)
|
rlDrawRenderBatchActive(); // Draw iternal buffers data (previous draw calls)
|
||||||
|
|
||||||
// Switch to plain OpenGL
|
// Switch to plain OpenGL
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
glUseProgram(shader.id);
|
glUseProgram(shader.id);
|
||||||
|
|
||||||
glUniform1f(currentTimeLoc, GetTime());
|
glUniform1f(currentTimeLoc, GetTime());
|
||||||
|
|
||||||
Vector4 color = ColorNormalize((Color){ 255, 0, 0, 128 });
|
Vector4 color = ColorNormalize((Color){ 255, 0, 0, 128 });
|
||||||
@@ -139,18 +139,18 @@ int main(void)
|
|||||||
|
|
||||||
// Get the current modelview and projection matrix so the particle system is displayed and transformed
|
// Get the current modelview and projection matrix so the particle system is displayed and transformed
|
||||||
Matrix modelViewProjection = MatrixMultiply(rlGetMatrixModelview(), rlGetMatrixProjection());
|
Matrix modelViewProjection = MatrixMultiply(rlGetMatrixModelview(), rlGetMatrixProjection());
|
||||||
|
|
||||||
glUniformMatrix4fv(shader.locs[SHADER_LOC_MATRIX_MVP], 1, false, MatrixToFloat(modelViewProjection));
|
glUniformMatrix4fv(shader.locs[SHADER_LOC_MATRIX_MVP], 1, false, MatrixToFloat(modelViewProjection));
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
glDrawArrays(GL_POINTS, 0, MAX_PARTICLES);
|
glDrawArrays(GL_POINTS, 0, MAX_PARTICLES);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
DrawFPS(screenWidth - 100, 10);
|
DrawFPS(screenWidth - 100, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
* Copyright (c) 2023-2025 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2023-2025 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
@@ -32,7 +32,7 @@ int main(void)
|
|||||||
Vector2 v0 = { screenWidth/2, screenHeight/2 };
|
Vector2 v0 = { screenWidth/2, screenHeight/2 };
|
||||||
Vector2 v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f });
|
Vector2 v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f });
|
||||||
Vector2 v2 = { 0 }; // Updated with mouse position
|
Vector2 v2 = { 0 }; // Updated with mouse position
|
||||||
|
|
||||||
float angle = 0.0f; // Angle in degrees
|
float angle = 0.0f; // Angle in degrees
|
||||||
int angleMode = 0; // 0-Vector2Angle(), 1-Vector2LineAngle()
|
int angleMode = 0; // 0-Vector2Angle(), 1-Vector2LineAngle()
|
||||||
|
|
||||||
@@ -47,12 +47,12 @@ int main(void)
|
|||||||
float startangle = 0.0f;
|
float startangle = 0.0f;
|
||||||
|
|
||||||
if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1)*RAD2DEG;
|
if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1)*RAD2DEG;
|
||||||
if (angleMode == 1) startangle = 0.0f;
|
if (angleMode == 1) startangle = 0.0f;
|
||||||
|
|
||||||
v2 = GetMousePosition();
|
v2 = GetMousePosition();
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) angleMode = !angleMode;
|
if (IsKeyPressed(KEY_SPACE)) angleMode = !angleMode;
|
||||||
|
|
||||||
if ((angleMode == 0) && IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) v1 = GetMousePosition();
|
if ((angleMode == 0) && IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) v1 = GetMousePosition();
|
||||||
|
|
||||||
if (angleMode == 0)
|
if (angleMode == 0)
|
||||||
@@ -75,12 +75,12 @@ int main(void)
|
|||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
if (angleMode == 0)
|
if (angleMode == 0)
|
||||||
{
|
{
|
||||||
DrawText("MODE 0: Angle between V1 and V2", 10, 10, 20, BLACK);
|
DrawText("MODE 0: Angle between V1 and V2", 10, 10, 20, BLACK);
|
||||||
DrawText("Right Click to Move V2", 10, 30, 20, DARKGRAY);
|
DrawText("Right Click to Move V2", 10, 30, 20, DARKGRAY);
|
||||||
|
|
||||||
DrawLineEx(v0, v1, 2.0f, BLACK);
|
DrawLineEx(v0, v1, 2.0f, BLACK);
|
||||||
DrawLineEx(v0, v2, 2.0f, RED);
|
DrawLineEx(v0, v2, 2.0f, RED);
|
||||||
|
|
||||||
@@ -89,13 +89,13 @@ int main(void)
|
|||||||
else if (angleMode == 1)
|
else if (angleMode == 1)
|
||||||
{
|
{
|
||||||
DrawText("MODE 1: Angle formed by line V1 to V2", 10, 10, 20, BLACK);
|
DrawText("MODE 1: Angle formed by line V1 to V2", 10, 10, 20, BLACK);
|
||||||
|
|
||||||
DrawLine(0, screenHeight/2, screenWidth, screenHeight/2, LIGHTGRAY);
|
DrawLine(0, screenHeight/2, screenWidth, screenHeight/2, LIGHTGRAY);
|
||||||
DrawLineEx(v0, v2, 2.0f, RED);
|
DrawLineEx(v0, v2, 2.0f, RED);
|
||||||
|
|
||||||
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));
|
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("v0", v0.x, v0.y, 10, DARKGRAY);
|
DrawText("v0", v0.x, v0.y, 10, DARKGRAY);
|
||||||
|
|
||||||
// If the line from v0 to v1 would overlap the text, move it's position up 10
|
// If the line from v0 to v1 would overlap the text, move it's position up 10
|
||||||
@@ -110,7 +110,7 @@ int main(void)
|
|||||||
|
|
||||||
DrawText("Press SPACE to change MODE", 460, 10, 20, DARKGRAY);
|
DrawText("Press SPACE to change MODE", 460, 10, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("ANGLE: %2.2f", angle), 10, 70, 20, LIME);
|
DrawText(TextFormat("ANGLE: %2.2f", angle), 10, 70, 20, LIME);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -137,7 +137,7 @@ int main(void)
|
|||||||
|
|
||||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||||
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
||||||
|
|
||||||
// WARNING: OpenGL 3.3 Core profile only
|
// WARNING: OpenGL 3.3 Core profile only
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
|
@@ -59,10 +59,10 @@ int main(void)
|
|||||||
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
||||||
// Get some required shader locations
|
// Get some required shader locations
|
||||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||||
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||||
// no need to get the location again if using that uniform name
|
// no need to get the location again if using that uniform name
|
||||||
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||||
|
|
||||||
// Ambient light level (some basic lighting)
|
// Ambient light level (some basic lighting)
|
||||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.1f, 0.1f, 0.1f, 1.0f }, SHADER_UNIFORM_VEC4);
|
SetShaderValue(shader, ambientLoc, (float[4]){ 0.1f, 0.1f, 0.1f, 1.0f }, SHADER_UNIFORM_VEC4);
|
||||||
@@ -87,13 +87,13 @@ int main(void)
|
|||||||
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
||||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||||
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
// Check key inputs to enable/disable lights
|
// Check key inputs to enable/disable lights
|
||||||
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
||||||
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
||||||
if (IsKeyPressed(KEY_G)) { lights[2].enabled = !lights[2].enabled; }
|
if (IsKeyPressed(KEY_G)) { lights[2].enabled = !lights[2].enabled; }
|
||||||
if (IsKeyPressed(KEY_B)) { lights[3].enabled = !lights[3].enabled; }
|
if (IsKeyPressed(KEY_B)) { lights[3].enabled = !lights[3].enabled; }
|
||||||
|
|
||||||
// Update light values (actually, only enable/disable them)
|
// Update light values (actually, only enable/disable them)
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
|
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@@ -13,8 +13,8 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2023-2025 Afan OLOVCIC (@_DevDad)
|
* Copyright (c) 2023-2025 Afan OLOVCIC (@_DevDad)
|
||||||
*
|
*
|
||||||
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
|
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
|
||||||
* licensed under Creative Commons Attribution-NonCommercial
|
* licensed under Creative Commons Attribution-NonCommercial
|
||||||
* (http://creativecommons.org/licenses/by-nc/4.0/)
|
* (http://creativecommons.org/licenses/by-nc/4.0/)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
@@ -105,7 +105,7 @@ int main()
|
|||||||
// shader already takes care of it accordingly
|
// shader already takes care of it accordingly
|
||||||
shader.locs[SHADER_LOC_MAP_METALNESS] = GetShaderLocation(shader, "mraMap");
|
shader.locs[SHADER_LOC_MAP_METALNESS] = GetShaderLocation(shader, "mraMap");
|
||||||
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
||||||
// WARNING: Similar to the MRA map, the emissive map packs different information
|
// WARNING: Similar to the MRA map, the emissive map packs different information
|
||||||
// into a single texture: it stores height and emission data
|
// into a single texture: it stores height and emission data
|
||||||
// It is binded to SHADER_LOC_MAP_EMISSION location an properly processed on shader
|
// It is binded to SHADER_LOC_MAP_EMISSION location an properly processed on shader
|
||||||
shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "emissiveMap");
|
shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "emissiveMap");
|
||||||
@@ -153,7 +153,7 @@ int main()
|
|||||||
car.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/old_car_mra.png");
|
car.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/old_car_mra.png");
|
||||||
car.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/old_car_n.png");
|
car.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/old_car_n.png");
|
||||||
car.materials[0].maps[MATERIAL_MAP_EMISSION].texture = LoadTexture("resources/old_car_e.png");
|
car.materials[0].maps[MATERIAL_MAP_EMISSION].texture = LoadTexture("resources/old_car_e.png");
|
||||||
|
|
||||||
// Load floor model mesh and assign material parameters
|
// Load floor model mesh and assign material parameters
|
||||||
// NOTE: A basic plane shape can be generated instead of being loaded from a model file
|
// NOTE: A basic plane shape can be generated instead of being loaded from a model file
|
||||||
Model floor = LoadModel("resources/models/plane.glb");
|
Model floor = LoadModel("resources/models/plane.glb");
|
||||||
@@ -161,9 +161,9 @@ int main()
|
|||||||
//GenMeshTangents(&floorMesh); // TODO: Review tangents generation
|
//GenMeshTangents(&floorMesh); // TODO: Review tangents generation
|
||||||
//Model floor = LoadModelFromMesh(floorMesh);
|
//Model floor = LoadModelFromMesh(floorMesh);
|
||||||
|
|
||||||
// Assign material shader for our floor model, same PBR shader
|
// Assign material shader for our floor model, same PBR shader
|
||||||
floor.materials[0].shader = shader;
|
floor.materials[0].shader = shader;
|
||||||
|
|
||||||
floor.materials[0].maps[MATERIAL_MAP_ALBEDO].color = WHITE;
|
floor.materials[0].maps[MATERIAL_MAP_ALBEDO].color = WHITE;
|
||||||
floor.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.8f;
|
floor.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.8f;
|
||||||
floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.1f;
|
floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.1f;
|
||||||
@@ -193,7 +193,7 @@ int main()
|
|||||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexNormal"), &usage, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, GetShaderLocation(shader, "useTexNormal"), &usage, SHADER_UNIFORM_INT);
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexMRA"), &usage, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, GetShaderLocation(shader, "useTexMRA"), &usage, SHADER_UNIFORM_INT);
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexEmissive"), &usage, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, GetShaderLocation(shader, "useTexEmissive"), &usage, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -221,11 +221,11 @@ int main()
|
|||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
// Set floor model texture tiling and emissive color parameters on shader
|
// Set floor model texture tiling and emissive color parameters on shader
|
||||||
SetShaderValue(shader, textureTilingLoc, &floorTextureTiling, SHADER_UNIFORM_VEC2);
|
SetShaderValue(shader, textureTilingLoc, &floorTextureTiling, SHADER_UNIFORM_VEC2);
|
||||||
Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
|
Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
|
||||||
@@ -234,7 +234,7 @@ int main()
|
|||||||
// Set floor metallic and roughness values
|
// Set floor metallic and roughness values
|
||||||
SetShaderValue(shader, metallicValueLoc, &floor.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, metallicValueLoc, &floor.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
||||||
SetShaderValue(shader, roughnessValueLoc, &floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, roughnessValueLoc, &floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
DrawModel(floor, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
|
DrawModel(floor, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
|
||||||
|
|
||||||
// Set old car model texture tiling, emissive color and emissive intensity parameters on shader
|
// Set old car model texture tiling, emissive color and emissive intensity parameters on shader
|
||||||
@@ -247,24 +247,24 @@ int main()
|
|||||||
// Set old car metallic and roughness values
|
// Set old car metallic and roughness values
|
||||||
SetShaderValue(shader, metallicValueLoc, &car.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, metallicValueLoc, &car.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
||||||
SetShaderValue(shader, roughnessValueLoc, &car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, roughnessValueLoc, &car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
DrawModel(car, (Vector3){ 0.0f, 0.0f, 0.0f }, 0.25f, WHITE); // Draw car model
|
DrawModel(car, (Vector3){ 0.0f, 0.0f, 0.0f }, 0.25f, WHITE); // Draw car model
|
||||||
|
|
||||||
// Draw spheres to show the lights positions
|
// Draw spheres to show the lights positions
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
{
|
{
|
||||||
Color lightColor = (Color){ lights[i].color[0]*255, lights[i].color[1]*255, lights[i].color[2]*255, lights[i].color[3]*255 };
|
Color lightColor = (Color){ lights[i].color[0]*255, lights[i].color[1]*255, lights[i].color[2]*255, lights[i].color[3]*255 };
|
||||||
|
|
||||||
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lightColor);
|
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lightColor);
|
||||||
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
|
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
|
||||||
}
|
}
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Toggle lights: [1][2][3][4]", 10, 40, 20, LIGHTGRAY);
|
DrawText("Toggle lights: [1][2][3][4]", 10, 40, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawText("(c) Old Rusty Car model by Renafox (https://skfb.ly/LxRy)", screenWidth - 320, screenHeight - 20, 10, LIGHTGRAY);
|
DrawText("(c) Old Rusty Car model by Renafox (https://skfb.ly/LxRy)", screenWidth - 320, screenHeight - 20, 10, LIGHTGRAY);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
@@ -273,20 +273,20 @@ int main()
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Unbind (disconnect) shader from car.material[0]
|
// Unbind (disconnect) shader from car.material[0]
|
||||||
// to avoid UnloadMaterial() trying to unload it automatically
|
// to avoid UnloadMaterial() trying to unload it automatically
|
||||||
car.materials[0].shader = (Shader){ 0 };
|
car.materials[0].shader = (Shader){ 0 };
|
||||||
UnloadMaterial(car.materials[0]);
|
UnloadMaterial(car.materials[0]);
|
||||||
car.materials[0].maps = NULL;
|
car.materials[0].maps = NULL;
|
||||||
UnloadModel(car);
|
UnloadModel(car);
|
||||||
|
|
||||||
floor.materials[0].shader = (Shader){ 0 };
|
floor.materials[0].shader = (Shader){ 0 };
|
||||||
UnloadMaterial(floor.materials[0]);
|
UnloadMaterial(floor.materials[0]);
|
||||||
floor.materials[0].maps = NULL;
|
floor.materials[0].maps = NULL;
|
||||||
UnloadModel(floor);
|
UnloadModel(floor);
|
||||||
|
|
||||||
UnloadShader(shader); // Unload Shader
|
UnloadShader(shader); // Unload Shader
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -310,7 +310,7 @@ static Light CreateLight(int type, Vector3 position, Vector3 target, Color color
|
|||||||
light.color[2] = (float)color.b/255.0f;
|
light.color[2] = (float)color.b/255.0f;
|
||||||
light.color[3] = (float)color.a/255.0f;
|
light.color[3] = (float)color.a/255.0f;
|
||||||
light.intensity = intensity;
|
light.intensity = intensity;
|
||||||
|
|
||||||
// NOTE: Shader parameters names for lights must match the requested ones
|
// NOTE: Shader parameters names for lights must match the requested ones
|
||||||
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", lightCount));
|
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", lightCount));
|
||||||
light.typeLoc = GetShaderLocation(shader, TextFormat("lights[%i].type", lightCount));
|
light.typeLoc = GetShaderLocation(shader, TextFormat("lights[%i].type", lightCount));
|
||||||
@@ -318,7 +318,7 @@ static Light CreateLight(int type, Vector3 position, Vector3 target, Color color
|
|||||||
light.targetLoc = GetShaderLocation(shader, TextFormat("lights[%i].target", lightCount));
|
light.targetLoc = GetShaderLocation(shader, TextFormat("lights[%i].target", lightCount));
|
||||||
light.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightCount));
|
light.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightCount));
|
||||||
light.intensityLoc = GetShaderLocation(shader, TextFormat("lights[%i].intensity", lightCount));
|
light.intensityLoc = GetShaderLocation(shader, TextFormat("lights[%i].intensity", lightCount));
|
||||||
|
|
||||||
UpdateLight(shader, light);
|
UpdateLight(shader, light);
|
||||||
|
|
||||||
lightCount++;
|
lightCount++;
|
||||||
@@ -333,7 +333,7 @@ static void UpdateLight(Shader shader, Light light)
|
|||||||
{
|
{
|
||||||
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
|
||||||
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
// Send to shader light position values
|
// Send to shader light position values
|
||||||
float position[3] = { light.position.x, light.position.y, light.position.z };
|
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||||
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);
|
||||||
|
@@ -78,7 +78,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||||
|
|
||||||
Vector2 mousePosition = GetMousePosition();
|
Vector2 mousePosition = GetMousePosition();
|
||||||
|
|
||||||
swirlCenter[0] = mousePosition.x;
|
swirlCenter[0] = mousePosition.x;
|
||||||
|
@@ -42,7 +42,7 @@ typedef struct GBuffer {
|
|||||||
unsigned int positionTexture;
|
unsigned int positionTexture;
|
||||||
unsigned int normalTexture;
|
unsigned int normalTexture;
|
||||||
unsigned int albedoSpecTexture;
|
unsigned int albedoSpecTexture;
|
||||||
|
|
||||||
unsigned int depthRenderbuffer;
|
unsigned int depthRenderbuffer;
|
||||||
} GBuffer;
|
} GBuffer;
|
||||||
|
|
||||||
@@ -94,14 +94,14 @@ int main(void)
|
|||||||
TraceLog(LOG_WARNING, "Failed to create framebuffer");
|
TraceLog(LOG_WARNING, "Failed to create framebuffer");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
rlEnableFramebuffer(gBuffer.framebuffer);
|
||||||
|
|
||||||
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
||||||
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
||||||
// depth, and the inverse view/projection matrices.
|
// depth, and the inverse view/projection matrices.
|
||||||
|
|
||||||
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios.
|
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios.
|
||||||
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
||||||
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`.
|
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`.
|
||||||
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||||
@@ -161,7 +161,7 @@ int main(void)
|
|||||||
const float CUBE_SCALE = 0.25;
|
const float CUBE_SCALE = 0.25;
|
||||||
Vector3 cubePositions[MAX_CUBES] = { 0 };
|
Vector3 cubePositions[MAX_CUBES] = { 0 };
|
||||||
float cubeRotations[MAX_CUBES] = { 0 };
|
float cubeRotations[MAX_CUBES] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_CUBES; i++)
|
for (int i = 0; i < MAX_CUBES; i++)
|
||||||
{
|
{
|
||||||
cubePositions[i] = (Vector3){
|
cubePositions[i] = (Vector3){
|
||||||
@@ -169,7 +169,7 @@ int main(void)
|
|||||||
.y = (float)(rand()%5),
|
.y = (float)(rand()%5),
|
||||||
.z = (float)(rand()%10) - 5,
|
.z = (float)(rand()%10) - 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
cubeRotations[i] = (float)(rand()%360);
|
cubeRotations[i] = (float)(rand()%360);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ int main(void)
|
|||||||
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
||||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||||
SetShaderValue(deferredShader, deferredShader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
SetShaderValue(deferredShader, deferredShader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
// Check key inputs to enable/disable lights
|
// Check key inputs to enable/disable lights
|
||||||
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
||||||
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
||||||
@@ -215,7 +215,7 @@ int main(void)
|
|||||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
rlEnableFramebuffer(gBuffer.framebuffer);
|
||||||
rlClearColor(0, 0, 0, 0);
|
rlClearColor(0, 0, 0, 0);
|
||||||
rlClearScreenBuffers(); // Clear color and depth buffer
|
rlClearScreenBuffers(); // Clear color and depth buffer
|
||||||
|
|
||||||
rlDisableColorBlend();
|
rlDisableColorBlend();
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
||||||
@@ -281,7 +281,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("FINAL RESULT", 10, screenHeight - 30, 20, DARKGREEN);
|
DrawText("FINAL RESULT", 10, screenHeight - 30, 20, DARKGREEN);
|
||||||
} break;
|
} break;
|
||||||
case DEFERRED_POSITION:
|
case DEFERRED_POSITION:
|
||||||
@@ -291,7 +291,7 @@ int main(void)
|
|||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
||||||
DrawText("POSITION TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
DrawText("POSITION TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||||
} break;
|
} break;
|
||||||
case DEFERRED_NORMAL:
|
case DEFERRED_NORMAL:
|
||||||
@@ -301,7 +301,7 @@ int main(void)
|
|||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
||||||
DrawText("NORMAL TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
DrawText("NORMAL TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||||
} break;
|
} break;
|
||||||
case DEFERRED_ALBEDO:
|
case DEFERRED_ALBEDO:
|
||||||
@@ -311,7 +311,7 @@ int main(void)
|
|||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
||||||
DrawText("ALBEDO TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
DrawText("ALBEDO TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
@@ -321,7 +321,7 @@ int main(void)
|
|||||||
DrawText("Switch G-buffer textures: [1][2][3][4]", 10, 70, 20, DARKGRAY);
|
DrawText("Switch G-buffer textures: [1][2][3][4]", 10, 70, 20, DARKGRAY);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Sieve of Eratosthenes
|
* raylib [shaders] example - sieve of Eratosthenes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@@ -45,7 +45,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - sieve of Eratosthenes");
|
||||||
|
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Hot reloading
|
* raylib [shaders] example - hot reloading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Hybrid Rendering
|
* raylib [shaders] example - hybrid rendering
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@@ -69,7 +69,7 @@ int main(void)
|
|||||||
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
||||||
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
|
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
|
||||||
|
|
||||||
// Transfer screenCenter position to shader. Which is used to calculate ray direction.
|
// Transfer screenCenter position to shader. Which is used to calculate ray direction.
|
||||||
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
|
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
||||||
|
|
||||||
@@ -84,10 +84,10 @@ int main(void)
|
|||||||
.fovy = 45.0f, // Camera field-of-view Y
|
.fovy = 45.0f, // Camera field-of-view Y
|
||||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||||
};
|
};
|
||||||
|
|
||||||
// Camera FOV is pre-calculated in the camera Distance.
|
// Camera FOV is pre-calculated in the camera Distance.
|
||||||
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -100,12 +100,12 @@ int main(void)
|
|||||||
|
|
||||||
// Update Camera Postion in the ray march shader.
|
// Update Camera Postion in the ray march shader.
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
// Update Camera Looking Vector. Vector length determines FOV.
|
// Update Camera Looking Vector. Vector length determines FOV.
|
||||||
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Draw into our custom render texture (framebuffer)
|
// Draw into our custom render texture (framebuffer)
|
||||||
@@ -117,7 +117,7 @@ int main(void)
|
|||||||
BeginShaderMode(shdrRaymarch);
|
BeginShaderMode(shdrRaymarch);
|
||||||
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
// Rasterize Scene
|
// Rasterize Scene
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
BeginShaderMode(shdrRaster);
|
BeginShaderMode(shdrRaster);
|
||||||
@@ -130,10 +130,10 @@ int main(void)
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw into screen our custom render texture
|
// Draw into screen our custom render texture
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
@@ -167,7 +167,7 @@ int main(void)
|
|||||||
// do not represent full screen coordinates (space where want to apply shader)
|
// do not represent full screen coordinates (space where want to apply shader)
|
||||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK); // Clear screen background
|
ClearBackground(BLACK); // Clear screen background
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ int main(void)
|
|||||||
// Load a new texcoords2 attributes buffer
|
// Load a new texcoords2 attributes buffer
|
||||||
mesh.vboId[SHADER_LOC_VERTEX_TEXCOORD02] = rlLoadVertexBuffer(mesh.texcoords2, mesh.vertexCount*2*sizeof(float), false);
|
mesh.vboId[SHADER_LOC_VERTEX_TEXCOORD02] = rlLoadVertexBuffer(mesh.texcoords2, mesh.vertexCount*2*sizeof(float), false);
|
||||||
rlEnableVertexArray(mesh.vaoId);
|
rlEnableVertexArray(mesh.vaoId);
|
||||||
|
|
||||||
// Index 5 is for texcoords2
|
// Index 5 is for texcoords2
|
||||||
rlSetVertexAttribute(5, 2, RL_FLOAT, 0, 0, 0);
|
rlSetVertexAttribute(5, 2, RL_FLOAT, 0, 0, 0);
|
||||||
rlEnableVertexAttribute(5);
|
rlEnableVertexAttribute(5);
|
||||||
@@ -156,10 +156,10 @@ int main(void)
|
|||||||
(Vector2){ 0.0, 0.0 },
|
(Vector2){ 0.0, 0.0 },
|
||||||
0.0,
|
0.0,
|
||||||
WHITE);
|
WHITE);
|
||||||
|
|
||||||
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
|
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
|
||||||
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
|
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@ int main(void)
|
|||||||
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
|
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
|
||||||
float angle = (float)GetRandomValue(0, 180)*DEG2RAD;
|
float angle = (float)GetRandomValue(0, 180)*DEG2RAD;
|
||||||
Matrix rotation = MatrixRotate(axis, angle);
|
Matrix rotation = MatrixRotate(axis, angle);
|
||||||
|
|
||||||
transforms[i] = MatrixMultiply(rotation, translation);
|
transforms[i] = MatrixMultiply(rotation, translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Multiple sample2D with default batch system
|
* raylib [shaders] example - multi sample2D
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@@ -38,7 +38,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib - multiple sample2D");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - multi sample2D");
|
||||||
|
|
||||||
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
|
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
|
||||||
Texture texRed = LoadTextureFromImage(imRed);
|
Texture texRed = LoadTextureFromImage(imRed);
|
||||||
@@ -93,7 +93,7 @@ int main(void)
|
|||||||
// an additional texture units is enabled for texBlue [sampler2D texture1]
|
// an additional texture units is enabled for texBlue [sampler2D texture1]
|
||||||
DrawTexture(texRed, 0, 0, WHITE);
|
DrawTexture(texRed, 0, 0, WHITE);
|
||||||
|
|
||||||
EndShaderMode(); // Texture sampler2D is reseted, needs to be set again for next frame
|
EndShaderMode(); // Texture sampler2D is reseted, needs to be set again for next frame
|
||||||
|
|
||||||
DrawText("Use KEY_LEFT/KEY_RIGHT to move texture mixing in shader!", 80, GetScreenHeight() - 40, 20, RAYWHITE);
|
DrawText("Use KEY_LEFT/KEY_RIGHT to move texture mixing in shader!", 80, GetScreenHeight() - 40, 20, RAYWHITE);
|
||||||
|
|
||||||
|
@@ -141,7 +141,7 @@ int main(void)
|
|||||||
DrawGrid(10, 1.0f); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
|
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
|
||||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE); // Clear screen background
|
ClearBackground(RAYWHITE); // Clear screen background
|
||||||
|
|
||||||
|
@@ -173,7 +173,7 @@ int main(void)
|
|||||||
|
|
||||||
// Draw the same exact things as we drew in the shadowmap!
|
// Draw the same exact things as we drew in the shadowmap!
|
||||||
DrawScene(cube, robot);
|
DrawScene(cube, robot);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);
|
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);
|
||||||
|
@@ -97,7 +97,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_FIRST_PERSON);
|
UpdateCamera(&camera, CAMERA_FIRST_PERSON);
|
||||||
|
|
||||||
framesCounter++;
|
framesCounter++;
|
||||||
rotation.x += 0.01f;
|
rotation.x += 0.01f;
|
||||||
rotation.y += 0.005f;
|
rotation.y += 0.005f;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Apply an shdrOutline to a texture
|
* raylib [shaders] example - texture outline
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@@ -36,7 +36,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture outline");
|
||||||
|
|
||||||
Texture2D texture = LoadTexture("resources/fudesumi.png");
|
Texture2D texture = LoadTexture("resources/fudesumi.png");
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ int main(void)
|
|||||||
// Load a cube model
|
// Load a cube model
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
Model model = LoadModelFromMesh(cube);
|
Model model = LoadModelFromMesh(cube);
|
||||||
|
|
||||||
// Load a texture and assign to cube model
|
// Load a texture and assign to cube model
|
||||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||||
@@ -77,17 +77,17 @@ int main(void)
|
|||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE);
|
DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
|
DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
|
||||||
@@ -104,6 +104,6 @@ int main(void)
|
|||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,7 @@ int main(void)
|
|||||||
Shader shader = LoadShader(
|
Shader shader = LoadShader(
|
||||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
|
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Load perlin noise texture
|
// Load perlin noise texture
|
||||||
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
|
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
|
||||||
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
|
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
|
||||||
@@ -64,7 +64,7 @@ int main(void)
|
|||||||
rlActiveTextureSlot(1);
|
rlActiveTextureSlot(1);
|
||||||
rlEnableTexture(perlinNoiseMap.id);
|
rlEnableTexture(perlinNoiseMap.id);
|
||||||
rlSetUniformSampler(perlinNoiseMapLoc, 1);
|
rlSetUniformSampler(perlinNoiseMapLoc, 1);
|
||||||
|
|
||||||
// Create a plane mesh and model
|
// Create a plane mesh and model
|
||||||
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
|
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
|
||||||
Model planeModel = LoadModelFromMesh(planeMesh);
|
Model planeModel = LoadModelFromMesh(planeMesh);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shader] example - render depth texture
|
* raylib [shaders] example - render depth texture
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@@ -36,7 +36,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shader] example - render depth texture");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - render depth texture");
|
||||||
|
|
||||||
// Init camera
|
// Init camera
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
@@ -76,7 +76,7 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
DrawModel(cube, (Vector3){ 0.0f, 0.0f, 0.0f }, 3.0f, YELLOW);
|
DrawModel(cube, (Vector3){ 0.0f, 0.0f, 0.0f }, 3.0f, YELLOW);
|
||||||
DrawModel(floor, (Vector3){ 10.0f, 0.0f, 2.0f }, 2.0f, RED);
|
DrawModel(floor, (Vector3){ 10.0f, 0.0f, 2.0f }, 2.0f, RED);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Depth buffer writing
|
* raylib [shaders] example - depth buffer writing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@@ -60,7 +60,7 @@ int main(void)
|
|||||||
.fovy = 45.0f, // Camera field-of-view Y
|
.fovy = 45.0f, // Camera field-of-view Y
|
||||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||||
};
|
};
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -71,13 +71,13 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Draw into our custom render texture (framebuffer)
|
// Draw into our custom render texture (framebuffer)
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
DrawCubeWiresV((Vector3){ 0.0f, 0.5f, 1.0f }, (Vector3){ 1.0f, 1.0f, 1.0f }, RED);
|
DrawCubeWiresV((Vector3){ 0.0f, 0.5f, 1.0f }, (Vector3){ 1.0f, 1.0f, 1.0f }, RED);
|
||||||
@@ -89,7 +89,7 @@ int main(void)
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw into screen our custom render texture
|
// Draw into screen our custom render texture
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||||
|
@@ -69,7 +69,7 @@ int main(void)
|
|||||||
|
|
||||||
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
|
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
|
||||||
DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
|
DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
|
||||||
|
|
||||||
// Draw start-end spline circles with some details
|
// Draw start-end spline circles with some details
|
||||||
DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14.0f : 8.0f, moveStartPoint? RED : BLUE);
|
DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14.0f : 8.0f, moveStartPoint? RED : BLUE);
|
||||||
DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14.0f : 8.0f, moveEndPoint? RED : BLUE);
|
DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14.0f : 8.0f, moveEndPoint? RED : BLUE);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Draw raylib logo using basic shapes
|
* raylib [shapes] example - draw raylib logo using basic shapes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Rectangle advanced
|
* raylib [shapes] example - advanced rectangle drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@@ -33,9 +33,9 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle avanced");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle avanced");
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Here we use the 'Diagram' to guide ourselves to which point receives what color
|
// Here we use the 'Diagram' to guide ourselves to which point receives what color
|
||||||
// By choosing the color correctly associated with a pointe the gradient effect
|
// By choosing the color correctly associated with a pointe the gradient effect
|
||||||
// will naturally come from OpenGL interpolation
|
// will naturally come from OpenGL interpolation
|
||||||
|
|
||||||
// [2] Upper Rectangle
|
// [2] Upper Rectangle
|
||||||
@@ -266,7 +266,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// Here we use the 'Diagram' to guide ourselves to which point receives what color.
|
// Here we use the 'Diagram' to guide ourselves to which point receives what color.
|
||||||
// By choosing the color correctly associated with a pointe the gradient effect
|
// By choosing the color correctly associated with a pointe the gradient effect
|
||||||
// will naturally come from OpenGL interpolation.
|
// will naturally come from OpenGL interpolation.
|
||||||
// But this time instead of Quad, we think in triangles.
|
// But this time instead of Quad, we think in triangles.
|
||||||
|
|
||||||
@@ -280,10 +280,10 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
|||||||
if (k == 1) color = right, radius = radiusRight; // [3] Upper Right Corner
|
if (k == 1) color = right, radius = radiusRight; // [3] Upper Right Corner
|
||||||
if (k == 2) color = right, radius = radiusRight; // [5] Lower Right Corner
|
if (k == 2) color = right, radius = radiusRight; // [5] Lower Right Corner
|
||||||
if (k == 3) color = left, radius = radiusLeft; // [7] Lower Left Corner
|
if (k == 3) color = left, radius = radiusLeft; // [7] Lower Left Corner
|
||||||
|
|
||||||
float angle = angles[k];
|
float angle = angles[k];
|
||||||
const Vector2 center = centers[k];
|
const Vector2 center = centers[k];
|
||||||
|
|
||||||
for (int i = 0; i < segments; i++)
|
for (int i = 0; i < segments; i++)
|
||||||
{
|
{
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
@@ -65,7 +65,7 @@ int main(void)
|
|||||||
// Check minimum rec size
|
// Check minimum rec size
|
||||||
if (rec.width < MOUSE_SCALE_MARK_SIZE) rec.width = MOUSE_SCALE_MARK_SIZE;
|
if (rec.width < MOUSE_SCALE_MARK_SIZE) rec.width = MOUSE_SCALE_MARK_SIZE;
|
||||||
if (rec.height < MOUSE_SCALE_MARK_SIZE) rec.height = MOUSE_SCALE_MARK_SIZE;
|
if (rec.height < MOUSE_SCALE_MARK_SIZE) rec.height = MOUSE_SCALE_MARK_SIZE;
|
||||||
|
|
||||||
// Check maximum rec size
|
// Check maximum rec size
|
||||||
if (rec.width > (GetScreenWidth() - rec.x)) rec.width = GetScreenWidth() - rec.x;
|
if (rec.width > (GetScreenWidth() - rec.x)) rec.width = GetScreenWidth() - rec.x;
|
||||||
if (rec.height > (GetScreenHeight() - rec.y)) rec.height = GetScreenHeight() - rec.y;
|
if (rec.height > (GetScreenHeight() - rec.y)) rec.height = GetScreenHeight() - rec.y;
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
#define MAX_SPLINE_POINTS 32
|
#define MAX_SPLINE_POINTS 32
|
||||||
|
|
||||||
// Cubic 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;
|
||||||
Vector2 end;
|
Vector2 end;
|
||||||
@@ -57,17 +57,17 @@ int main(void)
|
|||||||
{ 520.0f, 60.0f },
|
{ 520.0f, 60.0f },
|
||||||
{ 710.0f, 260.0f },
|
{ 710.0f, 260.0f },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Array required for spline bezier-cubic,
|
// Array required for spline bezier-cubic,
|
||||||
// including control points interleaved with start-end segment points
|
// including control points interleaved with start-end segment points
|
||||||
Vector2 pointsInterleaved[3*(MAX_SPLINE_POINTS - 1) + 1] = { 0 };
|
Vector2 pointsInterleaved[3*(MAX_SPLINE_POINTS - 1) + 1] = { 0 };
|
||||||
|
|
||||||
int pointCount = 5;
|
int pointCount = 5;
|
||||||
int selectedPoint = -1;
|
int selectedPoint = -1;
|
||||||
int focusedPoint = -1;
|
int focusedPoint = -1;
|
||||||
Vector2 *selectedControlPoint = NULL;
|
Vector2 *selectedControlPoint = NULL;
|
||||||
Vector2 *focusedControlPoint = NULL;
|
Vector2 *focusedControlPoint = NULL;
|
||||||
|
|
||||||
// Cubic Bezier control points initialization
|
// Cubic Bezier control points initialization
|
||||||
ControlPoint control[MAX_SPLINE_POINTS-1] = { 0 };
|
ControlPoint control[MAX_SPLINE_POINTS-1] = { 0 };
|
||||||
for (int i = 0; i < pointCount - 1; i++)
|
for (int i = 0; i < pointCount - 1; i++)
|
||||||
@@ -79,9 +79,9 @@ int main(void)
|
|||||||
// Spline config variables
|
// Spline config variables
|
||||||
float splineThickness = 8.0f;
|
float splineThickness = 8.0f;
|
||||||
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier
|
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier
|
||||||
bool splineTypeEditMode = false;
|
bool splineTypeEditMode = false;
|
||||||
bool splineHelpersActive = true;
|
bool splineHelpersActive = true;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -114,14 +114,14 @@ int main(void)
|
|||||||
}
|
}
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedPoint = focusedPoint;
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedPoint = focusedPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spline point movement logic
|
// Spline point movement logic
|
||||||
if (selectedPoint >= 0)
|
if (selectedPoint >= 0)
|
||||||
{
|
{
|
||||||
points[selectedPoint] = GetMousePosition();
|
points[selectedPoint] = GetMousePosition();
|
||||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedPoint = -1;
|
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedPoint = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cubic Bezier spline control points logic
|
// Cubic Bezier spline control points logic
|
||||||
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
|
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
|
||||||
{
|
{
|
||||||
@@ -144,7 +144,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedControlPoint = focusedControlPoint;
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedControlPoint = focusedControlPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spline control point movement logic
|
// Spline control point movement logic
|
||||||
if (selectedControlPoint != NULL)
|
if (selectedControlPoint != NULL)
|
||||||
{
|
{
|
||||||
@@ -152,7 +152,7 @@ int main(void)
|
|||||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedControlPoint = NULL;
|
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedControlPoint = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spline selection logic
|
// Spline selection logic
|
||||||
if (IsKeyPressed(KEY_ONE)) splineTypeActive = 0;
|
if (IsKeyPressed(KEY_ONE)) splineTypeActive = 0;
|
||||||
else if (IsKeyPressed(KEY_TWO)) splineTypeActive = 1;
|
else if (IsKeyPressed(KEY_TWO)) splineTypeActive = 1;
|
||||||
@@ -168,7 +168,7 @@ int main(void)
|
|||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
if (splineTypeActive == SPLINE_LINEAR)
|
if (splineTypeActive == SPLINE_LINEAR)
|
||||||
{
|
{
|
||||||
// Draw spline: linear
|
// Draw spline: linear
|
||||||
@@ -191,7 +191,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Draw spline: catmull-rom
|
// Draw spline: catmull-rom
|
||||||
DrawSplineCatmullRom(points, pointCount, splineThickness, RED); // Provide connected points array
|
DrawSplineCatmullRom(points, pointCount, splineThickness, RED); // Provide connected points array
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < (pointCount - 3); i++)
|
for (int i = 0; i < (pointCount - 3); i++)
|
||||||
{
|
{
|
||||||
@@ -202,20 +202,20 @@ int main(void)
|
|||||||
}
|
}
|
||||||
else if (splineTypeActive == SPLINE_BEZIER)
|
else if (splineTypeActive == SPLINE_BEZIER)
|
||||||
{
|
{
|
||||||
// NOTE: Cubic-bezier spline requires the 2 control points of each segnment to be
|
// NOTE: Cubic-bezier spline requires the 2 control points of each segnment to be
|
||||||
// provided interleaved with the start and end point of every segment
|
// provided interleaved with the start and end point of every segment
|
||||||
for (int i = 0; i < (pointCount - 1); i++)
|
for (int i = 0; i < (pointCount - 1); i++)
|
||||||
{
|
{
|
||||||
pointsInterleaved[3*i] = points[i];
|
pointsInterleaved[3*i] = points[i];
|
||||||
pointsInterleaved[3*i + 1] = control[i].start;
|
pointsInterleaved[3*i + 1] = control[i].start;
|
||||||
pointsInterleaved[3*i + 2] = control[i].end;
|
pointsInterleaved[3*i + 2] = control[i].end;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointsInterleaved[3*(pointCount - 1)] = points[pointCount - 1];
|
pointsInterleaved[3*(pointCount - 1)] = points[pointCount - 1];
|
||||||
|
|
||||||
// Draw spline: cubic-bezier (with control points)
|
// Draw spline: cubic-bezier (with control points)
|
||||||
DrawSplineBezierCubic(pointsInterleaved, 3*(pointCount - 1) + 1, splineThickness, RED);
|
DrawSplineBezierCubic(pointsInterleaved, 3*(pointCount - 1) + 1, splineThickness, RED);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < 3*(pointCount - 1); i += 3)
|
for (int i = 0; i < 3*(pointCount - 1); i += 3)
|
||||||
{
|
{
|
||||||
@@ -234,7 +234,7 @@ int main(void)
|
|||||||
else if (focusedControlPoint == &control[i].end) DrawCircleV(control[i].end, 8, GREEN);
|
else if (focusedControlPoint == &control[i].end) DrawCircleV(control[i].end, 8, GREEN);
|
||||||
DrawLineEx(points[i], control[i].start, 1.0f, LIGHTGRAY);
|
DrawLineEx(points[i], control[i].start, 1.0f, LIGHTGRAY);
|
||||||
DrawLineEx(points[i + 1], control[i].end, 1.0f, LIGHTGRAY);
|
DrawLineEx(points[i + 1], control[i].end, 1.0f, LIGHTGRAY);
|
||||||
|
|
||||||
// Draw spline control lines
|
// Draw spline control lines
|
||||||
DrawLineV(points[i], control[i].start, GRAY);
|
DrawLineV(points[i], control[i].start, GRAY);
|
||||||
//DrawLineV(control[i].start, control[i].end, LIGHTGRAY);
|
//DrawLineV(control[i].start, control[i].end, LIGHTGRAY);
|
||||||
@@ -258,7 +258,7 @@ int main(void)
|
|||||||
|
|
||||||
// Check all possible UI states that require controls lock
|
// Check all possible UI states that require controls lock
|
||||||
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlPoint != NULL)) GuiLock();
|
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlPoint != NULL)) GuiLock();
|
||||||
|
|
||||||
// Draw spline config
|
// Draw spline config
|
||||||
GuiLabel((Rectangle){ 12, 62, 140, 24 }, TextFormat("Spline thickness: %i", (int)splineThickness));
|
GuiLabel((Rectangle){ 12, 62, 140, 24 }, TextFormat("Spline thickness: %i", (int)splineThickness));
|
||||||
GuiSliderBar((Rectangle){ 12, 60 + 24, 140, 16 }, NULL, NULL, &splineThickness, 1.0f, 40.0f);
|
GuiSliderBar((Rectangle){ 12, 60 + 24, 140, 16 }, NULL, NULL, &splineThickness, 1.0f, 40.0f);
|
||||||
@@ -269,7 +269,7 @@ int main(void)
|
|||||||
|
|
||||||
GuiLabel((Rectangle){ 12, 10, 140, 24 }, "Spline type:");
|
GuiLabel((Rectangle){ 12, 10, 140, 24 }, "Spline type:");
|
||||||
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
|
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
|
||||||
|
|
||||||
GuiUnlock();
|
GuiUnlock();
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
@@ -55,7 +55,7 @@ LightInfo lights[MAX_LIGHTS] = { 0 };
|
|||||||
void MoveLight(int slot, float x, float y)
|
void MoveLight(int slot, float x, float y)
|
||||||
{
|
{
|
||||||
lights[slot].dirty = true;
|
lights[slot].dirty = true;
|
||||||
lights[slot].position.x = x;
|
lights[slot].position.x = x;
|
||||||
lights[slot].position.y = y;
|
lights[slot].position.y = y;
|
||||||
|
|
||||||
// update the cached bounds
|
// update the cached bounds
|
||||||
@@ -99,7 +99,7 @@ void DrawLightMask(int slot)
|
|||||||
|
|
||||||
// If we are valid, then draw the light radius to the alpha mask
|
// If we are valid, then draw the light radius to the alpha mask
|
||||||
if (lights[slot].valid) DrawCircleGradient((int)lights[slot].position.x, (int)lights[slot].position.y, lights[slot].outerRadius, ColorAlpha(WHITE, 0), WHITE);
|
if (lights[slot].valid) DrawCircleGradient((int)lights[slot].position.x, (int)lights[slot].position.y, lights[slot].outerRadius, ColorAlpha(WHITE, 0), WHITE);
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
rlDrawRenderBatchActive();
|
||||||
|
|
||||||
// Cut out the shadows from the light radius by forcing the alpha to maximum
|
// Cut out the shadows from the light radius by forcing the alpha to maximum
|
||||||
@@ -114,7 +114,7 @@ void DrawLightMask(int slot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
rlDrawRenderBatchActive();
|
||||||
|
|
||||||
// Go back to normal blend mode
|
// Go back to normal blend mode
|
||||||
rlSetBlendMode(BLEND_ALPHA);
|
rlSetBlendMode(BLEND_ALPHA);
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ bool UpdateLight(int slot, Rectangle* boxes, int count)
|
|||||||
if (!CheckCollisionRecs(lights[slot].bounds, boxes[i])) continue;
|
if (!CheckCollisionRecs(lights[slot].bounds, boxes[i])) continue;
|
||||||
|
|
||||||
// Check the edges that are on the same side we are, and cast shadow volumes out from them
|
// Check the edges that are on the same side we are, and cast shadow volumes out from them
|
||||||
|
|
||||||
// Top
|
// Top
|
||||||
Vector2 sp = (Vector2){ boxes[i].x, boxes[i].y };
|
Vector2 sp = (Vector2){ boxes[i].x, boxes[i].y };
|
||||||
Vector2 ep = (Vector2){ boxes[i].x + boxes[i].width, boxes[i].y };
|
Vector2 ep = (Vector2){ boxes[i].x + boxes[i].width, boxes[i].y };
|
||||||
@@ -219,7 +219,7 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - top down lights");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - top down lights");
|
||||||
|
|
||||||
// Initialize our 'world' of boxes
|
// Initialize our 'world' of boxes
|
||||||
@@ -274,7 +274,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Build up the light mask
|
// Build up the light mask
|
||||||
BeginTextureMode(lightMask);
|
BeginTextureMode(lightMask);
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
// Force the blend mode to only set the alpha of the destination
|
// Force the blend mode to only set the alpha of the destination
|
||||||
@@ -300,10 +300,10 @@ int main(void)
|
|||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
// Draw the tile background
|
// Draw the tile background
|
||||||
DrawTextureRec(backgroundTexture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE);
|
DrawTextureRec(backgroundTexture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE);
|
||||||
|
|
||||||
// Overlay the shadows from all the lights
|
// Overlay the shadows from all the lights
|
||||||
DrawTextureRec(lightMask.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight() }, Vector2Zero(), ColorAlpha(WHITE, showLines? 0.75f : 1.0f));
|
DrawTextureRec(lightMask.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight() }, Vector2Zero(), ColorAlpha(WHITE, showLines? 0.75f : 1.0f));
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Codepoints loading
|
* raylib [text] example - text codepoints loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Draw 3d
|
* raylib [text] example - drawing 3d text
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
||||||
* flexibility...for example to change position of each letter individually to make somethink
|
* flexibility...for example to change position of each letter individually to make somethink
|
||||||
* like a wavy text effect.
|
* like a wavy text effect.
|
||||||
*
|
*
|
||||||
* Special thanks to:
|
* Special thanks to:
|
||||||
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
|
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
|
||||||
* Chris Camacho (codifies - http://bedroomcoders.co.uk/) for the alpha discard shader
|
* Chris Camacho (codifies - http://bedroomcoders.co.uk/) for the alpha discard shader
|
||||||
@@ -146,7 +146,7 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, camera_mode);
|
UpdateCamera(&camera, camera_mode);
|
||||||
|
|
||||||
// Handle font files dropped
|
// Handle font files dropped
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
{
|
{
|
||||||
@@ -164,7 +164,7 @@ int main(void)
|
|||||||
font = LoadFont(droppedFiles.paths[0]);
|
font = LoadFont(droppedFiles.paths[0]);
|
||||||
fontSize = (float)font.baseSize;
|
fontSize = (float)font.baseSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
|
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Font filters
|
* raylib [text] example - font texture filters
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@@ -94,7 +94,7 @@ int main(void)
|
|||||||
UnloadFont(font);
|
UnloadFont(font);
|
||||||
font = LoadFontEx(droppedFiles.paths[0], (int)fontSize, 0, 0);
|
font = LoadFontEx(droppedFiles.paths[0], (int)fontSize, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
|
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Font SDF loading
|
* raylib [text] example - font SDF loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Sprite font loading
|
* raylib [text] example - sprite font loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Text formatting
|
* raylib [text] example - text formating
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Input Box
|
* raylib [text] example - text input box
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Rectangle bounds
|
* raylib [text] example - rectangle bounds
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Unicode
|
* raylib [text] example - unicode text drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@@ -284,7 +284,7 @@ int main(void)
|
|||||||
int length = GetCodepointCount(messages[message].text);
|
int length = GetCodepointCount(messages[message].text);
|
||||||
const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, length, size);
|
const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, length, size);
|
||||||
sz = MeasureTextEx(GetFontDefault(), info, 10, 1.0f);
|
sz = MeasureTextEx(GetFontDefault(), info, 10, 1.0f);
|
||||||
|
|
||||||
DrawText(info, (int)(textRect.x + textRect.width - sz.x), (int)(msgRect.y + msgRect.height - sz.y - 2), 10, RAYWHITE);
|
DrawText(info, (int)(textRect.x + textRect.width - sz.x), (int)(msgRect.y + msgRect.height - sz.y - 2), 10, RAYWHITE);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Text Writing Animation
|
* raylib [text] example - text writing animation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Background scrolling
|
* raylib [textures] example - background scrolling
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Bunnymark
|
* raylib [textures] example - bunnymark
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw part of the texture tiled
|
* raylib [textures] example - draw texture tiled
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@@ -36,7 +36,7 @@ int main(void)
|
|||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - Draw part of a texture tiled");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - draw texture tiled");
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Texture texPattern = LoadTexture("resources/patterns.png");
|
Texture texPattern = LoadTexture("resources/patterns.png");
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Fog of war
|
* raylib [textures] example - fog of war
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Retrive image channel (mask)
|
* raylib [textures] example - extract image channel
|
||||||
*
|
*
|
||||||
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
||||||
*
|
*
|
||||||
@@ -79,7 +79,7 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// TODO...
|
// TODO...
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
@@ -104,6 +104,7 @@ int main(void)
|
|||||||
UnloadTexture(textureGreen);
|
UnloadTexture(textureGreen);
|
||||||
UnloadTexture(textureBlue);
|
UnloadTexture(textureBlue);
|
||||||
UnloadTexture(textureAlpha);
|
UnloadTexture(textureAlpha);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image loading and drawing on it
|
* raylib [textures] example - image loading and drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Procedural images generation
|
* raylib [textures] example - procedural images generation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image loading and texture creation
|
* raylib [textures] example - image loading and texture creation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image Rotation
|
* raylib [textures] example - image rotation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@@ -27,7 +27,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture rotation");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image rotation");
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Image image45 = LoadImage("resources/raylib_logo.png");
|
Image image45 = LoadImage("resources/raylib_logo.png");
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image text drawing using TTF generated font
|
* raylib [textures] example - image text drawing using TTF generated font
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Texture loading and drawing
|
* raylib [textures] example - texture loading and drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Mouse painting
|
* raylib [textures] example - mouse painting
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw Textured Polygon
|
* raylib [textures] example - draw textured polygon
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
@@ -34,7 +34,7 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
||||||
|
|
||||||
// Define texture coordinates to map our texture to poly
|
// Define texture coordinates to map our texture to poly
|
||||||
@@ -60,7 +60,7 @@ int main(void)
|
|||||||
points[i].x = (texcoords[i].x - 0.5f)*256.0f;
|
points[i].x = (texcoords[i].x - 0.5f)*256.0f;
|
||||||
points[i].y = (texcoords[i].y - 0.5f)*256.0f;
|
points[i].y = (texcoords[i].y - 0.5f)*256.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the vertices drawing position
|
// Define the vertices drawing position
|
||||||
// NOTE: Initially same as points but updated every frame
|
// NOTE: Initially same as points but updated every frame
|
||||||
Vector2 positions[MAX_POINTS] = { 0 };
|
Vector2 positions[MAX_POINTS] = { 0 };
|
||||||
@@ -116,7 +116,7 @@ int main(void)
|
|||||||
void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint)
|
void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint)
|
||||||
{
|
{
|
||||||
rlBegin(RL_TRIANGLES);
|
rlBegin(RL_TRIANGLES);
|
||||||
|
|
||||||
rlSetTexture(texture.id);
|
rlSetTexture(texture.id);
|
||||||
|
|
||||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Load textures from raw data
|
* raylib [textures] example - load textures from raw data
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Sprite animation
|
* raylib [textures] example - sprite animation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Texture source and destination rectangles
|
* raylib [textures] example - texture source and destination rectangles
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw a texture along a segmented curve
|
* raylib [textures] example - draw texture along segmented curve
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@@ -112,7 +112,7 @@ int main()
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawTexturedCurve(); // Draw a textured Spline Cubic Bezier
|
DrawTexturedCurve(); // Draw a textured Spline Cubic Bezier
|
||||||
|
|
||||||
// Draw spline for reference
|
// Draw spline for reference
|
||||||
if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE);
|
if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE);
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ int main()
|
|||||||
DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE);
|
DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE);
|
||||||
DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f));
|
DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f));
|
||||||
DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE);
|
DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE);
|
||||||
|
|
||||||
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW);
|
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW);
|
||||||
DrawCircleV(curveStartPosition, 5, RED);
|
DrawCircleV(curveStartPosition, 5, RED);
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ int main()
|
|||||||
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);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ int main()
|
|||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texRoad);
|
UnloadTexture(texRoad);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Retrieve image data from texture: LoadImageFromTexture()
|
* raylib [textures] example - texture to image
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user