Skip to content

[examples] resize fixes #4796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
48f9c9c
example resize fixes
jopadan Feb 26, 2025
958ef6a
Merge branch 'raysan5:master' into master
jopadan Feb 26, 2025
7932a15
Merge branch 'raysan5:master' into master
jopadan Mar 4, 2025
01de3b4
Merge branch 'raysan5:master' into master
jopadan Mar 9, 2025
cba3669
Merge branch 'raysan5:master' into master
jopadan Mar 11, 2025
e6843aa
Merge branch 'raysan5:master' into master
jopadan Mar 12, 2025
58f8198
Merge branch 'raysan5:master' into master
jopadan Mar 13, 2025
fc7d606
Merge branch 'raysan5:master' into master
jopadan Mar 14, 2025
f8fcce2
Merge branch 'raysan5:master' into master
jopadan Mar 18, 2025
e46afa2
Merge branch 'raysan5:master' into master
jopadan Mar 24, 2025
d183774
Merge branch 'raysan5:master' into master
jopadan Mar 25, 2025
b8fe0c4
Merge branch 'raysan5:master' into master
jopadan Mar 28, 2025
5483d5f
Merge branch 'raysan5:master' into master
jopadan Mar 30, 2025
336c85d
Merge branch 'raysan5:master' into master
jopadan Apr 3, 2025
971e8d3
Merge branch 'raysan5:master' into master
jopadan Apr 7, 2025
89554a1
Merge branch 'raysan5:master' into master
jopadan Apr 10, 2025
4ceaac0
Merge branch 'raysan5:master' into master
jopadan Apr 13, 2025
db4efbc
Merge branch 'master' into master
jopadan Apr 13, 2025
369f767
Merge branch 'raysan5:master' into master
jopadan Apr 17, 2025
a618dae
Merge branch 'master' into master
jopadan Apr 19, 2025
ece30cd
Merge branch 'raysan5:master' into master
jopadan Apr 21, 2025
a7b7538
Merge branch 'raysan5:master' into master
jopadan Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/models/models_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(void)
EndMode3D();

DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, MAROON);
DrawText("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawText("(c) Guy IQM 3D model by @culacant", GetScreenWidth() - 200, GetScreenHeight() - 20, 10, GRAY);

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/models/models_box_collisions.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int main(void)

EndMode3D();

DrawText("Move player with arrow keys to collide", 220, 40, 20, GRAY);
DrawText("Move player with arrow keys to collide", GetScreenWidth()/2 - 220, 40, 20, GRAY);

DrawFPS(10, 10);

Expand All @@ -125,4 +125,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
6 changes: 3 additions & 3 deletions examples/models/models_heightmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ int main(void)

EndMode3D();

DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
DrawTexture(texture, GetScreenWidth() - texture.width - 20, 20, WHITE);
DrawRectangleLines(GetScreenWidth() - texture.width - 20, 20, texture.width, texture.height, GREEN);

DrawFPS(10, 10);

Expand All @@ -89,4 +89,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
4 changes: 2 additions & 2 deletions examples/models/models_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int main(void)
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);

DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawText("(c) Castle 3D model by Alberto Cano", GetScreenWidth() - 200, GetScreenHeight() - 20, 10, GRAY);

DrawFPS(10, 10);

Expand All @@ -152,4 +152,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
10 changes: 5 additions & 5 deletions examples/models/models_loading_vox.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ int main(void)
EndMode3D();

