Skip to content

Commit b00cbda

Browse files
authored
Cleanup warnings in examples (#5467)
1 parent f67e70b commit b00cbda

13 files changed

+83
-80
lines changed

examples/audio/audio_music_stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int main(void)
113113
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
114114
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
115115
DrawRectangleLines(300, 100, 200, 12, GRAY);
116-
DrawRectangle(300 + (pan + 1.0)/2.0f*200 - 5, 92, 10, 28, DARKGRAY);
116+
DrawRectangle((int)(300 + (pan + 1.0f)/2.0f*200 - 5), 92, 10, 28, DARKGRAY);
117117

118118
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
119119
DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON);
@@ -125,7 +125,7 @@ int main(void)
125125
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
126126
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
127127
DrawRectangleLines(300, 360, 200, 12, GRAY);
128-
DrawRectangle(300 + volume*200 - 5, 352, 10, 28, DARKGRAY);
128+
DrawRectangle((int)(300 + volume*200 - 5), 352, 10, 28, DARKGRAY);
129129

130130
EndDrawing();
131131
//----------------------------------------------------------------------------------

examples/core/core_input_gamepad.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(void)
6767
if (IsKeyPressed(KEY_RIGHT)) gamepad++;
6868
Vector2 mousePosition = GetMousePosition();
6969

70-
vibrateButton = (Rectangle){ 10, 70 + 20*GetGamepadAxisCount(gamepad) + 20, 75, 24 };
70+
vibrateButton = (Rectangle){ 10, 70.0f + 20*GetGamepadAxisCount(gamepad) + 20, 75, 24 };
7171
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(mousePosition, vibrateButton)) SetGamepadVibration(gamepad, 1.0, 1.0, 1.0);
7272
//----------------------------------------------------------------------------------
7373

@@ -262,7 +262,7 @@ int main(void)
262262

263263
// Draw vibrate button
264264
DrawRectangleRec(vibrateButton, SKYBLUE);
265-
DrawText("VIBRATE", vibrateButton.x + 14, vibrateButton.y + 1, 10, DARKGRAY);
265+
DrawText("VIBRATE", (int)(vibrateButton.x + 14), (int)(vibrateButton.y + 1), 10, DARKGRAY);
266266

267267
if (GetGamepadButtonPressed() != GAMEPAD_BUTTON_UNKNOWN) DrawText(TextFormat("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
268268
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);

examples/core/core_viewport_scaling.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ int main(void)
112112
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed)
113113
{
114114
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1)%RESOLUTION_COUNT;
115-
gameWidth = resolutionList[resolutionIndex].x;
116-
gameHeight = resolutionList[resolutionIndex].y;
115+
gameWidth = (int)resolutionList[resolutionIndex].x;
116+
gameHeight = (int)resolutionList[resolutionIndex].y;
117117
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
118118
}
119119

120120
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed)
121121
{
122122
resolutionIndex = (resolutionIndex + 1)%RESOLUTION_COUNT;
123-
gameWidth = resolutionList[resolutionIndex].x;
124-
gameHeight = resolutionList[resolutionIndex].y;
123+
gameWidth = (int)resolutionList[resolutionIndex].x;
124+
gameHeight = (int)resolutionList[resolutionIndex].y;
125125
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
126126
}
127127

@@ -145,7 +145,7 @@ int main(void)
145145
// Draw our scene to the render texture
146146
BeginTextureMode(target);
147147
ClearBackground(WHITE);
148-
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.0f, LIME);
148+
DrawCircleV(textureMousePosition, 20.0f, LIME);
149149
EndTextureMode();
150150

151151
// Draw render texture to main framebuffer
@@ -159,7 +159,7 @@ int main(void)
159159
// Draw info box
160160
Rectangle infoRect = (Rectangle){5, 5, 330, 105};
161161
DrawRectangleRec(infoRect, Fade(LIGHTGRAY, 0.7f));
162-
DrawRectangleLines(infoRect.x, infoRect.y, infoRect.width, infoRect.height, BLUE);
162+
DrawRectangleLinesEx(infoRect, 1, BLUE);
163163

