Skip to content

Commit f9db7fa

Browse files
committed
example resize fixes
1 parent e4993c5 commit f9db7fa

6 files changed

+31
-24
lines changed

examples/shaders/shaders_model_shader.c

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

8989
EndMode3D();
9090

91-
DrawText("(c) Watermill 3D model by Alberto Cano", screenWidth - 210, screenHeight - 20, 10, GRAY);
91+
DrawText("(c) Watermill 3D model by Alberto Cano", GetScreenWidth() - 210, GetScreenHeight() - 20, 10, GRAY);
9292

9393
DrawFPS(10, 10);
9494

@@ -106,4 +106,4 @@ int main(void)
106106
//--------------------------------------------------------------------------------------
107107

108108
return 0;
109-
}
109+
}

examples/shaders/shaders_postprocessing.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ int main(void)
133133

134134
// Draw
135135
//----------------------------------------------------------------------------------
136+
UnloadRenderTexture(target);
137+
target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
136138
BeginTextureMode(target); // Enable drawing to texture
137139
ClearBackground(RAYWHITE); // Clear texture background
138140

@@ -148,17 +150,17 @@ int main(void)
148150
// Render generated texture using selected postprocessing shader
149151
BeginShaderMode(shaders[currentShader]);
150152
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
151-
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0, 0 }, WHITE);
153+
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)-GetScreenHeight() }, (Vector2){0, 0}, WHITE);
152154
EndShaderMode();
153155

154156
// Draw 2d shapes and text over drawn texture
155157
DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
156158

157-
DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
159+
DrawText("(c) Church 3D model by Alberto Cano", GetScreenWidth() - 200, GetScreenHeight() - 20, 10, GRAY);
158160
DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
159161
DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
160162
DrawText("< >", 540, 10, 30, DARKBLUE);
161-
DrawFPS(700, 15);
163+
DrawFPS(GetScreenWidth() - 100, 15);
162164
EndDrawing();
163165
//----------------------------------------------------------------------------------
164166
}

examples/shaders/shaders_shadowmap.c

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

177177
EndMode3D();
178178

179-
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);
179+
DrawText("Shadows in raylib using the shadowmapping algorithm!", GetScreenWidth() - 320, GetScreenHeight() - 20, 10, GRAY);
180180
DrawText("Use the arrow keys to rotate the light!", 10, 10, 30, RED);
181181

182182
EndDrawing();

examples/shaders/shaders_spotlight.c

+14-11
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(void)
8585
for (int n = 0; n < MAX_STARS; n++) ResetStar(&stars[n]);
8686

8787
// Progress all the stars on, so they don't all start in the centre
88-
for (int m = 0; m < screenWidth/2.0; m++)
88+
for (int m = 0; m < GetScreenWidth()/2.0; m++)
8989
{
9090
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
9191
}
@@ -124,8 +124,8 @@ int main(void)
124124
// and initialize the shader locations
125125
for (int i = 0; i < MAX_SPOTS; i++)
126126
{
127-
spots[i].position.x = (float)GetRandomValue(64, screenWidth - 64);
128-
spots[i].position.y = (float)GetRandomValue(64, screenHeight - 64);
127+
spots[i].position.x = (float)GetRandomValue(64, GetScreenWidth() - 64);
128+
spots[i].position.y = (float)GetRandomValue(64, GetScreenHeight() - 64);
129129
spots[i].speed = (Vector2){ 0, 0 };
130130

131131
while ((fabs(spots[i].speed.x) + fabs(spots[i].speed.y)) < 2)
@@ -152,6 +152,9 @@ int main(void)
152152
//----------------------------------------------------------------------------------
153153
frameCounter++;
154154

155+
sw = (float)GetScreenWidth();
156+
SetShaderValue(shdrSpot, wLoc, &sw, SHADER_UNIFORM_FLOAT);
157+
155158
// Move the stars, resetting them if the go offscreen
156159
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
157160

@@ -162,17 +165,17 @@ int main(void)
162165
{
163166
Vector2 mp = GetMousePosition();
164167
spots[i].position.x = mp.x;
165-
spots[i].position.y = screenHeight - mp.y;
168+
spots[i].position.y = GetScreenHeight() - mp.y;
166169
}
167170
else
168171
{
169172
spots[i].position.x += spots[i].speed.x;
170173
spots[i].position.y += spots[i].speed.y;
171174

172175
if (spots[i].position.x < 64) spots[i].speed.x = -spots[i].speed.x;
173-
if (spots[i].position.x > (screenWidth - 64)) spots[i].speed.x = -spots[i].speed.x;
176+
if (spots[i].position.x > (GetScreenWidth() - 64)) spots[i].speed.x = -spots[i].speed.x;
174177
if (spots[i].position.y < 64) spots[i].speed.y = -spots[i].speed.y;
175-
if (spots[i].position.y > (screenHeight - 64)) spots[i].speed.y = -spots[i].speed.y;
178+
if (spots[i].position.y > (GetScreenHeight() - 64)) spots[i].speed.y = -spots[i].speed.y;
176179
}
177180

178181
SetShaderValue(shdrSpot, spots[i].positionLoc, &spots[i].position.x, SHADER_UNIFORM_VEC2);
@@ -194,8 +197,8 @@ int main(void)
194197
for (int i = 0; i < 16; i++)
195198
{
196199
DrawTexture(texRay,
197-
(int)((screenWidth/2.0f) + cos((frameCounter + i*8)/51.45f)*(screenWidth/2.2f) - 32),
198-
(int)((screenHeight/2.0f) + sin((frameCounter + i*8)/17.87f)*(screenHeight/4.2f)), WHITE);
200+
(int)((GetScreenWidth()/2.0f) + cos((frameCounter + i*8)/51.45f)*(GetScreenWidth()/2.2f) - 32),
201+
(int)((GetScreenHeight()/2.0f) + sin((frameCounter + i*8)/17.87f)*(GetScreenHeight()/4.2f)), WHITE);
199202
}
200203