// Display info
DrawRectangle(10, 400, 340, 60, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(10, 400, 340, 60, Fade(DARKBLUE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
DrawText("MOUSE MIDDLE BUTTON to ZOOM OR ROTATE CAMERA", 40, 420, 10, BLUE);
DrawText("UP-DOWN-LEFT-RIGHT KEYS to MOVE CAMERA", 40, 430, 10, BLUE);
DrawRectangle(10, GetScreenHeight() - 50, 340, 60, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(10, GetScreenHeight() - 50, 340, 60, Fade(DARKBLUE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, GetScreenHeight() - 50 + 10, 10, BLUE);
DrawText("MOUSE MIDDLE BUTTON to ZOOM OR ROTATE CAMERA", 40, GetScreenHeight() - 50 + 20, 10, BLUE);
DrawText("UP-DOWN-LEFT-RIGHT KEYS to MOVE CAMERA", 40, GetScreenHeight() - 50 + 30, 10, BLUE);
DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);

EndDrawing();
Expand Down
24 changes: 12 additions & 12 deletions examples/models/models_mesh_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ int main(void)

EndMode3D();

DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE);
DrawRectangle(30, GetScreenHeight() - 50, 310, 30, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, GetScreenHeight() - 50, 310, 30, Fade(DARKBLUE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, GetScreenHeight() - 50 + 10, 10, BLUE);

switch (currentModel)
{
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break;
case 1: DrawText("CUBE", 680, 10, 20, DARKBLUE); break;
case 2: DrawText("SPHERE", 680, 10, 20, DARKBLUE); break;
case 3: DrawText("HEMISPHERE", 640, 10, 20, DARKBLUE); break;
case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE); break;
case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE); break;
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
case 7: DrawText("POLY", 680, 10, 20, DARKBLUE); break;
case 8: DrawText("Custom (triangle)", 580, 10, 20, DARKBLUE); break;
case 0: DrawText("PLANE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 1: DrawText("CUBE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 2: DrawText("SPHERE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 3: DrawText("HEMISPHERE", GetScreenWidth() - 160, 10, 20, DARKBLUE); break;
case 4: DrawText("CYLINDER", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 5: DrawText("TORUS", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 6: DrawText("KNOT", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 7: DrawText("POLY", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
case 8: DrawText("Custom (triangle)", GetScreenWidth() - 220, 10, 20, DARKBLUE); break;
default: break;
}

Expand Down
6 changes: 3 additions & 3 deletions examples/models/models_mesh_picking.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ int main(void)
DrawText(TextFormat("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
}

DrawText("Right click mouse to toggle camera controls", 10, 430, 10, GRAY);
DrawText("Right click mouse to toggle camera controls", 10, GetScreenHeight() - 20, 10, GRAY);

DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawText("(c) Turret 3D model by Alberto Cano", GetScreenWidth() - 200, GetScreenHeight() - 20, 10, GRAY);

DrawFPS(10, 10);

Expand All @@ -245,4 +245,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
2 changes: 1 addition & 1 deletion examples/models/models_point_rendering.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main()
EndMode3D();

// Draw UI text
DrawText(TextFormat("Point Count: %d", numPoints), 20, screenHeight - 50, 40, WHITE);
DrawText(TextFormat("Point Count: %d", numPoints), 20, GetScreenHeight() - 50, 40, WHITE);
DrawText("Up - increase points", 20, 70, 20, WHITE);
DrawText("Down - decrease points", 20, 100, 20, WHITE);
DrawText("Space - drawing function", 20, 130, 20, WHITE);
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_rlgl_solar_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int main(void)

EndMode3D();

DrawText("EARTH ORBITING AROUND THE SUN!", 400, 10, 20, MAROON);
DrawText("EARTH ORBITING AROUND THE SUN!", GetScreenWidth() - 400, 10, 20, MAROON);
DrawFPS(10, 10);

EndDrawing();
Expand Down
12 changes: 6 additions & 6 deletions examples/models/models_yaw_pitch_roll.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ int main(void)
EndMode3D();

// Draw controls info
DrawRectangle(30, 370, 260, 70, Fade(GREEN, 0.5f));
DrawRectangleLines(30, 370, 260, 70, Fade(DARKGREEN, 0.5f));
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 380, 10, DARKGRAY);
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 400, 10, DARKGRAY);
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 420, 10, DARKGRAY);
DrawRectangle(30, GetScreenHeight() - 80, 260, 70, Fade(GREEN, 0.5f));
DrawRectangleLines(30, GetScreenHeight() - 80, 260, 70, Fade(DARKGREEN, 0.5f));
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, GetScreenHeight() - 70, 10, DARKGRAY);
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, GetScreenHeight() - 50, 10, DARKGRAY);
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, GetScreenHeight() - 30, 10, DARKGRAY);

DrawText("(c) WWI Plane Model created by GiaHanLam", screenWidth - 240, screenHeight - 20, 10, DARKGRAY);
DrawText("(c) WWI Plane Model created by GiaHanLam", GetScreenWidth() - 240, GetScreenHeight() - 20, 10, DARKGRAY);

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
10 changes: 3 additions & 7 deletions examples/shaders/resources/shaders/glsl100/swirl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ uniform vec4 colDiffuse;

// NOTE: Add your custom variables here

// NOTE: Render size values should be passed from code
const float renderWidth = 800.0;
const float renderHeight = 450.0;

float radius = 250.0;
float angle = 0.8;

uniform vec2 size = { 800.0, 450.0 };
uniform vec2 center;

void main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
vec2 tc = fragTexCoord*size;
tc -= center;

float dist = length(tc);
Expand All @@ -40,7 +36,7 @@ void main()
}

tc += center;
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
vec4 color = texture2D(texture0, tc/size)*colDiffuse*fragColor;;

gl_FragColor = vec4(color.rgb, 1.0);
}
12 changes: 4 additions & 8 deletions examples/shaders/resources/shaders/glsl120/swirl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ uniform vec4 colDiffuse;

// NOTE: Add your custom variables here

// NOTE: Render size values should be passed from code
const float renderWidth = 800;
const float renderHeight = 450;

float radius = 250.0;
float angle = 0.8;

uniform vec2 size = vec2(800.0, 450.0);
uniform vec2 center;

void main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
vec2 tc = fragTexCoord*size;
tc -= center;

float dist = length(tc);
Expand All @@ -38,7 +34,7 @@ void main()
}

tc += center;
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
vec4 color = texture2D(texture0, tc/size)*colDiffuse*fragColor;;