164164
DrawText(TextFormat("Window Resolution: %d x %d", screenWidth, screenHeight), 15, 15, 10, BLACK);
165165
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);

examples/models/models_decals.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ static void FreeMeshBuilder(MeshBuilder *mb);
4545
static Mesh BuildMesh(MeshBuilder *mb);
4646
static Mesh GenMeshDecal(Model inputModel, Matrix projection, float decalSize, float decalOffset);
4747
static Vector3 ClipSegment(Vector3 v0, Vector3 v1, Vector3 p, float s);
48-
#define FreeDecalMeshData() GenMeshDecal((Model){ .meshCount = -1.0f }, (Matrix){ 0 }, 0.0f, 0.0f)
48+
inline void FreeDecalMeshData()
49+
{
50+
GenMeshDecal((Model) { .meshCount = -1 }, (Matrix) { 0 }, 0.0f, 0.0f);
51+
}
4952
static bool GuiButton(Rectangle rec, const char *label);
5053

5154
//------------------------------------------------------------------------------------
@@ -198,12 +201,12 @@ int main(void)
198201
EndMode3D();
199202

200203
float yPos = 10;
201-
float x0 = GetScreenWidth() - 300;
204+
float x0 = GetScreenWidth() - 300.0f;
202205
float x1 = x0 + 100;
203206
float x2 = x1 + 100;
204207

205-
DrawText("Vertices", x1, yPos, 10, LIME);
206-
DrawText("Triangles", x2, yPos, 10, LIME);
208+
DrawText("Vertices", (int)x1, (int)yPos, 10, LIME);
209+
DrawText("Triangles", (int)x2, (int)yPos, 10, LIME);
207210
yPos += 15;
208211

209212
int vertexCount = 0;
@@ -215,43 +218,43 @@ int main(void)
215218
triangleCount += model.meshes[i].triangleCount;
216219
}
217220

218-
DrawText("Main model", x0, yPos, 10, LIME);
219-
DrawText(TextFormat("%d", vertexCount), x1, yPos, 10, LIME);
220-
DrawText(TextFormat("%d", triangleCount), x2, yPos, 10, LIME);
221+
DrawText("Main model", (int)x0, (int)yPos, 10, LIME);
222+
DrawText(TextFormat("%d", vertexCount), (int)x1, (int)yPos, 10, LIME);
223+
DrawText(TextFormat("%d", triangleCount), (int)x2, (int)yPos, 10, LIME);
221224
yPos += 15;
222225

223226
for (int i = 0; i < decalCount; i++)
224227
{
225228
if (i == 20)
226229
{
227-
DrawText("...", x0, yPos, 10, LIME);
230+
DrawText("...", (int)x0, (int)yPos, 10, LIME);
228231
yPos += 15;
229232
}
230233

231234
if (i < 20)
232235
{
233-
DrawText(TextFormat("Decal #%d", i+1), x0, yPos, 10, LIME);
234-
DrawText(TextFormat("%d", decalModels[i].meshes[0].vertexCount), x1, yPos, 10, LIME);
235-
DrawText(TextFormat("%d", decalModels[i].meshes[0].triangleCount), x2, yPos, 10, LIME);
236+
DrawText(TextFormat("Decal #%d", i+1), (int)x0, (int)yPos, 10, LIME);
237+
DrawText(TextFormat("%d", decalModels[i].meshes[0].vertexCount), (int)x1, (int)yPos, 10, LIME);
238+
DrawText(TextFormat("%d", decalModels[i].meshes[0].triangleCount), (int)x2, (int)yPos, 10, LIME);
236239
yPos += 15;
237240
}
238241

239242
vertexCount += decalModels[i].meshes[0].vertexCount;
240243
triangleCount += decalModels[i].meshes[0].triangleCount;
241244
}
242245

