EXAMPLES: Format tweaks

This commit is contained in:
Ray
2025-08-07 17:08:22 +02:00
parent 9f07cfe0b7
commit f0889a74fe
91 changed files with 409 additions and 397 deletions

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [audio] example - Mixed audio processing
* raylib [audio] example - mixed audio processing
*
* Example complexity rating: [★★★★] 4/4
*

View File

@@ -45,7 +45,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
{

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [audio] example - Playing spatialized 3D sound
* raylib [audio] example - spatialized 3D sound
*
* Example complexity rating: [★★☆☆] 2/4
*
@@ -31,9 +31,9 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Playing spatialized 3D sound");
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
InitAudioDevice();
Sound sound = LoadSound("resources/coin.wav");
@@ -45,9 +45,9 @@ int main(void)
.fovy = 60,
.projection = CAMERA_PERSPECTIVE
};
DisableCursor();
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -89,7 +89,7 @@ int main(void)
//--------------------------------------------------------------------------------------
UnloadSound(sound);
CloseAudioDevice(); // Close audio device
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
Vector3 direction = Vector3Subtract(position, listener.position);
float distance = Vector3Length(direction);
// Apply logarithmic distance attenuation and clamp between 0-1
float attenuation = 1.0f/(1.0f + (distance/maxDist));
attenuation = Clamp(attenuation, 0.0f, 1.0f);
// Calculate normalized vectors for spatial positioning
Vector3 normalizedDirection = Vector3Normalize(direction);
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
// Reduce volume for sounds behind the listener
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
// Set stereo panning based on sound position relative to listener
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
// Apply final sound properties
SetSoundVolume(sound, attenuation);
SetSoundPan(sound, pan);

View File

@@ -53,7 +53,7 @@ int main(void)
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
bool pause = false; // Music playing paused
bool enableEffectLPF = false; // Enable effect low-pass-filter
bool enableEffectDelay = false; // Enable effect delay (1 second)
@@ -98,7 +98,7 @@ int main(void)
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
}
// Get normalized time played for current music stream
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
@@ -119,7 +119,7 @@ int main(void)
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 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 D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);

View File

@@ -47,7 +47,7 @@ int main ()
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
// Translate based on mouse right click
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
@@ -68,7 +68,7 @@ int main ()
// Set the offset to where the mouse is
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
camera.target = mouseWorldPos;
@@ -89,7 +89,7 @@ int main ()
// Set the offset to where the mouse is
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
camera.target = mouseWorldPos;
}
@@ -111,7 +111,7 @@ int main ()
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
rlPushMatrix();
rlTranslatef(0, 25*50, 0);
@@ -121,19 +121,19 @@ int main ()
// Draw a reference circle
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
EndMode2D();
// Draw mouse reference
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
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);
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);
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -137,7 +137,7 @@ int main(void)
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
DrawRectangleRec(playerRect, RED);
DrawCircleV(player.position, 5.0f, GOLD);
EndMode2D();

View File

@@ -4,7 +4,7 @@
*
* 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
*
* Example originally created with raylib 4.5, last time updated with raylib 4.5
@@ -81,9 +81,9 @@ int main(void)
//----------------------------------------------------------------------------------
BeginTextureMode(screenCamera1);
ClearBackground(RAYWHITE);
BeginMode2D(camera1);
// Draw full scene with first camera
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
{
@@ -106,17 +106,17 @@ int main(void)
DrawRectangleRec(player1, RED);
DrawRectangleRec(player2, BLUE);
EndMode2D();
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
EndTextureMode();
BeginTextureMode(screenCamera2);
ClearBackground(RAYWHITE);
BeginMode2D(camera2);
// Draw full scene with second camera
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
{
@@ -138,21 +138,21 @@ int main(void)
DrawRectangleRec(player1, RED);
DrawRectangleRec(player2, BLUE);
EndMode2D();
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
EndTextureMode();
// Draw both views render textures to the screen side by side
BeginDrawing();
ClearBackground(BLACK);
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
EndDrawing();
}

View File

@@ -127,7 +127,7 @@ int main(void)
UpdateCameraPro(&camera,
(Vector3){
(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_A) || IsKeyDown(KEY_LEFT))*0.1f,
0.0f // Move up-down

View File

@@ -51,7 +51,7 @@ int main(void)
// 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 };
// Grid data
int count = 5;
float spacing = 4;
@@ -98,9 +98,9 @@ int main(void)
// Draw Player1 view to the render texture
BeginTextureMode(screenPlayer1);
ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer1);
// 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
@@ -116,20 +116,20 @@ int main(void)
// Draw a cube at each player's position
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
EndMode3D();
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
EndTextureMode();
// Draw Player2 view to the render texture
BeginTextureMode(screenPlayer2);
ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer2);
// 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
@@ -145,21 +145,21 @@ int main(void)
// Draw a cube at each player's position
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
EndMode3D();
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
EndTextureMode();
// Draw both views render textures to the screen side by side
BeginDrawing();
ClearBackground(BLACK);
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
EndDrawing();
}

View File