201204
// Draw spot lights
@@ -204,14 +207,14 @@ int main(void)
204207
// a render texture of the full screen used to do screen
205208
// scaling (slight adjustment to shader would be required
206209
// to actually pay attention to the colour!)
207-
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
210+
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE);
208211
EndShaderMode();
209212

210213
DrawFPS(10, 10);
211214

212215
DrawText("Move the mouse!", 10, 30, 20, GREEN);
213-
DrawText("Pitch Black", (int)(screenWidth*0.2f), screenHeight/2, 20, GREEN);
214-
DrawText("Dark", (int)(screenWidth*.66f), screenHeight/2, 20, GREEN);
216+
DrawText("Pitch Black", (int)(GetScreenWidth()*0.2f), GetScreenHeight()/2, 20, GREEN);
217+
DrawText("Dark", (int)(GetScreenWidth()*.66f), GetScreenHeight()/2, 20, GREEN);
215218

216219
EndDrawing();
217220
//----------------------------------------------------------------------------------

examples/shaders/shaders_write_depth.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ int main(void)
7575
// Draw
7676
//----------------------------------------------------------------------------------
7777

78+
UnloadRenderTexture(target);
79+
target = LoadRenderTextureDepthTex(GetScreenWidth(), GetScreenHeight());
7880
// Draw into our custom render texture (framebuffer)
7981
BeginTextureMode(target);
8082
ClearBackground(WHITE);
@@ -94,7 +96,7 @@ int main(void)
9496
BeginDrawing();
9597
ClearBackground(RAYWHITE);
9698

97-
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
99+
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)GetScreenWidth(), (float)-GetScreenHeight() }, (Vector2) { 0, 0 }, WHITE);
98100
DrawFPS(10, 10);
99101
EndDrawing();
100102
//----------------------------------------------------------------------------------
@@ -166,4 +168,4 @@ void UnloadRenderTextureDepthTex(RenderTexture2D target)
166168
// queried and deleted before deleting framebuffer
167169
rlUnloadFramebuffer(target.id);
168170
}
169-
}
171+
}

examples/text/text_draw_3d.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -415,23 +415,23 @@ int main(void)
415415
quads += TextLength(text)*2*layers;
416416
char *tmp = (char *)TextFormat("%2i layer(s) | %s camera | %4i quads (%4i verts)", layers, spin? "ORBITAL" : "FREE", quads, quads*4);
417417
int width = MeasureText(tmp, 10);
418-
DrawText(tmp, screenWidth - 20 - width, 10, 10, DARKGREEN);
418+
DrawText(tmp, GetScreenWidth() - 20 - width, 10, 10, DARKGREEN);
419419

420420
tmp = "[Home]/[End] to add/remove 3D text layers";
421421
width = MeasureText(tmp, 10);
422-
DrawText(tmp, screenWidth - 20 - width, 25, 10, DARKGRAY);
422+
DrawText(tmp, GetScreenWidth() - 20 - width, 25, 10, DARKGRAY);
423423

424424
tmp = "[Insert]/[Delete] to increase/decrease distance between layers";
425425
width = MeasureText(tmp, 10);
426-
DrawText(tmp, screenWidth - 20 - width, 40, 10, DARKGRAY);
426+
DrawText(tmp, GetScreenWidth() - 20 - width, 40, 10, DARKGRAY);
427427

428428
tmp = "click the [CUBE] for a random color";
429429
width = MeasureText(tmp, 10);
430-
DrawText(tmp, screenWidth - 20 - width, 55, 10, DARKGRAY);
430+
DrawText(tmp, GetScreenWidth() - 20 - width, 55, 10, DARKGRAY);
431431

432432
tmp = "[Tab] to toggle multicolor mode";
433433
width = MeasureText(tmp, 10);
434-
DrawText(tmp, screenWidth - 20 - width, 70, 10, DARKGRAY);
434+
DrawText(tmp, GetScreenWidth() - 20 - width, 70, 10, DARKGRAY);
435435
//-------------------------------------------------------------------------
436436

437437
DrawFPS(10, 10);

0 commit comments

Comments
 (0)