243-
DrawText("TOTAL", x0, yPos, 10, LIME);
244-
DrawText(TextFormat("%d", vertexCount), x1, yPos, 10, LIME);
245-
DrawText(TextFormat("%d", triangleCount), x2, yPos, 10, LIME);
246+
DrawText("TOTAL", (int)x0, (int)yPos, 10, LIME);
247+
DrawText(TextFormat("%d", vertexCount), (int)x1, (int)yPos, 10, LIME);
248+
DrawText(TextFormat("%d", triangleCount), (int)x2, (int)yPos, 10, LIME);
246249
yPos += 15;
247250

248251
DrawText("Hold RMB to move camera", 10, 430, 10, GRAY);
249252
DrawText("(c) Character model and texture from kenney.nl", screenWidth - 260, screenHeight - 20, 10, GRAY);
250253

251254
// UI elements
252-
if (GuiButton((Rectangle){ 10, screenHeight - 100, 100, 60 }, showModel ? "Hide Model" : "Show Model")) showModel = !showModel;
255+
if (GuiButton((Rectangle){ 10, screenHeight - 1000.f, 100, 60 }, showModel ? "Hide Model" : "Show Model")) showModel = !showModel;
253256

254-
if (GuiButton((Rectangle){ 10 + 110, screenHeight - 100, 100, 60 }, "Clear Decals"))
257+
if (GuiButton((Rectangle){ 10 + 110, screenHeight - 100.0f, 100, 60 }, "Clear Decals"))
255258
{
256259
// Clear decals, unload all decal models
257260
for (int i = 0; i < decalCount; i++) UnloadModel(decalModels[i]);
@@ -596,8 +599,8 @@ static bool GuiButton(Rectangle rec, const char *label)
596599
DrawRectangleRec(rec, bgColor);
597600
DrawRectangleLinesEx(rec, 2.0f, DARKGRAY);
598601

599-
float fontSize = 10.0f;
600-
float textWidth = MeasureText(label, fontSize);
602+
int fontSize = 10;
603+
int textWidth = MeasureText(label, fontSize);
601604

602605
DrawText(label, (int)(rec.x + rec.width*0.5f - textWidth*0.5f), (int)(rec.y + rec.height*0.5f - fontSize*0.5f), fontSize, DARKGRAY);
603606

examples/shapes/shapes_ball_physics.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ int main(void)
4646
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - ball physics");
4747

4848
Ball balls[MAX_BALLS] = {{
49-
.pos = { GetScreenWidth()/2, GetScreenHeight()/2 },
49+
.pos = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f },
5050
.vel = { 200, 200 },
5151
.ppos = { 0 },
5252
.radius = 40,
53-
.friction = 0.99,
54-
.elasticity = 0.9,
53+
.friction = 0.99f,
54+
.elasticity = 0.9f,
5555
.color = BLUE,
5656
.grabbed = false
5757
}};
@@ -110,11 +110,11 @@ int main(void)
110110
{
111111
balls[ballCount++] = (Ball){
112112
.pos = mousePos,
113-
.vel = { GetRandomValue(-300, 300), GetRandomValue(-300, 300) },
113+
.vel = { (float)GetRandomValue(-300, 300), (float)GetRandomValue(-300, 300) },
114114
.ppos = { 0 },
115-
.radius = 20 + GetRandomValue(0, 30),
116-
.friction = 0.99,
117-
.elasticity = 0.9,
115+
.radius = 20.0f + (float)GetRandomValue(0, 30),
116+
.friction = 0.99f,
117+
.elasticity = 0.9f,
118118
.color = { GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 },
119119
.grabbed = false
120120
};
@@ -126,7 +126,7 @@ int main(void)
126126
{
127127
for (int i = 0; i < ballCount; i++)
128128
{
129-
if (!balls[i].grabbed) balls[i].vel = (Vector2){ GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000) };
129+
if (!balls[i].grabbed) balls[i].vel = (Vector2){ (float)GetRandomValue(-2000, 2000), (float)GetRandomValue(-2000, 2000) };
130130
}
131131
}
132132