@@ -54,7 +54,7 @@ int main(void)
player.position = (Vector2){ 400, 280 };
player.speed = 0;
player.canJump = false;
// Define environment elements (platforms)
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
@@ -70,13 +70,13 @@ int main(void)
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
camera.rotation = 0.0f;
camera.zoom = 1.0f;
// Automation events
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
SetAutomationEventList(&aelist);
bool eventRecording = false;
bool eventPlaying = false;
unsigned int frameCounter = 0;
unsigned int playFrameCounter = 0;
unsigned int currentPlayFrame = 0;
@@ -90,7 +90,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
float deltaTime = 0.015f;//GetFrameTime();
// Dropped files logic
//----------------------------------------------------------------------------------
if (IsFileDropped())
@@ -102,14 +102,14 @@ int main(void)
{
UnloadAutomationEventList(aelist);
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
eventRecording = false;
// Reset scene state to play
eventPlaying = true;
playFrameCounter = 0;
currentPlayFrame = 0;
player.position = (Vector2){ 400, 280 };
player.speed = 0;
player.canJump = false;
@@ -174,7 +174,7 @@ int main(void)
//----------------------------------------------------------------------------------
// 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
//----------------------------------------------------------------------------------
if (eventPlaying)
@@ -228,7 +228,7 @@ int main(void)
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
//----------------------------------------------------------------------------------
// Events management
if (IsKeyPressed(KEY_S)) // Toggle events recording
{
@@ -238,12 +238,12 @@ int main(void)
{
StopAutomationEventRecording();
eventRecording = false;
ExportAutomationEventList(aelist, "automation.rae");
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
}
else
else
{
SetAutomationEventBaseFrame(180);
StartAutomationEventRecording();
@@ -293,7 +293,7 @@ int main(void)
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
EndMode2D();
// Draw game controls
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
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);
}
EndDrawing();
//----------------------------------------------------------------------------------

View File

@@ -39,7 +39,7 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
// Custom timming variables
@@ -48,11 +48,11 @@ int main(void)
double updateDrawTime = 0.0; // Update + Draw time
double waitTime = 0.0; // Wait time (if target fps required)
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
float timeCounter = 0.0f; // Accumulative time counter (seconds)
float position = 0.0f; // Circle position
bool pause = false; // Pause control flag
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
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
#endif
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
if (targetFPS < 0) targetFPS = 0;
if (!pause)
@@ -91,12 +91,12 @@ int main(void)
ClearBackground(RAYWHITE);
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
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("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("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
@@ -108,18 +108,18 @@ int main(void)
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
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
currentTime = GetTime();
updateDrawTime = currentTime - previousTime;
if (targetFPS > 0) // We want a fixed frame rate
{
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
if (waitTime > 0.0)
if (waitTime > 0.0)
{
WaitTime((float)waitTime);
currentTime = GetTime();

View File

@@ -13,12 +13,10 @@
#include "raylib.h"
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);
}
//------------------------------------------------------------------------------------
// Module functions declaration
//------------------------------------------------------------------------------------
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
//------------------------------------------------------------------------------------
// Program main entry point
@@ -31,10 +29,20 @@ int main(void)
const int screenHeight = 450;
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
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
//--------------------------------------------------------------------------------------
@@ -44,67 +52,60 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
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();
Vector2 dpiScale = GetWindowScaleDPI();
cellSizePx = ((float)cellSize)/dpiScale.x;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
Vector2 dpiScale = GetWindowScaleDPI();
ClearBackground(RAYWHITE);
int windowCenter = GetScreenWidth() / 2;
int windowCenter = GetScreenWidth()/2;
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);
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("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, LIGHTGRAY);
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
bool odd = true;
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
if (odd) {
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
}
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY);
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
{
if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
}
odd = true;
const int minTextSpace = 30;
int last_text_x = -minTextSpace;
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
int x = (int)(((float)i) / dpiScale.x);
if (odd) {
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
}
int lastTextX = -minTextSpace;
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
{
int x = (int)(((float)i)/dpiScale.x);
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);
if (x - last_text_x >= minTextSpace) {
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 12, LIGHTGRAY);
last_text_x = x;
if ((x - lastTextX) >= minTextSpace)
{
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
lastTextX = x;
}
}
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
{
const char *text = "Can you see this?";
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3);
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5};
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
}
const char *text = "Can you see this?";
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -117,3 +118,13 @@ int main(void)
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);
}

View File

@@ -52,7 +52,7 @@ int main(void)
isCursorHidden = 0;
}
}
ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;

View File

