REVIEWED: examples: Replace TABS and Remove trailing spaces
This commit is contained in:
parent
bd21d74914
commit
0b9f463e64
36 changed files with 473 additions and 480 deletions
|
|
@ -86,7 +86,7 @@ int main(void)
|
||||||
Vector2 iResolution = { (float)screenWidth, (float)screenHeight };
|
Vector2 iResolution = { (float)screenWidth, (float)screenHeight };
|
||||||
|
|
||||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/fft.fs", GLSL_VERSION));
|
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/fft.fs", GLSL_VERSION));
|
||||||
|
|
||||||
int iResolutionLocation = GetShaderLocation(shader, "iResolution");
|
int iResolutionLocation = GetShaderLocation(shader, "iResolution");
|
||||||
int iChannel0Location = GetShaderLocation(shader, "iChannel0");
|
int iChannel0Location = GetShaderLocation(shader, "iChannel0");
|
||||||
SetShaderValue(shader, iResolutionLocation, &iResolution, SHADER_UNIFORM_VEC2);
|
SetShaderValue(shader, iResolutionLocation, &iResolution, SHADER_UNIFORM_VEC2);
|
||||||
|
|
@ -153,16 +153,16 @@ int main(void)
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
SetShaderValueTexture(shader, iChannel0Location, fftTexture);
|
SetShaderValueTexture(shader, iChannel0Location, fftTexture);
|
||||||
DrawTextureRec(bufferA.texture,
|
DrawTextureRec(bufferA.texture,
|
||||||
(Rectangle){ 0, 0, (float)screenWidth, (float)-screenHeight },
|
(Rectangle){ 0, 0, (float)screenWidth, (float)-screenHeight },
|
||||||
(Vector2){ 0, 0 }, WHITE);
|
(Vector2){ 0, 0 }, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ int main(void)
|
||||||
|
|
||||||
// Encode data to Base64 string (includes NULL terminator), memory must be MemFree()
|
// Encode data to Base64 string (includes NULL terminator), memory must be MemFree()
|
||||||
base64Text = EncodeDataBase64((unsigned char *)textInput, textInputLen, &base64TextSize);
|
base64Text = EncodeDataBase64((unsigned char *)textInput, textInputLen, &base64TextSize);
|
||||||
|
|
||||||
hashCRC32 = ComputeCRC32((unsigned char *)textInput, textInputLen); // Compute CRC32 hash code (4 bytes)
|
hashCRC32 = ComputeCRC32((unsigned char *)textInput, textInputLen); // Compute CRC32 hash code (4 bytes)
|
||||||
hashMD5 = ComputeMD5((unsigned char *)textInput, textInputLen); // Compute MD5 hash code, returns static int[4] (16 bytes)
|
hashMD5 = ComputeMD5((unsigned char *)textInput, textInputLen); // Compute MD5 hash code, returns static int[4] (16 bytes)
|
||||||
hashSHA1 = ComputeSHA1((unsigned char *)textInput, textInputLen); // Compute SHA1 hash code, returns static int[5] (20 bytes)
|
hashSHA1 = ComputeSHA1((unsigned char *)textInput, textInputLen); // Compute SHA1 hash code, returns static int[5] (20 bytes)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ int main(void)
|
||||||
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
|
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
|
||||||
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
|
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
|
||||||
|
|
||||||
// Multiply by 6.0 (an arbitrary value) in order to make the speed
|
// Multiply by 6.0 (an arbitrary value) in order to make the speed
|
||||||
// visually closer to the other circle (at 60 fps), for comparison
|
// visually closer to the other circle (at 60 fps), for comparison
|
||||||
deltaCircle.x += GetFrameTime()*6.0f*speed;
|
deltaCircle.x += GetFrameTime()*6.0f*speed;
|
||||||
// This circle can move faster or slower visually depending on the FPS
|
// This circle can move faster or slower visually depending on the FPS
|
||||||
|
|
@ -68,7 +68,7 @@ int main(void)
|
||||||
// If either circle is off the screen, reset it back to the start
|
// If either circle is off the screen, reset it back to the start
|
||||||
if (deltaCircle.x > screenWidth) deltaCircle.x = 0;
|
if (deltaCircle.x > screenWidth) deltaCircle.x = 0;
|
||||||
if (frameCircle.x > screenWidth) frameCircle.x = 0;
|
if (frameCircle.x > screenWidth) frameCircle.x = 0;
|
||||||
|
|
||||||
// Reset both circles positions
|
// Reset both circles positions
|
||||||
if (IsKeyPressed(KEY_R))
|
if (IsKeyPressed(KEY_R))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
// Simple example for decoding input as actions, allowing remapping of input to different keys or gamepad buttons
|
// Simple example for decoding input as actions, allowing remapping of input to different keys or gamepad buttons
|
||||||
// For example instead of using `IsKeyDown(KEY_LEFT)`, you can use `IsActionDown(ACTION_LEFT)`
|
// For example instead of using `IsKeyDown(KEY_LEFT)`, you can use `IsActionDown(ACTION_LEFT)`
|
||||||
// which can be reassigned to e.g. KEY_A and also assigned to a gamepad button. the action will trigger with either gamepad or keys
|
// which can be reassigned to e.g. KEY_A and also assigned to a gamepad button. the action will trigger with either gamepad or keys
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ typedef struct ActionInput {
|
||||||
// Global Variables Definition
|
// Global Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static int gamepadIndex = 0; // Gamepad default index
|
static int gamepadIndex = 0; // Gamepad default index
|
||||||
static ActionInput actionInputs[MAX_ACTION] = { 0 };
|
static ActionInput actionInputs[MAX_ACTION] = { 0 };
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
|
|
@ -67,15 +67,15 @@ int main(void)
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - input actions");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input actions");
|
||||||
|
|
||||||
// Set default actions
|
// Set default actions
|
||||||
char actionSet = 0;
|
char actionSet = 0;
|
||||||
SetActionsDefault();
|
SetActionsDefault();
|
||||||
bool releaseAction = false;
|
bool releaseAction = false;
|
||||||
|
|
||||||
Vector2 position = (Vector2){ 400.0f, 200.0f };
|
Vector2 position = (Vector2){ 400.0f, 200.0f };
|
||||||
Vector2 size = (Vector2){ 40.0f, 40.0f };
|
Vector2 size = (Vector2){ 40.0f, 40.0f };
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
gamepadIndex = 0; // Set gamepad being checked
|
gamepadIndex = 0; // Set gamepad being checked
|
||||||
|
|
||||||
if (IsActionDown(ACTION_UP)) position.y -= 2;
|
if (IsActionDown(ACTION_UP)) position.y -= 2;
|
||||||
if (IsActionDown(ACTION_DOWN)) position.y += 2;
|
if (IsActionDown(ACTION_DOWN)) position.y += 2;
|
||||||
if (IsActionDown(ACTION_LEFT)) position.x -= 2;
|
if (IsActionDown(ACTION_LEFT)) position.x -= 2;
|
||||||
|
|
@ -95,12 +95,12 @@ int main(void)
|
||||||
position.x = (screenWidth-size.x)/2;
|
position.x = (screenWidth-size.x)/2;
|
||||||
position.y = (screenHeight-size.y)/2;
|
position.y = (screenHeight-size.y)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register release action for one frame
|
// Register release action for one frame
|
||||||
releaseAction = false;
|
releaseAction = false;
|
||||||
if (IsActionReleased(ACTION_FIRE)) releaseAction = true;
|
if (IsActionReleased(ACTION_FIRE)) releaseAction = true;
|
||||||
|
|
||||||
// Switch control scheme by pressing TAB
|
// Switch control scheme by pressing TAB
|
||||||
if (IsKeyPressed(KEY_TAB))
|
if (IsKeyPressed(KEY_TAB))
|
||||||
{
|
{
|
||||||
actionSet = !actionSet;
|
actionSet = !actionSet;
|
||||||
|
|
@ -116,7 +116,7 @@ int main(void)
|
||||||
ClearBackground(GRAY);
|
ClearBackground(GRAY);
|
||||||
|
|
||||||
DrawRectangleV(position, size, releaseAction? BLUE : RED);
|
DrawRectangleV(position, size, releaseAction? BLUE : RED);
|
||||||
|
|
||||||
DrawText((actionSet == 0)? "Current input set: WASD (default)" : "Current input set: Cursor", 10, 10, 20, WHITE);
|
DrawText((actionSet == 0)? "Current input set: WASD (default)" : "Current input set: Cursor", 10, 10, 20, WHITE);
|
||||||
DrawText("Use TAB key to toggles Actions keyset", 10, 50, 20, GREEN);
|
DrawText("Use TAB key to toggles Actions keyset", 10, 50, 20, GREEN);
|
||||||
|
|
||||||
|
|
@ -140,9 +140,9 @@ int main(void)
|
||||||
static bool IsActionPressed(int action)
|
static bool IsActionPressed(int action)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (action < MAX_ACTION) result = (IsKeyPressed(actionInputs[action].key) || IsGamepadButtonPressed(gamepadIndex, actionInputs[action].button));
|
if (action < MAX_ACTION) result = (IsKeyPressed(actionInputs[action].key) || IsGamepadButtonPressed(gamepadIndex, actionInputs[action].button));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,20 +151,20 @@ static bool IsActionPressed(int action)
|
||||||
static bool IsActionReleased(int action)
|
static bool IsActionReleased(int action)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (action < MAX_ACTION) result = (IsKeyReleased(actionInputs[action].key) || IsGamepadButtonReleased(gamepadIndex, actionInputs[action].button));
|
if (action < MAX_ACTION) result = (IsKeyReleased(actionInputs[action].key) || IsGamepadButtonReleased(gamepadIndex, actionInputs[action].button));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check action key/button down
|
// Check action key/button down
|
||||||
// NOTE: Combines key down and gamepad button down in one action
|
// NOTE: Combines key down and gamepad button down in one action
|
||||||
static bool IsActionDown(int action)
|
static bool IsActionDown(int action)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (action < MAX_ACTION) result = (IsKeyDown(actionInputs[action].key) || IsGamepadButtonDown(gamepadIndex, actionInputs[action].button));
|
if (action < MAX_ACTION) result = (IsKeyDown(actionInputs[action].key) || IsGamepadButtonDown(gamepadIndex, actionInputs[action].button));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ int main(void)
|
||||||
const float rightStickDeadzoneY = 0.1f;
|
const float rightStickDeadzoneY = 0.1f;
|
||||||
const float leftTriggerDeadzone = -0.9f;
|
const float leftTriggerDeadzone = -0.9f;
|
||||||
const float rightTriggerDeadzone = -0.9f;
|
const float rightTriggerDeadzone = -0.9f;
|
||||||
|
|
||||||
Rectangle vibrateButton = { 0 };
|
Rectangle vibrateButton = { 0 };
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
@ -97,7 +97,7 @@ int main(void)
|
||||||
if (leftTrigger < leftTriggerDeadzone) leftTrigger = -1.0f;
|
if (leftTrigger < leftTriggerDeadzone) leftTrigger = -1.0f;
|
||||||
if (rightTrigger < rightTriggerDeadzone) rightTrigger = -1.0f;
|
if (rightTrigger < rightTriggerDeadzone) rightTrigger = -1.0f;
|
||||||
|
|
||||||
if ((TextFindIndex(TextToLower(GetGamepadName(gamepad)), XBOX_ALIAS_1) > -1) ||
|
if ((TextFindIndex(TextToLower(GetGamepadName(gamepad)), XBOX_ALIAS_1) > -1) ||
|
||||||
(TextFindIndex(TextToLower(GetGamepadName(gamepad)), XBOX_ALIAS_2) > -1))
|
(TextFindIndex(TextToLower(GetGamepadName(gamepad)), XBOX_ALIAS_2) > -1))
|
||||||
{
|
{
|
||||||
DrawTexture(texXboxPad, 0, 0, DARKGRAY);
|
DrawTexture(texXboxPad, 0, 0, DARKGRAY);
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,6 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,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 contributed by GreenSnakeLinux (@GreenSnakeLinux),
|
* Example contributed by GreenSnakeLinux (@GreenSnakeLinux),
|
||||||
* reviewed by Ramon Santamaria (@raysan5), oblerion (@oblerion) and danilwhale (@danilwhale)
|
* reviewed by Ramon Santamaria (@raysan5), oblerion (@oblerion) and danilwhale (@danilwhale)
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
|
@ -86,7 +86,7 @@ int main(void)
|
||||||
pressedButton = BUTTON_NONE;
|
pressedButton = BUTTON_NONE;
|
||||||
|
|
||||||
// Make sure user is pressing left mouse button if they're from desktop
|
// Make sure user is pressing left mouse button if they're from desktop
|
||||||
if ((GetTouchPointCount() > 0) ||
|
if ((GetTouchPointCount() > 0) ||
|
||||||
((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)))
|
((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)))
|
||||||
{
|
{
|
||||||
// Find nearest D-Pad button to the input position
|
// Find nearest D-Pad button to the input position
|
||||||
|
|
@ -113,7 +113,7 @@ int main(void)
|
||||||
default: break;
|
default: break;
|
||||||
};
|
};
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
|
||||||
|
|
@ -66,25 +66,25 @@ int main(void)
|
||||||
for (int i = 0; i < monitorCount; i++)
|
for (int i = 0; i < monitorCount; i++)
|
||||||
{
|
{
|
||||||
monitors[i] = (MonitorInfo){
|
monitors[i] = (MonitorInfo){
|
||||||
GetMonitorPosition(i),
|
GetMonitorPosition(i),
|
||||||
GetMonitorName(i),
|
GetMonitorName(i),
|
||||||
GetMonitorWidth(i),
|
GetMonitorWidth(i),
|
||||||
GetMonitorHeight(i),
|
GetMonitorHeight(i),
|
||||||
GetMonitorPhysicalWidth(i),
|
GetMonitorPhysicalWidth(i),
|
||||||
GetMonitorPhysicalHeight(i),
|
GetMonitorPhysicalHeight(i),
|
||||||
GetMonitorRefreshRate(i)
|
GetMonitorRefreshRate(i)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (monitors[i].position.x < monitorOffsetX) monitorOffsetX = -(int)monitors[i].position.x;
|
if (monitors[i].position.x < monitorOffsetX) monitorOffsetX = -(int)monitors[i].position.x;
|
||||||
|
|
||||||
const int width = (int)monitors[i].position.x + monitors[i].width;
|
const int width = (int)monitors[i].position.x + monitors[i].width;
|
||||||
const int height = (int)monitors[i].position.y + monitors[i].height;
|
const int height = (int)monitors[i].position.y + monitors[i].height;
|
||||||
|
|
||||||
if (maxWidth < width) maxWidth = width;
|
if (maxWidth < width) maxWidth = width;
|
||||||
if (maxHeight < height) maxHeight = height;
|
if (maxHeight < height) maxHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ENTER) && (monitorCount > 1))
|
if (IsKeyPressed(KEY_ENTER) && (monitorCount > 1))
|
||||||
{
|
{
|
||||||
currentMonitorIndex += 1;
|
currentMonitorIndex += 1;
|
||||||
|
|
||||||
|
|
@ -95,8 +95,8 @@ int main(void)
|
||||||
}
|
}
|
||||||
else currentMonitorIndex = GetCurrentMonitor(); // Get currentMonitorIndex if manually moved
|
else currentMonitorIndex = GetCurrentMonitor(); // Get currentMonitorIndex if manually moved
|
||||||
|
|
||||||
float monitorScale = 0.6f;
|
float monitorScale = 0.6f;
|
||||||
|
|
||||||
if (maxHeight > (maxWidth + monitorOffsetX)) monitorScale *= ((float)screenHeight/(float)maxHeight);
|
if (maxHeight > (maxWidth + monitorOffsetX)) monitorScale *= ((float)screenHeight/(float)maxHeight);
|
||||||
else monitorScale *= ((float)screenWidth/(float)(maxWidth + monitorOffsetX));
|
else monitorScale *= ((float)screenWidth/(float)(maxWidth + monitorOffsetX));
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -125,9 +125,9 @@ int main(void)
|
||||||
// Draw monitor name and information inside the rectangle
|
// Draw monitor name and information inside the rectangle
|
||||||
DrawText(TextFormat("[%i] %s", i, monitors[i].name), (int)rec.x + 10, (int)rec.y + (int)(100*monitorScale), (int)(120*monitorScale), BLUE);
|
DrawText(TextFormat("[%i] %s", i, monitors[i].name), (int)rec.x + 10, (int)rec.y + (int)(100*monitorScale), (int)(120*monitorScale), BLUE);
|
||||||
DrawText(
|
DrawText(
|
||||||
TextFormat("Resolution: [%ipx x %ipx]\nRefreshRate: [%ihz]\nPhysical Size: [%imm x %imm]\nPosition: %3.0f x %3.0f",
|
TextFormat("Resolution: [%ipx x %ipx]\nRefreshRate: [%ihz]\nPhysical Size: [%imm x %imm]\nPosition: %3.0f x %3.0f",
|
||||||
monitors[i].width,
|
monitors[i].width,
|
||||||
monitors[i].height,
|
monitors[i].height,
|
||||||
monitors[i].refreshRate,
|
monitors[i].refreshRate,
|
||||||
monitors[i].physicalWidth,
|
monitors[i].physicalWidth,
|
||||||
monitors[i].physicalHeight,
|
monitors[i].physicalHeight,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#define MAX_UNDO_STATES 26 // Maximum undo states supported for the ring buffer
|
#define MAX_UNDO_STATES 26 // Maximum undo states supported for the ring buffer
|
||||||
|
|
||||||
#define GRID_CELL_SIZE 24
|
#define GRID_CELL_SIZE 24
|
||||||
#define MAX_GRID_CELLS_X 30
|
#define MAX_GRID_CELLS_X 30
|
||||||
#define MAX_GRID_CELLS_Y 13
|
#define MAX_GRID_CELLS_Y 13
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
// We have multiple options to implement an Undo/Redo system
|
// We have multiple options to implement an Undo/Redo system
|
||||||
// Probably the most professional one is using the Command pattern to
|
// Probably the most professional one is using the Command pattern to
|
||||||
// define Actions and store those actions into an array as the events happen,
|
// define Actions and store those actions into an array as the events happen,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
// For itteration purposes and teaching example
|
// For itteration purposes and teaching example
|
||||||
#define RESOLUTION_COUNT 4
|
#define RESOLUTION_COUNT 4
|
||||||
|
|
||||||
enum ViewportType
|
enum ViewportType
|
||||||
{
|
{
|
||||||
// Only upscale, useful for pixel art
|
// Only upscale, useful for pixel art
|
||||||
KEEP_ASPECT_INTEGER,
|
KEEP_ASPECT_INTEGER,
|
||||||
|
|
@ -113,7 +113,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
Vector2 mousePosition = GetMousePosition();
|
Vector2 mousePosition = GetMousePosition();
|
||||||
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
||||||
|
|
||||||
// Check buttons and rescale
|
// Check buttons and rescale
|
||||||
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed){
|
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed){
|
||||||
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1) % RESOLUTION_COUNT;
|
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1) % RESOLUTION_COUNT;
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ int main(void)
|
||||||
anim_timer += GetFrameTime();
|
anim_timer += GetFrameTime();
|
||||||
|
|
||||||
// Update frame index after a certain amount of time (half a second)
|
// Update frame index after a certain amount of time (half a second)
|
||||||
if (anim_timer > 0.5f)
|
if (anim_timer > 0.5f)
|
||||||
{
|
{
|
||||||
anim_timer = 0.0f;
|
anim_timer = 0.0f;
|
||||||
anim += 1;
|
anim += 1;
|
||||||
|
|
|
||||||
|
|
@ -35,122 +35,122 @@
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
const char *voxFileNames[] = {
|
const char *voxFileNames[] = {
|
||||||
"resources/models/vox/chr_knight.vox",
|
"resources/models/vox/chr_knight.vox",
|
||||||
"resources/models/vox/chr_sword.vox",
|
"resources/models/vox/chr_sword.vox",
|
||||||
"resources/models/vox/monu9.vox",
|
"resources/models/vox/monu9.vox",
|
||||||
"resources/models/vox/fez.vox"
|
"resources/models/vox/fez.vox"
|
||||||
};
|
};
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - loading vox");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - loading vox");
|
||||||
|
|
||||||
// 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){ 10.0f, 10.0f, 10.0f }; // Camera position
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load MagicaVoxel files
|
// Load MagicaVoxel files
|
||||||
Model models[MAX_VOX_FILES] = { 0 };
|
Model models[MAX_VOX_FILES] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++)
|
for (int i = 0; i < MAX_VOX_FILES; i++)
|
||||||
{
|
{
|
||||||
// Load VOX file and measure time
|
// Load VOX file and measure time
|
||||||
double t0 = GetTime()*1000.0;
|
double t0 = GetTime()*1000.0;
|
||||||
models[i] = LoadModel(voxFileNames[i]);
|
models[i] = LoadModel(voxFileNames[i]);
|
||||||
double t1 = GetTime()*1000.0;
|
double t1 = GetTime()*1000.0;
|
||||||
|
|
||||||
TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
||||||
|
|
||||||
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
||||||
BoundingBox bb = GetModelBoundingBox(models[i]);
|
BoundingBox bb = GetModelBoundingBox(models[i]);
|
||||||
Vector3 center = { 0 };
|
Vector3 center = { 0 };
|
||||||
center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
|
center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
|
||||||
center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
|
center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
|
||||||
|
|
||||||
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
||||||
models[i].transform = matTranslate;
|
models[i].transform = matTranslate;
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
Vector3 modelpos = { 0 };
|
Vector3 modelpos = { 0 };
|
||||||
Vector3 camerarot = { 0 };
|
Vector3 camerarot = { 0 };
|
||||||
|
|
||||||
// Load voxel shader
|
// Load voxel shader
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/voxel_lighting.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/voxel_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);
|
||||||
|
|
||||||
// Assign out lighting shader to model
|
// Assign out lighting shader to model
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++)
|
for (int i = 0; i < MAX_VOX_FILES; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < models[i].materialCount; j++) models[i].materials[j].shader = shader;
|
for (int j = 0; j < models[i].materialCount; j++) models[i].materials[j].shader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create lights
|
// Create lights
|
||||||
Light lights[MAX_LIGHTS] = { 0 };
|
Light lights[MAX_LIGHTS] = { 0 };
|
||||||
lights[0] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, -20 }, Vector3Zero(), GRAY, shader);
|
lights[0] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, -20 }, Vector3Zero(), GRAY, shader);
|
||||||
lights[1] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, 20 }, Vector3Zero(), GRAY, shader);
|
lights[1] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, 20 }, Vector3Zero(), GRAY, shader);
|
||||||
lights[2] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, 20 }, Vector3Zero(), GRAY, shader);
|
lights[2] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, 20 }, Vector3Zero(), GRAY, shader);
|
||||||
lights[3] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, -20 }, Vector3Zero(), GRAY, shader);
|
lights[3] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, -20 }, Vector3Zero(), GRAY, shader);
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE))
|
if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE))
|
||||||
{
|
{
|
||||||
const Vector2 mouseDelta = GetMouseDelta();
|
const Vector2 mouseDelta = GetMouseDelta();
|
||||||
camerarot.x = mouseDelta.x*0.05f;
|
camerarot.x = mouseDelta.x*0.05f;
|
||||||
camerarot.y = mouseDelta.y*0.05f;
|
camerarot.y = mouseDelta.y*0.05f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
camerarot.x = 0;
|
camerarot.x = 0;
|
||||||
camerarot.y = 0;
|
camerarot.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateCameraPro(&camera,
|
UpdateCameraPro(&camera,
|
||||||
(Vector3){ (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, // Move forward-backward
|
(Vector3){ (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, // Move forward-backward
|
||||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, // Move right-left
|
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, // Move right-left
|
||||||
0.0f }, // Move up-down
|
0.0f }, // Move up-down
|
||||||
camerarot, // Camera rotation
|
camerarot, // Camera rotation
|
||||||
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
||||||
|
|
||||||
// Cycle between models on mouse click
|
// Cycle between models on mouse click
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1) % MAX_VOX_FILES;
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1) % MAX_VOX_FILES;
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
// 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]);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
|
@ -175,17 +175,17 @@ int main(void)
|
||||||
DrawText("- UP-DOWN-LEFT-RIGHT KEYS: MOVE CAMERA", 20, 90, 10, BLUE);
|
DrawText("- UP-DOWN-LEFT-RIGHT KEYS: MOVE CAMERA", 20, 90, 10, BLUE);
|
||||||
DrawText(TextFormat("Model file: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
|
DrawText(TextFormat("Model file: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Unload models data (GPU VRAM)
|
// Unload models data (GPU VRAM)
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++) UnloadModel(models[i]);
|
for (int i = 0; i < MAX_VOX_FILES; i++) UnloadModel(models[i]);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
|
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
|
||||||
*
|
*
|
||||||
* Example contributed by Jopestpe (@jopestpe)
|
* Example contributed by Jopestpe (@jopestpe)
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
|
@ -48,7 +48,7 @@ int main(void)
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||||
|
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ int main(void)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
rotation += 1.0f;
|
rotation += 1.0f;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
@ -67,13 +67,13 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
// Draw model defining: position, size, rotation-axis, rotation (degrees), size, and tint-color
|
// Draw model defining: position, size, rotation-axis, rotation (degrees), size, and tint-color
|
||||||
DrawModelEx(model, (Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.5f, 1.0f, 0.0f },
|
DrawModelEx(model, (Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.5f, 1.0f, 0.0f },
|
||||||
rotation, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
|
rotation, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NoEase function, used when "no easing" is selected for any axis
|
// NoEase function, used when "no easing" is selected for any axis
|
||||||
// It just ignores all parameters besides b
|
// It just ignores all parameters besides b
|
||||||
static float NoEase(float t, float b, float c, float d)
|
static float NoEase(float t, float b, float c, float d)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -87,15 +87,15 @@ int main(void)
|
||||||
DrawTexture(fudesumi, 500, -30, WHITE);
|
DrawTexture(fudesumi, 500, -30, WHITE);
|
||||||
DrawTextureV(raysan, circlePos, WHITE);
|
DrawTextureV(raysan, circlePos, WHITE);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
// Draw the scene texture (that we rendered earlier) to the screen
|
// Draw the scene texture (that we rendered earlier) to the screen
|
||||||
// The shader will process every pixel of this texture
|
// The shader will process every pixel of this texture
|
||||||
DrawTextureRec(target.texture,
|
DrawTextureRec(target.texture,
|
||||||
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
|
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
|
||||||
(Vector2){ 0, 0 }, WHITE);
|
(Vector2){ 0, 0 }, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ int main(void)
|
||||||
SetShaderValue(shader, emissiveColorLoc, &carEmissiveColor, SHADER_UNIFORM_VEC4);
|
SetShaderValue(shader, emissiveColorLoc, &carEmissiveColor, SHADER_UNIFORM_VEC4);
|
||||||
float emissiveIntensity = 0.01f;
|
float emissiveIntensity = 0.01f;
|
||||||
SetShaderValue(shader, emissiveIntensityLoc, &emissiveIntensity, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, emissiveIntensityLoc, &emissiveIntensity, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
@ -252,7 +252,7 @@ int main(void)
|
||||||
// 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){
|
Color lightColor = (Color){
|
||||||
(unsigned char)(lights[i].color[0]*255),
|
(unsigned char)(lights[i].color[0]*255),
|
||||||
(unsigned char)(lights[i].color[1] * 255),
|
(unsigned char)(lights[i].color[1] * 255),
|
||||||
(unsigned char)(lights[i].color[2] * 255),
|
(unsigned char)(lights[i].color[2] * 255),
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ int main(void)
|
||||||
);
|
);
|
||||||
BeginBlendMode(BLEND_ALPHA);
|
BeginBlendMode(BLEND_ALPHA);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// NOTE: To enable trilinear filtering we need mipmaps available for texture
|
// NOTE: To enable trilinear filtering we need mipmaps available for texture
|
||||||
GenTextureMipmaps(&lightmap.texture);
|
GenTextureMipmaps(&lightmap.texture);
|
||||||
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
|
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
|
||||||
|
|
@ -143,7 +143,7 @@ int main(void)
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
@ -155,7 +155,7 @@ int main(void)
|
||||||
(Vector2){ 0.0, 0.0 }, 0.0, WHITE);
|
(Vector2){ 0.0, 0.0 }, 0.0, WHITE);
|
||||||
|
|
||||||
DrawText(TextFormat("LIGHTMAP: %ix%i pixels", MAP_SIZE, MAP_SIZE), GetRenderWidth() - 130, 20 + MAP_SIZE*8, 10, GREEN);
|
DrawText(TextFormat("LIGHTMAP: %ix%i pixels", MAP_SIZE, MAP_SIZE), GetRenderWidth() - 130, 20 + MAP_SIZE*8, 10, GREEN);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ int main(void)
|
||||||
// Shadows are a HUGE topic, and this example shows an extremely simple implementation of the shadowmapping algorithm,
|
// Shadows are a HUGE topic, and this example shows an extremely simple implementation of the shadowmapping algorithm,
|
||||||
// which is the industry standard for shadows. This algorithm can be extended in a ridiculous number of ways to improve
|
// which is the industry standard for shadows. This algorithm can be extended in a ridiculous number of ways to improve
|
||||||
// realism and also adapt it for different scenes. This is pretty much the simplest possible implementation
|
// realism and also adapt it for different scenes. This is pretty much the simplest possible implementation
|
||||||
|
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shadowmap rendering");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shadowmap rendering");
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ int main(void)
|
||||||
Shader shadowShader = LoadShader(TextFormat("resources/shaders/glsl%i/shadowmap.vs", GLSL_VERSION),
|
Shader shadowShader = LoadShader(TextFormat("resources/shaders/glsl%i/shadowmap.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/shadowmap.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/shadowmap.fs", GLSL_VERSION));
|
||||||
shadowShader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shadowShader, "viewPos");
|
shadowShader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shadowShader, "viewPos");
|
||||||
|
|
||||||
Vector3 lightDir = Vector3Normalize((Vector3){ 0.35f, -1.0f, -0.35f });
|
Vector3 lightDir = Vector3Normalize((Vector3){ 0.35f, -1.0f, -0.35f });
|
||||||
Color lightColor = WHITE;
|
Color lightColor = WHITE;
|
||||||
Vector4 lightColorNormalized = ColorNormalize(lightColor);
|
Vector4 lightColorNormalized = ColorNormalize(lightColor);
|
||||||
|
|
@ -83,7 +83,7 @@ int main(void)
|
||||||
ModelAnimation *robotAnimations = LoadModelAnimations("resources/models/robot.glb", &animCount);
|
ModelAnimation *robotAnimations = LoadModelAnimations("resources/models/robot.glb", &animCount);
|
||||||
|
|
||||||
RenderTexture2D shadowMap = LoadShadowmapRenderTexture(SHADOWMAP_RESOLUTION, SHADOWMAP_RESOLUTION);
|
RenderTexture2D shadowMap = LoadShadowmapRenderTexture(SHADOWMAP_RESOLUTION, SHADOWMAP_RESOLUTION);
|
||||||
|
|
||||||
// For the shadowmapping algorithm, we will be rendering everything from the light's point of view
|
// For the shadowmapping algorithm, we will be rendering everything from the light's point of view
|
||||||
Camera3D lightCamera = { 0 };
|
Camera3D lightCamera = { 0 };
|
||||||
lightCamera.position = Vector3Scale(lightDir, -15.0f);
|
lightCamera.position = Vector3Scale(lightDir, -15.0f);
|
||||||
|
|
@ -91,9 +91,9 @@ int main(void)
|
||||||
lightCamera.projection = CAMERA_ORTHOGRAPHIC; // Use an orthographic projection for directional lights
|
lightCamera.projection = CAMERA_ORTHOGRAPHIC; // Use an orthographic projection for directional lights
|
||||||
lightCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
lightCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
lightCamera.fovy = 20.0f;
|
lightCamera.fovy = 20.0f;
|
||||||
|
|
||||||
int frameCounter = 0;
|
int frameCounter = 0;
|
||||||
|
|
||||||
// Store the light matrices
|
// Store the light matrices
|
||||||
Matrix lightView = { 0 };
|
Matrix lightView = { 0 };
|
||||||
Matrix lightProj = { 0 };
|
Matrix lightProj = { 0 };
|
||||||
|
|
@ -136,7 +136,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
if (lightDir.z > -0.6f) lightDir.z -= cameraSpeed*60.0f*deltaTime;
|
if (lightDir.z > -0.6f) lightDir.z -= cameraSpeed*60.0f*deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
lightDir = Vector3Normalize(lightDir);
|
lightDir = Vector3Normalize(lightDir);
|
||||||
lightCamera.position = Vector3Scale(lightDir, -15.0f);
|
lightCamera.position = Vector3Scale(lightDir, -15.0f);
|
||||||
SetShaderValue(shadowShader, lightDirLoc, &lightDir, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shadowShader, lightDirLoc, &lightDir, SHADER_UNIFORM_VEC3);
|
||||||
|
|
@ -151,13 +151,13 @@ int main(void)
|
||||||
// to determine whether a given point is "visible" to the light
|
// to determine whether a given point is "visible" to the light
|
||||||
BeginTextureMode(shadowMap);
|
BeginTextureMode(shadowMap);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
BeginMode3D(lightCamera);
|
BeginMode3D(lightCamera);
|
||||||
lightView = rlGetMatrixModelview();
|
lightView = rlGetMatrixModelview();
|
||||||
lightProj = rlGetMatrixProjection();
|
lightProj = rlGetMatrixProjection();
|
||||||
DrawScene(cube, robot);
|
DrawScene(cube, robot);
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
lightViewProj = MatrixMultiply(lightView, lightProj);
|
lightViewProj = MatrixMultiply(lightView, lightProj);
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ int main(void)
|
||||||
|
|
||||||
SetShaderValueMatrix(shadowShader, lightVPLoc, lightViewProj);
|
SetShaderValueMatrix(shadowShader, lightVPLoc, lightViewProj);
|
||||||
rlEnableShader(shadowShader.id);
|
rlEnableShader(shadowShader.id);
|
||||||
|
|
||||||
rlActiveTextureSlot(textureActiveSlot);
|
rlActiveTextureSlot(textureActiveSlot);
|
||||||
rlEnableTexture(shadowMap.depth.id);
|
rlEnableTexture(shadowMap.depth.id);
|
||||||
rlSetUniform(shadowMapLoc, &textureActiveSlot, SHADER_UNIFORM_INT, 1);
|
rlSetUniform(shadowMapLoc, &textureActiveSlot, SHADER_UNIFORM_INT, 1);
|
||||||
|
|
@ -178,7 +178,7 @@ int main(void)
|
||||||
|
|
||||||
DrawText("Use the arrow keys to rotate the light!", 10, 10, 30, RED);
|
DrawText("Use the arrow keys to rotate the light!", 10, 10, 30, RED);
|
||||||
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 280, screenHeight - 20, 10, GRAY);
|
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 280, screenHeight - 20, 10, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_F)) TakeScreenshot("shaders_shadowmap.png");
|
if (IsKeyPressed(KEY_F)) TakeScreenshot("shaders_shadowmap.png");
|
||||||
|
|
@ -200,7 +200,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load render texture for shadowmap projection
|
// Load render texture for shadowmap projection
|
||||||
// NOTE: Load framebuffer with only a texture depth attachment,
|
// NOTE: Load framebuffer with only a texture depth attachment,
|
||||||
// no color attachment required for shadowmap
|
// no color attachment required for shadowmap
|
||||||
static RenderTexture2D LoadShadowmapRenderTexture(int width, int height)
|
static RenderTexture2D LoadShadowmapRenderTexture(int width, int height)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ int main(void)
|
||||||
static void ResetStar(Star *star)
|
static void ResetStar(Star *star)
|
||||||
{
|
{
|
||||||
star->position = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
star->position = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||||
|
|
||||||
star->speed.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
star->speed.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
star->speed.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
star->speed.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ static void ResetStar(Star *star)
|
||||||
{
|
{
|
||||||
star->speed.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
star->speed.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
star->speed.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
star->speed.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
star->position = Vector2Add(star->position, Vector2Multiply(star->speed, (Vector2){ 8.0f, 8.0f }));
|
star->position = Vector2Add(star->position, Vector2Multiply(star->speed, (Vector2){ 8.0f, 8.0f }));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
||||||
*
|
*
|
||||||
* Example contributed by Ramon Santamaria (@raysan5), reviewed by Jopestpe (@jopestpe)
|
* Example contributed by Ramon Santamaria (@raysan5), reviewed by Jopestpe (@jopestpe)
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
*
|
*
|
||||||
|
|
@ -49,14 +49,14 @@ int main(void)
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_G)) useGravity = !useGravity;
|
if (IsKeyPressed(KEY_G)) useGravity = !useGravity;
|
||||||
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
||||||
|
|
||||||
if (!pause)
|
if (!pause)
|
||||||
{
|
{
|
||||||
ballPosition.x += ballSpeed.x;
|
ballPosition.x += ballSpeed.x;
|
||||||
ballPosition.y += ballSpeed.y;
|
ballPosition.y += ballSpeed.y;
|
||||||
|
|
||||||
if (useGravity) ballSpeed.y += gravity;
|
if (useGravity) ballSpeed.y += gravity;
|
||||||
|
|
||||||
// Check walls collision for bouncing
|
// Check walls collision for bouncing
|
||||||
if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
|
if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
|
||||||
if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -0.95f;
|
if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -0.95f;
|
||||||
|
|
@ -72,7 +72,7 @@ int main(void)
|
||||||
|
|
||||||
DrawCircleV(ballPosition, (float)ballRadius, MAROON);
|
DrawCircleV(ballPosition, (float)ballRadius, MAROON);
|
||||||
DrawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY);
|
DrawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY);
|
||||||
|
|
||||||
if (useGravity) DrawText("GRAVITY: ON (Press G to disable)", 10, GetScreenHeight() - 50, 20, DARKGREEN);
|
if (useGravity) DrawText("GRAVITY: ON (Press G to disable)", 10, GetScreenHeight() - 50, 20, DARKGREEN);
|
||||||
else DrawText("GRAVITY: OFF (Press G to enable)", 10, GetScreenHeight() - 50, 20, RED);
|
else DrawText("GRAVITY: OFF (Press G to enable)", 10, GetScreenHeight() - 50, 20, RED);
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ int main(void)
|
||||||
if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY);
|
if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue