Skip to content

Commit

Permalink
example resize fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jopadan committed Feb 26, 2025
1 parent f9db7fa commit 07e5a17
Show file tree
Hide file tree
Showing 26 changed files with 292 additions and 210 deletions.
18 changes: 10 additions & 8 deletions cmake/raylib-config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# - Try to find raylib
# Options:
# raylib_USE_STATIC_LIBS - OFF by default
# raylib_USE_STATIC_LIBS - ON by default
# raylib_VERBOSE - OFF by default
# Once done, this defines a raylib target that can be passed to
# target_link_libraries as well as following variables:
Expand All @@ -11,6 +11,9 @@
# raylib_LDFLAGS - The linker flags needed with raylib
# raylib_DEFINITIONS - Compiler switches required for using raylib

option(raylib_USE_STATIC_LIBS "Use static libs" ON)
option(raylib_VERBOSE "Use static libs" OFF)

if (NOT TARGET raylib)
set(XPREFIX PC_RAYLIB)

Expand All @@ -25,23 +28,22 @@ if (NOT TARGET raylib)

find_path(raylib_INCLUDE_DIR
NAMES raylib.h
HINTS ${${XPREFIX}_INCLUDE_DIRS}
HINTS ${${XPREFIX}_INCLUDE_DIRS} ${raylib_DIR}/../../../include/
)

set(RAYLIB_NAMES raylib)

if (raylib_USE_STATIC_LIBS)
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
endif()
set(RAYLIB_NAMES libraylib.a raylib.lib)
else ()
set(RAYLIB_NAMES raylib)
endif ()

find_library(raylib_LIBRARY
NAMES ${RAYLIB_NAMES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
HINTS ${${XPREFIX}_LIBRARY_DIRS} ${raylib_DIR}/../../
)

set(raylib_LIBRARIES ${raylib_LIBRARY})
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS})
set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS})

Expand Down
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;
}
}
Loading

0 comments on commit 07e5a17

Please sign in to comment.