@@ -54,7 +54,7 @@ int main(void)
BeginDrawing();
ClearBackground(RAYWHITE);
for (int i = 0; i < tCount; ++i)
{
// Make sure point is not (0, 0) as this means there is no touch for it

View File

@@ -7,7 +7,7 @@
* Example originally created with raylib 5.0, last time updated with raylib 5.0
*
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
* lighter by oblerion (@oblerion) and
* lighter by oblerion (@oblerion) and
* reviewed by Ramon Santamaria (@raysan5) and
* improved by danilwhale (@danilwhale)
*

View File

@@ -4,7 +4,7 @@
*
* 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
*
* Example originally created with raylib 2.5, last time updated with raylib 3.0

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [core] example - Generates a random sequence
* raylib [core] example - generate random sequence
*
* Example complexity rating: [★☆☆☆] 1/4
*
@@ -43,7 +43,7 @@ int main(void)
const int screenWidth = 800;
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;
float rectSize = (float)screenWidth/rectCount;
@@ -118,8 +118,8 @@ int main(void)
//------------------------------------------------------------------------------------
static Color GenerateRandomColor()
{
Color color = {
GetRandomValue(0, 255),
Color color = {
GetRandomValue(0, 255),
GetRandomValue(0, 255),
GetRandomValue(0, 255),
255
@@ -138,20 +138,20 @@ static ColorRect *GenerateRandomColorRectSequence(float rectCount, float rectWid
for (int i = 0; i < rectCount; i++)
{
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
rectangles[i].c = GenerateRandomColor();
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
}
UnloadRandomSequence(seq);
return rectangles;
}
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
{
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
for (int i1 = 0; i1 < rectCount; i1++)
{
ColorRect *r1 = &rectangles[i1];
@@ -166,16 +166,16 @@ static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
r2->r.height = tmp.r.height;
r2->r.y = tmp.r.y;
}
UnloadRandomSequence(seq);
}
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
{
int spaceSize = MeasureText(" ", fontSize);
int pressSize = MeasureText("Press", fontSize);
int keySize = MeasureText(key, fontSize);
int textSize = MeasureText(text, fontSize);
int spaceSize = MeasureText(" ", fontSize);
int pressSize = MeasureText("Press", fontSize);
int keySize = MeasureText(key, fontSize);
int textSize = MeasureText(text, fontSize);
int textSizeCurrent = 0;
DrawText("Press", posX, posY, fontSize, color);

View File

@@ -30,9 +30,9 @@ int main(void)
// 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)
unsigned int framesCounter = 0; // Variable used to count frames
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

View File

@@ -5,7 +5,7 @@
* Example complexity rating: [★★★☆] 3/4
*
* Example originally created with raylib 3.7, last time updated with raylib 4.0
*
*
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
* reviewed by Ramon Santamaria (@raysan5)
*

View File

@@ -127,7 +127,7 @@ int main(void)
EndMode3D();
EndVrStereoMode();
EndTextureMode();
BeginDrawing();
ClearBackground(RAYWHITE);
BeginShaderMode(distortion);

View File

@@ -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("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
EndTextureMode();
BeginDrawing();
ClearBackground(BLACK); // Clear screen background

View File

@@ -26,9 +26,9 @@ int main()
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close");
SetExitKey(KEY_NULL); // Disable KEY_ESCAPE to close window, X-button still works
bool exitWindowRequested = false; // Flag to request 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
if (WindowShouldClose() || IsKeyPressed(KEY_ESCAPE)) exitWindowRequested = true;
if (exitWindowRequested)
{
// A request for close window has been issued, we can save data before closing
// or just show a message asking for confirmation
if (IsKeyPressed(KEY_Y)) exitWindow = true;
else if (IsKeyPressed(KEY_N)) exitWindowRequested = false;
}

View File

@@ -70,7 +70,7 @@ int main(void)
EndMode3D();
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("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);

View File

@@ -15,8 +15,8 @@
*
********************************************************************************************
*
* 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
* 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
* set to 0. Scaling can be done from the export menu.
*
********************************************************************************************/

View File

@@ -85,17 +85,17 @@ int main(void)
DrawGrid(10, 1.0f); // Draw a grid
// Draw order matters!
if (distanceStatic > distanceRotating)
if (distanceStatic > distanceRotating)
{
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
}
}
else
{
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
}
EndMode3D();
DrawFPS(10, 10);

View File

@@ -3,7 +3,7 @@
* raylib [core] example - Using bones as socket for calculating the positioning of something
*
* Example complexity rating: [★★★★] 4/4
*
*
* 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)
@@ -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_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
// Load gltf model animations
@@ -63,7 +63,7 @@ int main(void)
// indices of bones for sockets
int boneSocketIndex[BONE_SOCKETS] = { -1, -1, -1 };
// search bones for sockets
// search bones for sockets
for (int i = 0; i < characterModel.boneCount; i++)
{
if (TextIsEqual(characterModel.bones[i].name, "socket_hat"))
@@ -71,13 +71,13 @@ int main(void)
boneSocketIndex[BONE_SOCKET_HAT] = i;
continue;
}
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_R"))
{
boneSocketIndex[BONE_SOCKET_HAND_R] = i;
continue;
}
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_L"))
{
boneSocketIndex[BONE_SOCKET_HAND_L] = i;
@@ -99,7 +99,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
// Rotate character
if (IsKeyDown(KEY_F)) angle = (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_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];
// Update model animation
ModelAnimation anim = modelAnimations[animIndex];
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
@@ -140,7 +140,7 @@ int main(void)
Transform *transform = &anim.framePoses[animCurrentFrame][boneSocketIndex[i]];
Quaternion inRotation = characterModel.bindPose[boneSocketIndex[i]].rotation;
Quaternion outRotation = transform->rotation;
// Calculate socket rotation (angle between bone in initial pose and same bone in current animation frame)
Quaternion rotate = QuaternionMultiply(outRotation, QuaternionInvert(inRotation));
Matrix matrixTransform = QuaternionToMatrix(rotate);
@@ -148,7 +148,7 @@ int main(void)
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)
matrixTransform = MatrixMultiply(matrixTransform, characterModel.transform);
// Draw mesh at socket position with socket angle rotation
DrawMesh(equipModel[i].meshes[0], equipModel[i].materials[1], matrixTransform);
}
@@ -168,7 +168,7 @@ int main(void)
//--------------------------------------------------------------------------------------
UnloadModelAnimations(modelAnimations, animsCount);
UnloadModel(characterModel); // Unload character model and meshes/material
// Unload equipment model and meshes/material
for (int i = 0; i < BONE_SOCKETS; i++) UnloadModel(equipModel[i]);

View File

@@ -42,7 +42,7 @@ int main(void)
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE;
// Load texture to be applied to the cubes sides
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);
// 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);
DrawGrid(10, 1.0f); // Draw a grid
@@ -85,7 +85,7 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
@@ -171,7 +171,7 @@ void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, f
rlSetTexture(texture.id);
// 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);
rlColor4ub(color.r, color.g, color.b, color.a);

View File

@@ -3,7 +3,7 @@
* raylib [core] example - Doing skinning on the gpu using a vertex shader
*
* Example complexity rating: [★★★☆] 3/4
*
*
* 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)
@@ -12,7 +12,7 @@
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2024-2025 Daniel Holden (@orangeduck)
*
*
* 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
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
// Load skinning shader
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
characterModel.materials[1].shader = skinningShader;
// Load gltf model animations
int animsCount = 0;
unsigned int animIndex = 0;
@@ -75,7 +75,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
// Select current animation
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
@@ -94,12 +94,12 @@ int main(void)
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Draw character mesh, pose calculation is done in shader (GPU skinning)
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
DrawGrid(10, 1.0f);
EndMode3D();
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
UnloadModel(characterModel); // Unload model and meshes/material
UnloadShader(skinningShader); // Unload GPU skinning shader
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

View File

@@ -45,7 +45,7 @@ int main(void)
// Load gltf model
Model model = LoadModel("resources/models/gltf/robot.glb");
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
// Load gltf model animations
int animsCount = 0;
unsigned int animIndex = 0;

View File

@@ -47,7 +47,7 @@ int main(void)
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
models[8] = LoadModelFromMesh(GenMeshCustom());
// NOTE: Generated meshes could be exported using ExportMesh()
// Set checked texture as default diffuse component for all models material

View File

@@ -137,7 +137,7 @@ int main(void)
RayCollision meshHitInfo = { 0 };
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
// model drawn multiple times with multiple transforms
meshHitInfo = GetRayCollisionMesh(ray, tower.meshes[m], tower.transform);
@@ -145,7 +145,7 @@ int main(void)
{
// Save the closest hit mesh
if ((!collision.hit) || (collision.distance > meshHitInfo.distance)) collision = meshHitInfo;
break; // Stop once one mesh collision is detected, the colliding mesh is m
}
}

View File

@@ -35,7 +35,7 @@ int main()
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - point rendering");
Camera camera = {
@@ -50,10 +50,10 @@ int main()
bool useDrawModelPoints = true;
bool numPointsChanged = false;
int numPoints = 1000;
Mesh mesh = GenMeshPoints(numPoints);
Model model = LoadModelFromMesh(mesh);
//SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -114,14 +114,14 @@ int main()
.b = mesh.colors[i*4 + 2],
.a = mesh.colors[i*4 + 3],
};
DrawPoint3D(pos, color);
}
}
// Draw a unit sphere for reference
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
EndMode3D();
// Draw UI text
@@ -129,12 +129,12 @@ int main()
DrawText("Up - increase points", 20, 70, 20, WHITE);
DrawText("Down - decrease points", 20, 100, 20, WHITE);
DrawText("Space - drawing function", 20, 130, 20, WHITE);
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
@@ -151,7 +151,7 @@ int main()
// Generate a spherical point cloud
static Mesh GenMeshPoints(int numPoints)
{
Mesh mesh = {
Mesh mesh = {
.triangleCount = 1,
.vertexCount = numPoints,
.vertices = (float *)MemAlloc(numPoints*3*sizeof(float)),
@@ -164,13 +164,13 @@ static Mesh GenMeshPoints(int numPoints)
float theta = ((float)PI*rand())/RAND_MAX;
float phi = (2.0f*PI*rand())/RAND_MAX;
float r = (10.0f*rand())/RAND_MAX;
mesh.vertices[i*3 + 0] = r*sinf(theta)*cosf(phi);
mesh.vertices[i*3 + 1] = r*sinf(theta)*sinf(phi);
mesh.vertices[i*3 + 2] = r*cosf(theta);
Color color = ColorFromHSV(r*360.0f, 1.0f, 1.0f);
mesh.colors[i*4 + 0] = color.r;
mesh.colors[i*4 + 1] = color.g;
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
UploadMesh(&mesh, false);
return mesh;
}

View File

@@ -70,7 +70,7 @@ int main(void)
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
char skyboxFileName[256] = { 0 };
if (useHDR)
{
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
@@ -116,7 +116,7 @@ int main(void)
{
// Unload current cubemap texture to load new one
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
if (useHDR)
{
// Load HDR panorama (sphere) texture
@@ -124,7 +124,7 @@ int main(void)
// Generate cubemap from panorama texture
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
}
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
// Activate and enable texture for drawing to cubemap faces
rlActiveTextureSlot(0);
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
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
// Select the current cubemap face attachment for the 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);

View File

@@ -32,7 +32,7 @@ int main(void)
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - tesseract view");
// Define the camera to look into our 3d world
Camera camera = { 0 };
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
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 },
};
float rotation = 0.0f;
Vector3 transformed[16] = { 0 };
float wValues[16] = { 0 };
@@ -66,7 +66,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
rotation = DEG2RAD*45.0f*GetTime();
for (int i = 0; i < 16; i++)
{
Vector4 p = tesseract[i];
@@ -92,9 +92,9 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
for (int i = 0; i < 16; i++)
{
@@ -114,7 +114,7 @@ int main(void)
}
}
EndMode3D();
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -91,7 +91,7 @@ int main()
};
// 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
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);