examples/shapes/shapes_kaleidoscope.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ int main(void)
5050
int symmetry = 6;
5151
float angle = 360.0f/(float)symmetry;
5252
float thickness = 3.0f;
53-
Rectangle resetButtonRec = { screenWidth - 55, 5, 50, 25 };
54-
Rectangle backButtonRec = { screenWidth - 55, screenHeight - 30, 25, 25 };
55-
Rectangle nextButtonRec = { screenWidth - 30, screenHeight - 30, 25, 25 };
53+
Rectangle resetButtonRec = { screenWidth - 55.0f, 5.0f, 50, 25 };
54+
Rectangle backButtonRec = { screenWidth - 55.0f, screenHeight - 30.0f, 25, 25 };
55+
Rectangle nextButtonRec = { screenWidth - 30.0f, screenHeight - 30.0f, 25, 25 };
5656
Vector2 mousePos = { 0 };
5757
Vector2 prevMousePos = { 0 };
5858
Vector2 scaleVector = { 1.0f, -1.0f };

examples/shapes/shapes_penrose_tile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ static void BuildProductionStep(PenroseLSystem *ls)
185185
char *newProduction = (char *)RL_MALLOC(sizeof(char)*STR_MAX_SIZE);
186186
newProduction[0] = '\0';
187187

188-
int productionLength = strnlen(ls->production, STR_MAX_SIZE);
188+
int productionLength = (int)strnlen(ls->production, STR_MAX_SIZE);
189189