gl_FragColor = vec4(color.rgb, 1.0);;
}
}
12 changes: 4 additions & 8 deletions examples/shaders/resources/shaders/glsl330/swirl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ out vec4 finalColor;

// NOTE: Add your custom variables here

// NOTE: Render size values should be passed from code
const float renderWidth = 800;
const float renderHeight = 450;

float radius = 250.0;
float angle = 0.8;

uniform vec2 size = vec2(800.0, 450.0);
uniform vec2 center = vec2(200.0, 200.0);

void main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
vec2 tc = fragTexCoord*size;
tc -= center;

float dist = length(tc);
Expand All @@ -41,7 +37,7 @@ void main()
}

tc += center;
vec4 color = texture(texture0, tc/texSize)*colDiffuse*fragColor;;
vec4 color = texture(texture0, tc/size)*colDiffuse*fragColor;;

finalColor = vec4(color.rgb, 1.0);;
}
}
2 changes: 1 addition & 1 deletion examples/shaders/shaders_basic_pbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int main()

DrawText("Toggle lights: [1][2][3][4]", 10, 40, 20, LIGHTGRAY);

DrawText("(c) Old Rusty Car model by Renafox (https://skfb.ly/LxRy)", screenWidth - 320, screenHeight - 20, 10, LIGHTGRAY);
DrawText("(c) Old Rusty Car model by Renafox (https://skfb.ly/LxRy)", GetScreenWidth() - 320, GetScreenHeight() - 20, 10, LIGHTGRAY);

DrawFPS(10, 10);

Expand Down
28 changes: 19 additions & 9 deletions examples/shaders/shaders_custom_uniform.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
int screenWidth = 800;
int screenHeight = 450;
float swirlSize[2] = { (float)screenWidth, (float)screenHeight };
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };

SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)

Expand All @@ -62,28 +64,36 @@ int main(void)

// Get variable (uniform) location on the shader to connect with the program
// NOTE: If uniform variable could not be found in the shader, function returns -1
int swirlSizeLoc = GetShaderLocation(shader, "size");
int swirlCenterLoc = GetShaderLocation(shader, "center");

float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };

// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
RenderTexture2D target;

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
screenWidth = GetScreenWidth();
screenHeight = GetScreenHeight();
// Create a RenderTexture2D to be used for render to texture
UnloadRenderTexture(target);
target = LoadRenderTexture(screenWidth, screenHeight);

// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL);

Vector2 mousePosition = GetMousePosition();

swirlSize[0] = screenWidth;
swirlSize[1] = screenHeight;
SetShaderValue(shader, swirlSizeLoc, swirlSize, SHADER_UNIFORM_VEC2);

swirlCenter[0] = mousePosition.x;
swirlCenter[1] = screenHeight - mousePosition.y;

// Send new value to the shader to be used on drawing
SetShaderValue(shader, swirlCenterLoc, swirlCenter, SHADER_UNIFORM_VEC2);
//----------------------------------------------------------------------------------
Expand All @@ -98,7 +108,7 @@ int main(void)
DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode

DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED);
DrawText("TEXT DRAWN IN RENDER TEXTURE", screenWidth - 600, 10, 30, RED);
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)

BeginDrawing();
Expand All @@ -107,7 +117,7 @@ int main(void)
// Enable shader using the custom uniform
BeginShaderMode(shader);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2){ 0, 0 }, WHITE);
EndShaderMode();

// Draw some 2d text over drawn texture
Expand All @@ -128,4 +138,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
10 changes: 5 additions & 5 deletions examples/shaders/shaders_hot_reloading.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ int main(void)
int mouseLoc = GetShaderLocation(shader, "mouse");
int timeLoc = GetShaderLocation(shader, "time");

float resolution[2] = { (float)screenWidth, (float)screenHeight };
SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);

float totalTime = 0.0f;
bool shaderAutoReloading = false;

Expand All @@ -65,6 +62,9 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
float resolution[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);

totalTime += GetFrameTime();
Vector2 mouse = GetMousePosition();
float mousePos[2] = { mouse.x, mouse.y };
Expand Down Expand Up @@ -113,14 +113,14 @@ int main(void)

// We only draw a white full-screen rectangle, frame is generated in shader
BeginShaderMode(shader);
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE);
EndShaderMode();

DrawText(TextFormat("PRESS [A] to TOGGLE SHADER AUTOLOADING: %s",
shaderAutoReloading? "AUTO" : "MANUAL"), 10, 10, 10, shaderAutoReloading? RED : BLACK);
if (!shaderAutoReloading) DrawText("MOUSE CLICK to SHADER RE-LOADING", 10, 30, 10, BLACK);

DrawText(TextFormat("Shader last modification: %s", asctime(localtime(&fragShaderFileModTime))), 10, 430, 10, BLACK);
DrawText(TextFormat("Shader last modification: %s", asctime(localtime(&fragShaderFileModTime))), 10, GetScreenHeight() - 20, 10, BLACK);

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
Loading