View File

@@ -30,18 +30,18 @@
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
#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 glBindVertexArray glBindVertexArrayOES
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define GLSL_VERSION 100
#else
#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/gl3ext.h> // OpenGL 3 extensions library for OSX
#else
#include "glad.h" // Required for: OpenGL functionality
#include "glad.h" // Required for: OpenGL functionality
#endif
#define GLSL_VERSION 330
#endif
@@ -71,7 +71,7 @@ int main(void)
const int screenWidth = 800;
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),
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].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.
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.
GLuint vao = 0;
GLuint vbo = 0;
@@ -125,13 +125,13 @@ int main(void)
DrawRectangle(10, 10, 210, 30, MAROON);
DrawText(TextFormat("%zu particles in one vertex buffer", MAX_PARTICLES), 20, 20, 10, RAYWHITE);
rlDrawRenderBatchActive(); // Draw iternal buffers data (previous draw calls)
// Switch to plain OpenGL
//------------------------------------------------------------------------------
glUseProgram(shader.id);
glUniform1f(currentTimeLoc, GetTime());
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
Matrix modelViewProjection = MatrixMultiply(rlGetMatrixModelview(), rlGetMatrixProjection());
glUniformMatrix4fv(shader.locs[SHADER_LOC_MATRIX_MVP], 1, false, MatrixToFloat(modelViewProjection));
glBindVertexArray(vao);
glDrawArrays(GL_POINTS, 0, MAX_PARTICLES);
glBindVertexArray(0);
glUseProgram(0);
//------------------------------------------------------------------------------
DrawFPS(screenWidth - 100, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -12,7 +12,7 @@
* Copyright (c) 2023-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
@@ -32,7 +32,7 @@ int main(void)
Vector2 v0 = { screenWidth/2, screenHeight/2 };
Vector2 v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f });
Vector2 v2 = { 0 }; // Updated with mouse position
float angle = 0.0f; // Angle in degrees
int angleMode = 0; // 0-Vector2Angle(), 1-Vector2LineAngle()
@@ -47,12 +47,12 @@ int main(void)
float startangle = 0.0f;
if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1)*RAD2DEG;
if (angleMode == 1) startangle = 0.0f;
if (angleMode == 1) startangle = 0.0f;
v2 = GetMousePosition();
if (IsKeyPressed(KEY_SPACE)) angleMode = !angleMode;
if ((angleMode == 0) && IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) v1 = GetMousePosition();
if (angleMode == 0)
@@ -75,12 +75,12 @@ int main(void)
BeginDrawing();
ClearBackground(RAYWHITE);
if (angleMode == 0)
{
DrawText("MODE 0: Angle between V1 and V2", 10, 10, 20, BLACK);
DrawText("Right Click to Move V2", 10, 30, 20, DARKGRAY);
DrawLineEx(v0, v1, 2.0f, BLACK);
DrawLineEx(v0, v2, 2.0f, RED);
@@ -89,13 +89,13 @@ int main(void)
else if (angleMode == 1)
{
DrawText("MODE 1: Angle formed by line V1 to V2", 10, 10, 20, BLACK);
DrawLine(0, screenHeight/2, screenWidth, screenHeight/2, LIGHTGRAY);
DrawLineEx(v0, v2, 2.0f, RED);
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));
}
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
@@ -110,7 +110,7 @@ int main(void)
DrawText("Press SPACE to change MODE", 460, 10, 20, DARKGRAY);
DrawText(TextFormat("ANGLE: %2.2f", angle), 10, 70, 20, LIME);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -137,7 +137,7 @@ int main(void)
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_DEPTH_BITS, 16);
// WARNING: OpenGL 3.3 Core profile only
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

