Skip to content

Commit 07e5a17

Browse files
committed
example resize fixes
1 parent f9db7fa commit 07e5a17

26 files changed

+292
-210
lines changed

cmake/raylib-config.cmake

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# - Try to find raylib
22
# Options:
3-
# raylib_USE_STATIC_LIBS - OFF by default
3+
# raylib_USE_STATIC_LIBS - ON by default
44
# raylib_VERBOSE - OFF by default
55
# Once done, this defines a raylib target that can be passed to
66
# target_link_libraries as well as following variables:
@@ -11,6 +11,9 @@
1111
# raylib_LDFLAGS - The linker flags needed with raylib
1212
# raylib_DEFINITIONS - Compiler switches required for using raylib
1313

14+
option(raylib_USE_STATIC_LIBS "Use static libs" ON)
15+
option(raylib_VERBOSE "Use static libs" OFF)
16+
1417
if (NOT TARGET raylib)
1518
set(XPREFIX PC_RAYLIB)
1619

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

2629
find_path(raylib_INCLUDE_DIR
2730
NAMES raylib.h
28-
HINTS ${${XPREFIX}_INCLUDE_DIRS}
31+
HINTS ${${XPREFIX}_INCLUDE_DIRS} ${raylib_DIR}/../../../include/
2932
)
3033

31-
set(RAYLIB_NAMES raylib)
3234

3335
if (raylib_USE_STATIC_LIBS)
34-
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
35-
endif()
36+
set(RAYLIB_NAMES libraylib.a raylib.lib)
37+
else ()
38+
set(RAYLIB_NAMES raylib)
39+
endif ()
3640

3741
find_library(raylib_LIBRARY
3842
NAMES ${RAYLIB_NAMES}
39-
HINTS ${${XPREFIX}_LIBRARY_DIRS}
43+
HINTS ${${XPREFIX}_LIBRARY_DIRS} ${raylib_DIR}/../../
4044
)
4145

4246
set(raylib_LIBRARIES ${raylib_LIBRARY})
43-
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
44-
set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS})
4547
set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
4648
set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS})
4749

examples/models/models_animation.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main(void)
9494
EndMode3D();
9595

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

9999
EndDrawing();
100100
//----------------------------------------------------------------------------------

examples/models/models_box_collisions.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(void)
111111

112112
EndMode3D();
113113

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

116116
DrawFPS(10, 10);
117117

@@ -125,4 +125,4 @@ int main(void)
125125
//--------------------------------------------------------------------------------------
126126

127127
return 0;
128-
}
128+
}

examples/models/models_heightmap.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ int main(void)
7171

7272
EndMode3D();
7373

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

7777
DrawFPS(10, 10);
7878

@@ -89,4 +89,4 @@ int main(void)
8989
//--------------------------------------------------------------------------------------
9090

9191
return 0;
92-
}
92+
}

examples/models/models_loading.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int main(void)
135135
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
136136
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
137137

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

140140
DrawFPS(10, 10);
141141

@@ -152,4 +152,4 @@ int main(void)
152152
//--------------------------------------------------------------------------------------
153153

154154
return 0;
155-
}
155+
}

examples/models/models_loading_vox.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ int main(void)
182182
EndMode3D();
183183

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

192192
EndDrawing();

examples/models/models_mesh_generation.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,21 @@ int main(void)
110110

111111
EndMode3D();
112112

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

