mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-21 04:59:17 -05:00
[examples] Fix examples to work in MSVC (#5267)
* Fix warnings in many examples Add examples to MSVC solution correctly * fix CI error --------- Co-authored-by: Ray <raysan5@gmail.com>
This commit is contained in:
@ -68,8 +68,8 @@ int main(void)
|
||||
// Draw circle to bullet texture, then draw bullet using DrawTexture()
|
||||
// NOTE: This is done to improve the performance, since DrawCircle() is very slow
|
||||
BeginTextureMode(bulletTexture);
|
||||
DrawCircle(12, 12, bulletRadius, WHITE);
|
||||
DrawCircleLines(12, 12, bulletRadius, BLACK);
|
||||
DrawCircle(12, 12, (float)bulletRadius, WHITE);
|
||||
DrawCircleLines(12, 12, (float)bulletRadius, BLACK);
|
||||
EndTextureMode();
|
||||
|
||||
bool drawInPerformanceMode = true; // Switch between DrawCircle() and DrawTexture()
|
||||
@ -192,8 +192,8 @@ int main(void)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
DrawTexture(bulletTexture.texture,
|
||||
bullets[i].position.x - bulletTexture.texture.width*0.5f,
|
||||
bullets[i].position.y - bulletTexture.texture.height*0.5f,
|
||||
(int)(bullets[i].position.x - bulletTexture.texture.width*0.5f),
|
||||
(int)(bullets[i].position.y - bulletTexture.texture.height*0.5f),
|
||||
bullets[i].color);
|
||||
}
|
||||
}
|
||||
@ -206,8 +206,8 @@ int main(void)
|
||||
// Do not draw disabled bullets (out of screen)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
DrawCircleV(bullets[i].position, bulletRadius, bullets[i].color);
|
||||
DrawCircleLinesV(bullets[i].position, bulletRadius, BLACK);
|
||||
DrawCircleV(bullets[i].position, (float)bulletRadius, bullets[i].color);
|
||||
DrawCircleLinesV(bullets[i].position, (float)bulletRadius, BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ int main(void)
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw the dashed line with the current properties
|
||||
DrawLineDashed(lineStartPosition, lineEndPosition, dashLength, blankLength, lineColors[colorIndex]);
|
||||
DrawLineDashed(lineStartPosition, lineEndPosition, (int)dashLength, (int)blankLength, lineColors[colorIndex]);
|
||||
|
||||
// Draw UI and Instructions
|
||||
DrawRectangle(5, 5, 265, 95, Fade(SKYBLUE, 0.5f));
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS // Disable some Visual Studio warnings
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <math.h> // Required for: cosf(), sinf()
|
||||
@ -158,7 +160,7 @@ static void UpdateClock(Clock *clock)
|
||||
clock->minute.value = timeinfo->tm_min;
|
||||
clock->hour.value = timeinfo->tm_hour;
|
||||
|
||||
clock->hour.angle = (timeinfo->tm_hour%12)*180.0/6.0f;
|
||||
clock->hour.angle = (timeinfo->tm_hour%12)*180.0f/6.0f;
|
||||
clock->hour.angle += (timeinfo->tm_min%60)*30/60.0f;
|
||||
clock->hour.angle -= 90;
|
||||
|
||||
@ -175,8 +177,8 @@ static void UpdateClock(Clock *clock)
|
||||
static void DrawClockAnalog(Clock clock, Vector2 position)
|
||||
{
|
||||
// Draw clock base
|
||||
DrawCircleV(position, clock.second.length + 40, LIGHTGRAY);
|
||||
DrawCircleV(position, 12, GRAY);
|
||||
DrawCircleV(position, clock.second.length + 40.0f, LIGHTGRAY);
|
||||
DrawCircleV(position, 12.0f, GRAY);
|
||||
|
||||
// Draw clock minutes/seconds lines
|
||||
for (int i = 0; i < 60; i++)
|
||||
@ -192,15 +194,15 @@ static void DrawClockAnalog(Clock clock, Vector2 position)
|
||||
}
|
||||
|
||||
// Draw hand seconds
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, clock.second.length, clock.second.thickness },
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.second.length, (float)clock.second.thickness },
|
||||
(Vector2){ 0.0f, clock.second.thickness/2.0f }, clock.second.angle, clock.second.color);
|
||||
|
||||
// Draw hand minutes
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, clock.minute.length, clock.minute.thickness },
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.minute.length, (float)clock.minute.thickness },
|
||||
(Vector2){ 0.0f, clock.minute.thickness/2.0f }, clock.minute.angle, clock.minute.color);
|
||||
|
||||
// Draw hand hours
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, clock.hour.length, clock.hour.thickness },
|
||||
DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.hour.length, (float)clock.hour.thickness },
|
||||
(Vector2){ 0.0f, clock.hour.thickness/2.0f }, clock.hour.angle, clock.hour.color);
|
||||
}
|
||||
|
||||
@ -212,14 +214,14 @@ static void DrawClockDigital(Clock clock, Vector2 position)
|
||||
DrawDisplayValue((Vector2){ position.x, position.y }, clock.hour.value/10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
DrawDisplayValue((Vector2){ position.x + 120, position.y }, clock.hour.value%10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
DrawCircle(position.x + 240, position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle(position.x + 240, position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle((int)position.x + 240, (int)position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle((int)position.x + 240, (int)position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
DrawDisplayValue((Vector2){ position.x + 260, position.y }, clock.minute.value/10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
DrawDisplayValue((Vector2){ position.x + 380, position.y }, clock.minute.value%10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
DrawCircle(position.x + 500, position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle(position.x + 500, position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle((int)position.x + 500, (int)position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
DrawCircle((int)position.x + 500, (int)position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
DrawDisplayValue((Vector2){ position.x + 520, position.y }, clock.second.value/10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
DrawDisplayValue((Vector2){ position.x + 640, position.y }, clock.second.value%10, RED, Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
// Constant for Simulation
|
||||
#define SIMULATION_STEPS 30
|
||||
#define G 9.81
|
||||
#define G 9.81f
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
@ -43,9 +43,9 @@ int main(void)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - double pendulum");
|
||||
|
||||
// Simulation Paramters
|
||||
float l1 = 15, m1 = 0.2, theta1 = DEG2RAD*170, w1 = 0;
|
||||
float l2 = 15, m2 = 0.1, theta2 = DEG2RAD*0, w2 = 0;
|
||||
float lengthScaler = 0.1;
|
||||
float l1 = 15.0f, m1 = 0.2f, theta1 = DEG2RAD*170, w1 = 0;
|
||||
float l2 = 15.0f, m2 = 0.1f, theta2 = DEG2RAD*0, w2 = 0;
|
||||
float lengthScaler = 0.1f;
|
||||
float totalM = m1 + m2;
|
||||
|
||||
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
||||
@ -57,8 +57,8 @@ int main(void)
|
||||
float L2 = l2*lengthScaler;
|
||||
|
||||
// Draw parameters
|
||||
int lineThick = 20, trailThick = 2;
|
||||
float fateAlpha = 0.01;
|
||||
float lineThick = 20, trailThick = 2;
|
||||
float fateAlpha = 0.01f;
|
||||
|
||||
// Create framebuffer
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
@ -129,15 +129,15 @@ int main(void)
|
||||
ClearBackground(BLACK);
|
||||
|
||||
// Draw trails texture
|
||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
||||
|
||||
// Draw double pendulum
|
||||
DrawRectanglePro((Rectangle){ screenWidth/2, screenHeight/2 - 100, 10*l1, lineThick },
|
||||
(Vector2){0, lineThick*0.5}, 90 - RAD2DEG*theta1, RAYWHITE);
|
||||
DrawRectanglePro((Rectangle){ screenWidth/2.0f, screenHeight/2.0f - 100, 10*l1, lineThick },
|
||||
(Vector2){0, lineThick*0.5f}, 90 - RAD2DEG*theta1, RAYWHITE);
|
||||
|
||||
Vector2 endpoint1 = CalculatePendulumEndPoint(l1, theta1);
|
||||
DrawRectanglePro((Rectangle){ screenWidth/2 + endpoint1.x, screenHeight/2 - 100 + endpoint1.y, 10*l2, lineThick },
|
||||
(Vector2){0, lineThick*0.5}, 90 - RAD2DEG*theta2, RAYWHITE);
|
||||
DrawRectanglePro((Rectangle){ screenWidth/2.0f + endpoint1.x, screenHeight/2.0f - 100 + endpoint1.y, 10*l2, lineThick },
|
||||
(Vector2){0, lineThick*0.5f}, 90 - RAD2DEG*theta2, RAYWHITE);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -159,7 +159,7 @@ int main(void)
|
||||
// Calculate pendulum end point
|
||||
static Vector2 CalculatePendulumEndPoint(float l, float theta)
|
||||
{
|
||||
return (Vector2){ 10*l*sin(theta), 10*l*cos(theta) };
|
||||
return (Vector2){ 10*l*sinf(theta), 10*l*cosf(theta) };
|
||||
}
|
||||
|
||||
// Calculate double pendulum end point
|
||||
|
||||
@ -48,7 +48,7 @@ int main(void)
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - shapes recursive tree");
|
||||
|
||||
Vector2 start = { (screenWidth/2.0f) - 125.0f, screenHeight };
|
||||
Vector2 start = { (screenWidth/2.0f) - 125.0f, (float)screenHeight };
|
||||
float angle = 40.0f;
|
||||
float thick = 1.0f;
|
||||
float treeDepth = 10.0f;
|
||||
@ -66,7 +66,7 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
float theta = angle*DEG2RAD;
|
||||
int maxBranches = (int)(powf(2, (int)(treeDepth)));
|
||||
int maxBranches = (int)(powf(2, floorf(treeDepth)));
|
||||
Branch branches[1024] = { 0 };
|
||||
int count = 0;
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ int main(void)
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - vector angle");
|
||||
|
||||
Vector2 v0 = { screenWidth/2, screenHeight/2 };
|
||||
Vector2 v0 = { screenWidth/2.0f, screenHeight/2.0f };
|
||||
Vector2 v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f });
|
||||
Vector2 v2 = { 0 }; // Updated with mouse position
|
||||
|
||||
@ -97,17 +97,17 @@ int main(void)
|
||||
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));
|
||||
}
|
||||
|
||||
DrawText("v0", v0.x, v0.y, 10, DARKGRAY);
|
||||
DrawText("v0", (int)v0.x, (int)v0.y, 10, DARKGRAY);
|
||||
|
||||
// If the line from v0 to v1 would overlap the text, move it's position up 10
|
||||
if (angleMode == 0 && Vector2Subtract(v0, v1).y > 0.0f) DrawText("v1", v1.x, v1.y-10.0f, 10, DARKGRAY);
|
||||
if (angleMode == 0 && Vector2Subtract(v0, v1).y < 0.0f) DrawText("v1", v1.x, v1.y, 10, DARKGRAY);
|
||||
if (angleMode == 0 && Vector2Subtract(v0, v1).y > 0.0f) DrawText("v1", (int)v1.x, (int)v1.y-10, 10, DARKGRAY);
|
||||
if (angleMode == 0 && Vector2Subtract(v0, v1).y < 0.0f) DrawText("v1", (int)v1.x, (int)v1.y, 10, DARKGRAY);
|
||||
|
||||
// If angle mode 1, use v1 to emphasize the horizontal line
|
||||
if (angleMode == 1) DrawText("v1", v0.x + 40.0f, v0.y, 10, DARKGRAY);
|
||||
if (angleMode == 1) DrawText("v1", (int)v0.x + 40, (int)v0.y, 10, DARKGRAY);
|
||||
|
||||
// position adjusted by -10 so it isn't hidden by cursor
|
||||
DrawText("v2", v2.x-10.0f, v2.y-10.0f, 10, DARKGRAY);
|
||||
DrawText("v2", (int)v2.x-10, (int)v2.y-10, 10, DARKGRAY);
|
||||
|
||||
DrawText("Press SPACE to change MODE", 460, 10, 20, DARKGRAY);
|
||||
DrawText(TextFormat("ANGLE: %2.2f", angle), 10, 70, 20, LIME);
|
||||
|
||||
Reference in New Issue
Block a user