View File

@@ -59,10 +59,10 @@ int main(void)
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
// Get some required shader locations
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
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
// Ambient light level (some basic lighting)
int ambientLoc = GetShaderLocation(shader, "ambient");
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 })
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
// Check key inputs to enable/disable lights
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
if (IsKeyPressed(KEY_G)) { lights[2].enabled = !lights[2].enabled; }
if (IsKeyPressed(KEY_B)) { lights[3].enabled = !lights[3].enabled; }
// Update light values (actually, only enable/disable them)
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
//----------------------------------------------------------------------------------

View File

@@ -13,8 +13,8 @@
*
* Copyright (c) 2023-2025 Afan OLOVCIC (@_DevDad)
*
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
* licensed under Creative Commons Attribution-NonCommercial
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
* licensed under Creative Commons Attribution-NonCommercial
* (http://creativecommons.org/licenses/by-nc/4.0/)
*
********************************************************************************************/
@@ -105,7 +105,7 @@ int main()
// shader already takes care of it accordingly
shader.locs[SHADER_LOC_MAP_METALNESS] = GetShaderLocation(shader, "mraMap");
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
// It is binded to SHADER_LOC_MAP_EMISSION location an properly processed on shader
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_NORMAL].texture = LoadTexture("resources/old_car_n.png");
car.materials[0].maps[MATERIAL_MAP_EMISSION].texture = LoadTexture("resources/old_car_e.png");
// Load floor model mesh and assign material parameters
// NOTE: A basic plane shape can be generated instead of being loaded from a model file
Model floor = LoadModel("resources/models/plane.glb");
@@ -161,9 +161,9 @@ int main()
//GenMeshTangents(&floorMesh); // TODO: Review tangents generation
//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].maps[MATERIAL_MAP_ALBEDO].color = WHITE;
floor.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.8f;
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, "useTexMRA"), &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
//---------------------------------------------------------------------------------------
@@ -221,11 +221,11 @@ int main()
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(BLACK);
BeginMode3D(camera);
// Set floor model texture tiling and emissive color parameters on shader
SetShaderValue(shader, textureTilingLoc, &floorTextureTiling, SHADER_UNIFORM_VEC2);
Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
@@ -234,7 +234,7 @@ int main()
// Set floor metallic and roughness values
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);
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
@@ -247,24 +247,24 @@ int main()
// Set old car metallic and roughness values
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);
DrawModel(car, (Vector3){ 0.0f, 0.0f, 0.0f }, 0.25f, WHITE); // Draw car model
// Draw spheres to show the lights positions
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 };
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));
}
EndMode3D();
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);
DrawFPS(10, 10);
EndDrawing();
@@ -273,20 +273,20 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
// Unbind (disconnect) shader from car.material[0]
// Unbind (disconnect) shader from car.material[0]
// to avoid UnloadMaterial() trying to unload it automatically
car.materials[0].shader = (Shader){ 0 };
UnloadMaterial(car.materials[0]);
car.materials[0].maps = NULL;
UnloadModel(car);
floor.materials[0].shader = (Shader){ 0 };
UnloadMaterial(floor.materials[0]);
floor.materials[0].maps = NULL;
UnloadModel(floor);
UnloadShader(shader); // Unload Shader
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[3] = (float)color.a/255.0f;
light.intensity = intensity;
// NOTE: Shader parameters names for lights must match the requested ones
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", 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.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightCount));
light.intensityLoc = GetShaderLocation(shader, TextFormat("lights[%i].intensity", lightCount));
UpdateLight(shader, light);
lightCount++;
@@ -333,7 +333,7 @@ static void UpdateLight(Shader shader, Light light)
{
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
// Send to shader light position values
float position[3] = { light.position.x, light.position.y, light.position.z };
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);

View File

@@ -78,7 +78,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL);
Vector2 mousePosition = GetMousePosition();
swirlCenter[0] = mousePosition.x;

View File