117117
switch (currentModel)
118118
{
119-
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break;
120-
case 1: DrawText("CUBE", 680, 10, 20, DARKBLUE); break;
121-
case 2: DrawText("SPHERE", 680, 10, 20, DARKBLUE); break;
122-
case 3: DrawText("HEMISPHERE", 640, 10, 20, DARKBLUE); break;
123-
case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE); break;
124-
case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE); break;
125-
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
126-
case 7: DrawText("POLY", 680, 10, 20, DARKBLUE); break;
127-
case 8: DrawText("Custom (triangle)", 580, 10, 20, DARKBLUE); break;
119+
case 0: DrawText("PLANE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
120+
case 1: DrawText("CUBE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
121+
case 2: DrawText("SPHERE", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
122+
case 3: DrawText("HEMISPHERE", GetScreenWidth() - 160, 10, 20, DARKBLUE); break;
123+
case 4: DrawText("CYLINDER", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
124+
case 5: DrawText("TORUS", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
125+
case 6: DrawText("KNOT", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
126+
case 7: DrawText("POLY", GetScreenWidth() - 120, 10, 20, DARKBLUE); break;
127+
case 8: DrawText("Custom (triangle)", GetScreenWidth() - 220, 10, 20, DARKBLUE); break;
128128
default: break;
129129
}
130130

examples/models/models_mesh_picking.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ int main(void)
226226
DrawText(TextFormat("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
227227
}
228228

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

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

233233
DrawFPS(10, 10);
234234

@@ -245,4 +245,4 @@ int main(void)
245245
//--------------------------------------------------------------------------------------
246246

247247
return 0;
248-
}
248+
}

examples/models/models_point_rendering.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int main()
125125
EndMode3D();
126126

127127
// Draw UI text
128-
DrawText(TextFormat("Point Count: %d", numPoints), 20, screenHeight - 50, 40, WHITE);
128+
DrawText(TextFormat("Point Count: %d", numPoints), 20, GetScreenHeight() - 50, 40, WHITE);
129129
DrawText("Up - increase points", 20, 70, 20, WHITE);
130130
DrawText("Down - decrease points", 20, 100, 20, WHITE);
131131
DrawText("Space - drawing function", 20, 130, 20, WHITE);

examples/models/models_rlgl_solar_system.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int main(void)
112112

113113
EndMode3D();
114114

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

118118
EndDrawing();

examples/models/models_yaw_pitch_roll.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ int main(void)
101101
EndMode3D();
102102

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

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

112112
EndDrawing();
113113
//----------------------------------------------------------------------------------

examples/shaders/resources/shaders/glsl100/swirl.fs

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ uniform vec4 colDiffuse;
1212

1313
// NOTE: Add your custom variables here
1414

15-
// NOTE: Render size values should be passed from code
16-
const float renderWidth = 800.0;
17-
const float renderHeight = 450.0;
18-
1915
float radius = 250.0;
2016
float angle = 0.8;
2117

18+
uniform vec2 size = { 800.0, 450.0 };
2219
uniform vec2 center;
2320

2421
void main()
2522
{
26-
vec2 texSize = vec2(renderWidth, renderHeight);
27-
vec2 tc = fragTexCoord*texSize;
23+
vec2 tc = fragTexCoord*size;
2824
tc -= center;
2925

3026
float dist = length(tc);
@@ -40,7 +36,7 @@ void main()
4036
}
4137

4238
tc += center;
43-
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
39+
vec4 color = texture2D(texture0, tc/size)*colDiffuse*fragColor;;
4440

4541
gl_FragColor = vec4(color.rgb, 1.0);
4642
}

examples/shaders/resources/shaders/glsl120/swirl.fs

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ uniform vec4 colDiffuse;
1010

1111
// NOTE: Add your custom variables here
1212

13-
// NOTE: Render size values should be passed from code
14-
const float renderWidth = 800;
15-
const float renderHeight = 450;
16-
1713
float radius = 250.0;
1814
float angle = 0.8;
1915

16+
uniform vec2 size = vec2(800.0, 450.0);
2017
uniform vec2 center;
2118

2219
void main()
2320
{
24-
vec2 texSize = vec2(renderWidth, renderHeight);
25-
vec2 tc = fragTexCoord*texSize;
21+
vec2 tc = fragTexCoord*size;
2622
tc -= center;
2723

2824
float dist = length(tc);
@@ -38,7 +34,7 @@ void main()
3834
}
3935

4036
tc += center;
41-
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
37+
vec4 color = texture2D(texture0, tc/size)*colDiffuse*fragColor;;
4238

4339
gl_FragColor = vec4(color.rgb, 1.0);;
44-
}
40+
}

examples/shaders/resources/shaders/glsl330/swirl.fs

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ out vec4 finalColor;
1313

1414
// NOTE: Add your custom variables here
1515

16-
// NOTE: Render size values should be passed from code
17-
const float renderWidth = 800;
18-
const float renderHeight = 450;
19-
2016
float radius = 250.0;
2117
float angle = 0.8;
2218

19+
uniform vec2 size = vec2(800.0, 450.0);
2320
uniform vec2 center = vec2(200.0, 200.0);
2421

2522
void main()
2623
{
27-
vec2 texSize = vec2(renderWidth, renderHeight);
28-
vec2 tc = fragTexCoord*texSize;
24+
vec2 tc = fragTexCoord*size;
2925
tc -= center;
3026

3127
float dist = length(tc);
@@ -41,7 +37,7 @@ void main()
4137
}
4238

4339
tc += center;
44-
vec4 color = texture(texture0, tc/texSize)*colDiffuse*fragColor;;
40+
vec4 color = texture(texture0, tc/size)*colDiffuse*fragColor;;
4541

4642
finalColor = vec4(color.rgb, 1.0);;
47-
}
43+
}

examples/shaders/shaders_basic_pbr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ int main()
253253

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

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

258258
DrawFPS(10, 10);
259259

examples/shaders/shaders_custom_uniform.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ int main(void)
3535
{
3636
// Initialization
3737
//--------------------------------------------------------------------------------------
38-
const int screenWidth = 800;
39-
const int screenHeight = 450;
38+
int screenWidth = 800;
39+
int screenHeight = 450;
40+
float swirlSize[2] = { (float)screenWidth, (float)screenHeight };
41+
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
4042

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

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

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

67-
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
68-
6970
// Create a RenderTexture2D to be used for render to texture
70-
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
71+
RenderTexture2D target;
7172

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

7576
// Main game loop
7677
while (!WindowShouldClose()) // Detect window close button or ESC key
7778
{
79+
screenWidth = GetScreenWidth();
80+
screenHeight = GetScreenHeight();
81+
// Create a RenderTexture2D to be used for render to texture
82+
UnloadRenderTexture(target);
83+
target = LoadRenderTexture(screenWidth, screenHeight);
84+
7885
// Update
7986
//----------------------------------------------------------------------------------
8087
UpdateCamera(&camera, CAMERA_ORBITAL);
8188

8289
Vector2 mousePosition = GetMousePosition();
8390

91+
swirlSize[0] = screenWidth;
92+
swirlSize[1] = screenHeight;
93+
SetShaderValue(shader, swirlSizeLoc, swirlSize, SHADER_UNIFORM_VEC2);
94+
8495
swirlCenter[0] = mousePosition.x;
8596
swirlCenter[1] = screenHeight - mousePosition.y;
86-
8797
// Send new value to the shader to be used on drawing
8898
SetShaderValue(shader, swirlCenterLoc, swirlCenter, SHADER_UNIFORM_VEC2);
8999
//----------------------------------------------------------------------------------
@@ -98,7 +108,7 @@ int main(void)
98108
DrawGrid(10, 1.0f); // Draw a grid
99109
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
100110

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

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

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

130140
return 0;
131-
}
141+
}

0 commit comments

Comments
 (0)