190190
for (int i = 0; i < productionLength; i++)
191191
{
192192
char step = ls->production[i];
193-
int remainingSpace = STR_MAX_SIZE - strnlen(newProduction, STR_MAX_SIZE) - 1;
193+
int remainingSpace = STR_MAX_SIZE - (int)strnlen(newProduction, STR_MAX_SIZE) - 1;
194194
switch (step)
195195
{
196196
case 'W': strncat(newProduction, ls->ruleW, remainingSpace); break;
@@ -201,7 +201,7 @@ static void BuildProductionStep(PenroseLSystem *ls)
201201
{
202202
if (step != 'F')
203203
{
204-
int t = strnlen(newProduction, STR_MAX_SIZE);
204+
int t = (int)strnlen(newProduction, STR_MAX_SIZE);
205205
newProduction[t] = step;
206206
newProduction[t + 1] = '\0';
207207
}
@@ -218,7 +218,7 @@ static void BuildProductionStep(PenroseLSystem *ls)
218218
// Draw penrose tile lines
219219
static void DrawPenroseLSystem(PenroseLSystem *ls)
220220
{
221-
Vector2 screenCenter = { GetScreenWidth()/2, GetScreenHeight()/2 };
221+
Vector2 screenCenter = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
222222

223223
TurtleState turtle = {
224224
.origin = { 0 },
@@ -245,7 +245,7 @@ static void DrawPenroseLSystem(PenroseLSystem *ls)
245245
Vector2 startPosScreen = { startPosWorld.x + screenCenter.x, startPosWorld.y + screenCenter.y };
246246
Vector2 endPosScreen = { turtle.origin.x + screenCenter.x, turtle.origin.y + screenCenter.y };
247247

248-
DrawLineEx(startPosScreen, endPosScreen, 2, Fade(BLACK, 0.2));
248+
DrawLineEx(startPosScreen, endPosScreen, 2, Fade(BLACK, 0.2f));
249249
}
250250

251251
repeats = 1;

examples/text/text_inline_styling.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ static void DrawTextStyled(Font font, const char *text, Vector2 position, float
178178
// Convert hex color text into actual Color
179179
unsigned int colHexValue = strtoul(colHexText, NULL, 16);
180180
if (text[i - 1] == 'c')
181-
{
181+
{
182182
colFront = GetColor(colHexValue);
183-
colFront.a *= (float)color.a/255.0f;
183+
colFront.a = (unsigned char)(colFront.a * (float)color.a/255.0f);
184184
}
185185
else if (text[i - 1] == 'b')
186186
{
187187
colBack = GetColor(colHexValue);
188-
colBack.a *= (float)color.a/255.0f;
188+
colBack.a *= (unsigned char)(colFront.a * (float)color.a / 255.0f);
189189
}
190190

191191
i += (colHexCount + 1); // Skip color value retrieved and ']'

examples/text/text_strings_management.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int main(void)
133133
{
134134
for (int i = 0; i < particleCount; i++)
135135
{
136-
if (!textParticles[i].grabbed) textParticles[i].vel = (Vector2){ GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000) };
136+
if (!textParticles[i].grabbed) textParticles[i].vel = (Vector2){ (float)GetRandomValue(-2000, 2000), (float)GetRandomValue(-2000, 2000) };
137137
}
138138
}
139139

@@ -233,9 +233,9 @@ int main(void)
233233
for (int i = 0; i < particleCount; i++)
234234
{
235235
TextParticle *tp = &textParticles[i];
236-
DrawRectangle(tp->rect.x-tp->borderWidth, tp->rect.y-tp->borderWidth, tp->rect.width+tp->borderWidth*2, tp->rect.height+tp->borderWidth*2, BLACK);
236+
DrawRectangleRec((Rectangle) { tp->rect.x - tp->borderWidth, tp->rect.y - tp->borderWidth, tp->rect.width + tp->borderWidth * 2, tp->rect.height + tp->borderWidth * 2 }, BLACK);
237237
DrawRectangleRec(tp->rect, tp->color);
238-
DrawText(tp->text, tp->rect.x+tp->padding, tp->rect.y+tp->padding, FONT_SIZE, BLACK);
238+
DrawText(tp->text, (int)(tp->rect.x+tp->padding), (int)(tp->rect.y+tp->padding), FONT_SIZE, BLACK);
239239
}
240240

241241
DrawText("grab a text particle by pressing with the mouse and throw it by releasing", 10, 10, 10, DARKGRAY);
@@ -265,8 +265,8 @@ void PrepareFirstTextParticle(const char* text, TextParticle *tps, int *particle
265265
{
266266
tps[0] = CreateTextParticle(
267267
text,
268-
GetScreenWidth()/2,
269-
GetScreenHeight()/2,
268+
GetScreenWidth()/2.0f,
269+
GetScreenHeight()/2.0f,
270270
RAYWHITE
271271
);
272272
*particleCount = 1;
@@ -277,12 +277,12 @@ TextParticle CreateTextParticle(const char *text, float x, float y, Color color)
277277
TextParticle tp = {
278278
.text = "",
279279
.rect = { x, y, 30, 30 },
280-
.vel = { GetRandomValue(-200, 200), GetRandomValue(-200, 200) },
280+
.vel = { (float)GetRandomValue(-200, 200), (float)GetRandomValue(-200, 200) },
281281
.ppos = { 0 },
282282
.padding = 5.0f,
283283
.borderWidth = 5.0f,
284-
.friction = 0.99,
285-
.elasticity = 0.9,
284+
.friction = 0.99f,
285+
.elasticity = 0.9f,
286286
.color = color,
287287
.grabbed = false
288288
};

examples/textures/textures_screen_buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main(void)
6666
// Grow flameRoot
6767
for (int x = 2; x < flameWidth; x++)
6868
{
69-
unsigned short flame = flameRootBuffer[x];
69+
unsigned char flame = flameRootBuffer[x];
7070
if (flame == 255) continue;
7171
flame += GetRandomValue(0, 2);
7272
if (flame > 255) flame = 255;

0 commit comments

Comments
 (0)