@@ -42,7 +42,7 @@ typedef struct GBuffer {
unsigned int positionTexture;
unsigned int normalTexture;
unsigned int albedoSpecTexture;
unsigned int depthRenderbuffer;
} GBuffer;
@@ -94,14 +94,14 @@ int main(void)
TraceLog(LOG_WARNING, "Failed to create framebuffer");
exit(1);
}
rlEnableFramebuffer(gBuffer.framebuffer);
// 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.
// 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
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`.
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
@@ -161,7 +161,7 @@ int main(void)
const float CUBE_SCALE = 0.25;
Vector3 cubePositions[MAX_CUBES] = { 0 };
float cubeRotations[MAX_CUBES] = { 0 };
for (int i = 0; i < MAX_CUBES; i++)
{
cubePositions[i] = (Vector3){
@@ -169,7 +169,7 @@ int main(void)
.y = (float)(rand()%5),
.z = (float)(rand()%10) - 5,
};
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 })
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(deferredShader, deferredShader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
// Check key inputs to enable/disable lights
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
@@ -215,7 +215,7 @@ int main(void)
rlEnableFramebuffer(gBuffer.framebuffer);
rlClearColor(0, 0, 0, 0);
rlClearScreenBuffers(); // Clear color and depth buffer
rlDisableColorBlend();
BeginMode3D(camera);
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
@@ -281,7 +281,7 @@ int main(void)
}
rlDisableShader();
EndMode3D();
DrawText("FINAL RESULT", 10, screenHeight - 30, 20, DARKGREEN);
} break;
case DEFERRED_POSITION:
@@ -291,7 +291,7 @@ int main(void)
.width = screenWidth,
.height = screenHeight,
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
DrawText("POSITION TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
} break;
case DEFERRED_NORMAL:
@@ -301,7 +301,7 @@ int main(void)
.width = screenWidth,
.height = screenHeight,
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
DrawText("NORMAL TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
} break;
case DEFERRED_ALBEDO:
@@ -311,7 +311,7 @@ int main(void)
.width = screenWidth,
.height = screenHeight,
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
DrawText("ALBEDO TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
} break;
default: break;
@@ -321,7 +321,7 @@ int main(void)
DrawText("Switch G-buffer textures: [1][2][3][4]", 10, 70, 20, DARKGRAY);
DrawFPS(10, 10);
EndDrawing();
// -----------------------------------------------------------------------------
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Sieve of Eratosthenes
* raylib [shaders] example - sieve of Eratosthenes
*
* Example complexity rating: [★★★☆] 3/4
*
@@ -45,7 +45,7 @@ int main(void)
const int screenWidth = 800;
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);

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Hot reloading
* raylib [shaders] example - hot reloading
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Hybrid Rendering
* raylib [shaders] example - hybrid rendering
*
* Example complexity rating: [★★★★] 4/4
*
@@ -69,7 +69,7 @@ int main(void)
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
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};
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
@@ -84,10 +84,10 @@ int main(void)
.fovy = 45.0f, // Camera field-of-view Y
.projection = CAMERA_PERSPECTIVE // Camera projection type
};
// Camera FOV is pre-calculated in the camera Distance.
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
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.
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
// Update Camera Looking Vector. Vector length determines FOV.
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
// Draw into our custom render texture (framebuffer)
@@ -117,7 +117,7 @@ int main(void)
BeginShaderMode(shdrRaymarch);
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
EndShaderMode();
// Rasterize Scene
BeginMode3D(camera);
BeginShaderMode(shdrRaster);
@@ -130,10 +130,10 @@ int main(void)
EndMode3D();
EndTextureMode();
// Draw into screen our custom render texture
// Draw into screen our custom render texture
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
DrawFPS(10, 10);
EndDrawing();

View File

@@ -167,7 +167,7 @@ int main(void)
// do not represent full screen coordinates (space where want to apply shader)
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
EndTextureMode();
BeginDrawing();
ClearBackground(BLACK); // Clear screen background

View File

@@ -70,7 +70,7 @@ int main(void)
// Load a new texcoords2 attributes buffer
mesh.vboId[SHADER_LOC_VERTEX_TEXCOORD02] = rlLoadVertexBuffer(mesh.texcoords2, mesh.vertexCount*2*sizeof(float), false);
rlEnableVertexArray(mesh.vaoId);
// Index 5 is for texcoords2
rlSetVertexAttribute(5, 2, RL_FLOAT, 0, 0, 0);
rlEnableVertexAttribute(5);
@@ -156,10 +156,10 @@ int main(void)
(Vector2){ 0.0, 0.0 },
0.0,
WHITE);
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -64,7 +64,7 @@ int main(void)
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
float angle = (float)GetRandomValue(0, 180)*DEG2RAD;
Matrix rotation = MatrixRotate(axis, angle);
transforms[i] = MatrixMultiply(rotation, translation);
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Multiple sample2D with default batch system
* raylib [shaders] example - multi sample2D
*
* Example complexity rating: [★★☆☆] 2/4
*
@@ -38,7 +38,7 @@ int main(void)
const int screenWidth = 800;
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 });
Texture texRed = LoadTextureFromImage(imRed);
@@ -93,7 +93,7 @@ int main(void)
// an additional texture units is enabled for texBlue [sampler2D texture1]
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);

View File

@@ -141,7 +141,7 @@ int main(void)
DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
BeginDrawing();
ClearBackground(RAYWHITE); // Clear screen background

View File

@@ -173,7 +173,7 @@ int main(void)
// Draw the same exact things as we drew in the shadowmap!
DrawScene(cube, robot);
EndMode3D();
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);

View File

@@ -97,7 +97,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_FIRST_PERSON);
framesCounter++;
rotation.x += 0.01f;
rotation.y += 0.005f;

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Apply an shdrOutline to a texture
* raylib [shaders] example - texture outline
*
* Example complexity rating: [★★★☆] 3/4
*
@@ -36,7 +36,7 @@ int main(void)
const int screenWidth = 800;
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");

View File

@@ -48,7 +48,7 @@ int main(void)
// Load a cube model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model model = LoadModelFromMesh(cube);
// Load a texture and assign to cube model
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
@@ -77,17 +77,17 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
BeginShaderMode(shader);
DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE);
EndShaderMode();
DrawGrid(10, 1.0f);
EndMode3D();
DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
@@ -104,6 +104,6 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View File

@@ -52,7 +52,7 @@ int main(void)
Shader shader = LoadShader(
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
// Load perlin noise texture
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
@@ -64,7 +64,7 @@ int main(void)
rlActiveTextureSlot(1);
rlEnableTexture(perlinNoiseMap.id);
rlSetUniformSampler(perlinNoiseMapLoc, 1);
// Create a plane mesh and model
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
Model planeModel = LoadModelFromMesh(planeMesh);

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shader] example - render depth texture
* raylib [shaders] example - render depth texture
*
* Example complexity rating: [★★★☆] 3/4
*
@@ -36,7 +36,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shader] example - render depth texture");
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - render depth texture");
// Init camera
Camera camera = { 0 };
@@ -76,7 +76,7 @@ int main(void)
//----------------------------------------------------------------------------------
BeginTextureMode(target);
ClearBackground(WHITE);
BeginMode3D(camera);
DrawModel(cube, (Vector3){ 0.0f, 0.0f, 0.0f }, 3.0f, YELLOW);
DrawModel(floor, (Vector3){ 10.0f, 0.0f, 2.0f }, 2.0f, RED);

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shaders] example - Depth buffer writing
* raylib [shaders] example - depth buffer writing
*
* Example complexity rating: [★★☆☆] 2/4
*
@@ -60,7 +60,7 @@ int main(void)
.fovy = 45.0f, // Camera field-of-view Y
.projection = CAMERA_PERSPECTIVE // Camera projection type
};
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -71,13 +71,13 @@ int main(void)
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
// Draw into our custom render texture (framebuffer)
BeginTextureMode(target);
ClearBackground(WHITE);
BeginMode3D(camera);
BeginShaderMode(shader);
DrawCubeWiresV((Vector3){ 0.0f, 0.5f, 1.0f }, (Vector3){ 1.0f, 1.0f, 1.0f }, RED);
@@ -89,7 +89,7 @@ int main(void)
EndMode3D();
EndTextureMode();
// Draw into screen our custom render texture
// Draw into screen our custom render texture
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);

View File

@@ -69,7 +69,7 @@ int main(void)
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
// Draw start-end spline circles with some details
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);

View File

@@ -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
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [shapes] example - Rectangle advanced
* raylib [shapes] example - advanced rectangle drawing
*
* Example complexity rating: [★★★★] 4/4
*
@@ -33,9 +33,9 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle avanced");
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
// 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
// [2] Upper Rectangle
@@ -266,7 +266,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
#else
// 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.
// 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 == 2) color = right, radius = radiusRight; // [5] Lower Right Corner
if (k == 3) color = left, radius = radiusLeft; // [7] Lower Left Corner
float angle = angles[k];
const Vector2 center = centers[k];
for (int i = 0; i < segments; i++)
{
rlColor4ub(color.r, color.g, color.b, color.a);

View File

@@ -65,7 +65,7 @@ int main(void)
// Check minimum rec 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;
// Check maximum rec size
if (rec.width > (GetScreenWidth() - rec.x)) rec.width = GetScreenWidth() - rec.x;
if (rec.height > (GetScreenHeight() - rec.y)) rec.height = GetScreenHeight() - rec.y;

View File

@@ -23,7 +23,7 @@
#define MAX_SPLINE_POINTS 32
// Cubic Bezier spline control points
// NOTE: Every segment has two control points
// NOTE: Every segment has two control points
typedef struct {
Vector2 start;
Vector2 end;
@@ -57,17 +57,17 @@ int main(void)
{ 520.0f, 60.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
Vector2 pointsInterleaved[3*(MAX_SPLINE_POINTS - 1) + 1] = { 0 };
int pointCount = 5;
int selectedPoint = -1;
int focusedPoint = -1;
Vector2 *selectedControlPoint = NULL;
Vector2 *focusedControlPoint = NULL;
// Cubic Bezier control points initialization
ControlPoint control[MAX_SPLINE_POINTS-1] = { 0 };
for (int i = 0; i < pointCount - 1; i++)
@@ -79,9 +79,9 @@ int main(void)
// Spline config variables
float splineThickness = 8.0f;
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier
bool splineTypeEditMode = false;
bool splineTypeEditMode = false;
bool splineHelpersActive = true;
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;
}
// Spline point movement logic
if (selectedPoint >= 0)
{
points[selectedPoint] = GetMousePosition();
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedPoint = -1;
}
// Cubic Bezier spline control points logic
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
{
@@ -144,7 +144,7 @@ int main(void)
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedControlPoint = focusedControlPoint;
}
// Spline control point movement logic
if (selectedControlPoint != NULL)
{
@@ -152,7 +152,7 @@ int main(void)
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedControlPoint = NULL;
}
}
// Spline selection logic
if (IsKeyPressed(KEY_ONE)) splineTypeActive = 0;
else if (IsKeyPressed(KEY_TWO)) splineTypeActive = 1;
@@ -168,7 +168,7 @@ int main(void)
BeginDrawing();
ClearBackground(RAYWHITE);
if (splineTypeActive == SPLINE_LINEAR)
{
// Draw spline: linear
@@ -191,7 +191,7 @@ int main(void)
{
// Draw spline: catmull-rom
DrawSplineCatmullRom(points, pointCount, splineThickness, RED); // Provide connected points array
/*
for (int i = 0; i < (pointCount - 3); i++)
{
@@ -202,20 +202,20 @@ int main(void)
}
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
for (int i = 0; i < (pointCount - 1); i++)
for (int i = 0; i < (pointCount - 1); i++)
{
pointsInterleaved[3*i] = points[i];
pointsInterleaved[3*i + 1] = control[i].start;
pointsInterleaved[3*i + 2] = control[i].end;
}
pointsInterleaved[3*(pointCount - 1)] = points[pointCount - 1];
// Draw spline: cubic-bezier (with control points)
DrawSplineBezierCubic(pointsInterleaved, 3*(pointCount - 1) + 1, splineThickness, RED);
/*
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);
DrawLineEx(points[i], control[i].start, 1.0f, LIGHTGRAY);
DrawLineEx(points[i + 1], control[i].end, 1.0f, LIGHTGRAY);
// Draw spline control lines
DrawLineV(points[i], control[i].start, GRAY);
//DrawLineV(control[i].start, control[i].end, LIGHTGRAY);
@@ -258,7 +258,7 @@ int main(void)
// Check all possible UI states that require controls lock
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlPoint != NULL)) GuiLock();
// Draw spline config
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);
@@ -269,7 +269,7 @@ int main(void)
GuiLabel((Rectangle){ 12, 10, 140, 24 }, "Spline type:");
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
GuiUnlock();
EndDrawing();

View File

@@ -55,7 +55,7 @@ LightInfo lights[MAX_LIGHTS] = { 0 };
void MoveLight(int slot, float x, float y)
{
lights[slot].dirty = true;
lights[slot].position.x = x;
lights[slot].position.x = x;
lights[slot].position.y = y;
// 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 (lights[slot].valid) DrawCircleGradient((int)lights[slot].position.x, (int)lights[slot].position.y, lights[slot].outerRadius, ColorAlpha(WHITE, 0), WHITE);
rlDrawRenderBatchActive();
// Cut out the shadows from the light radius by forcing the alpha to maximum
@@ -114,7 +114,7 @@ void DrawLightMask(int slot)
}
rlDrawRenderBatchActive();
// Go back to normal blend mode
rlSetBlendMode(BLEND_ALPHA);
@@ -156,7 +156,7 @@ bool UpdateLight(int slot, Rectangle* boxes, int count)
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
// Top
Vector2 sp = (Vector2){ boxes[i].x, 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 screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - top down lights");
// Initialize our 'world' of boxes
@@ -274,7 +274,7 @@ int main(void)
{
// Build up the light mask
BeginTextureMode(lightMask);
ClearBackground(BLACK);
// Force the blend mode to only set the alpha of the destination
@@ -300,10 +300,10 @@ int main(void)
BeginDrawing();
ClearBackground(BLACK);
// Draw the tile background
DrawTextureRec(backgroundTexture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE);
// 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));

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Codepoints loading
* raylib [text] example - text codepoints loading
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Draw 3d
* raylib [text] example - drawing 3d text
*
* 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
* flexibility...for example to change position of each letter individually to make somethink
* like a wavy text effect.
*
*
* Special thanks to:
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
* Chris Camacho (codifies - http://bedroomcoders.co.uk/) for the alpha discard shader
@@ -146,7 +146,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, camera_mode);
// Handle font files dropped
if (IsFileDropped())
{
@@ -164,7 +164,7 @@ int main(void)
font = LoadFont(droppedFiles.paths[0]);
fontSize = (float)font.baseSize;
}
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Font filters
* raylib [text] example - font texture filters
*
* Example complexity rating: [★★☆☆] 2/4
*
@@ -94,7 +94,7 @@ int main(void)
UnloadFont(font);
font = LoadFontEx(droppedFiles.paths[0], (int)fontSize, 0, 0);
}
UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory
}
//----------------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Font SDF loading
* raylib [text] example - font SDF loading
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Sprite font loading
* raylib [text] example - sprite font loading
*
* Example complexity rating: [★☆☆☆] 1/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Text formatting
* raylib [text] example - text formating
*
* Example complexity rating: [★☆☆☆] 1/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Input Box
* raylib [text] example - text input box
*
* Example complexity rating: [★★☆☆] 2/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Rectangle bounds
* raylib [text] example - rectangle bounds
*
* Example complexity rating: [★★★★] 4/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Unicode
* raylib [text] example - unicode text drawing
*
* Example complexity rating: [★★★★] 4/4
*
@@ -284,7 +284,7 @@ int main(void)
int length = GetCodepointCount(messages[message].text);
const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, length, size);
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);
}
//------------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [text] example - Text Writing Animation
* raylib [text] example - text writing animation
*
* Example complexity rating: [★★☆☆] 2/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Background scrolling
* raylib [textures] example - background scrolling
*
* Example complexity rating: [★☆☆☆] 1/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Bunnymark
* raylib [textures] example - bunnymark
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Draw part of the texture tiled
* raylib [textures] example - draw texture tiled
*
* Example complexity rating: [★★★☆] 3/4
*
@@ -36,7 +36,7 @@ int main(void)
const int screenHeight = 450;
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)
Texture texPattern = LoadTexture("resources/patterns.png");

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Fog of war
* raylib [textures] example - fog of war
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -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)
*
@@ -79,7 +79,7 @@ int main(void)
//----------------------------------------------------------------------------------
// TODO...
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
@@ -104,6 +104,7 @@ int main(void)
UnloadTexture(textureGreen);
UnloadTexture(textureBlue);
UnloadTexture(textureAlpha);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

View File

@@ -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
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Procedural images generation
* raylib [textures] example - procedural images generation
*
* Example complexity rating: [★★☆☆] 2/4
*

View File

@@ -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
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Image Rotation
* raylib [textures] example - image rotation
*
* Example complexity rating: [★★☆☆] 2/4
*
@@ -27,7 +27,7 @@ int main(void)
const int screenWidth = 800;
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)
Image image45 = LoadImage("resources/raylib_logo.png");

View File

@@ -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
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Texture loading and drawing
* raylib [textures] example - texture loading and drawing
*
* Example complexity rating: [★☆☆☆] 1/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Mouse painting
* raylib [textures] example - mouse painting
*
* Example complexity rating: [★★★☆] 3/4
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Draw Textured Polygon
* raylib [textures] example - draw textured polygon
*
* Example complexity rating: [★☆☆☆] 1/4
*
@@ -34,7 +34,7 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
// 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].y = (texcoords[i].y - 0.5f)*256.0f;
}
// Define the vertices drawing position
// NOTE: Initially same as points but updated every frame
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)
{
rlBegin(RL_TRIANGLES);
rlSetTexture(texture.id);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);

View File

@@ -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
*

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Sprite animation
* raylib [textures] example - sprite animation
*
* Example complexity rating: [★★☆☆] 2/4
*

View File

@@ -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
*

View File

@@ -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
*
@@ -112,7 +112,7 @@ int main()
ClearBackground(RAYWHITE);
DrawTexturedCurve(); // Draw a textured Spline Cubic Bezier
// Draw spline for reference
if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE);
@@ -120,7 +120,7 @@ int main()
DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE);
DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f));
DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE);
if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW);
DrawCircleV(curveStartPosition, 5, RED);
@@ -137,7 +137,7 @@ int main()
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 segments: %d (Use LEFT and RIGHT to adjust)", curveSegments), 10, 50, 10, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
@@ -145,7 +145,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texRoad);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [textures] example - Retrieve image data from texture: LoadImageFromTexture()
* raylib [textures] example - texture to image
*
* Example complexity rating: [★☆☆☆] 1/4
*