Skip to content

Commit 199f993

Browse files
authored
Merge pull request #393 from penggrin12/fix-msvc-errors
Fix building with MSVC & reduce the amount of warnings in general
2 parents 0a981c4 + d5628c4 commit 199f993

34 files changed

Lines changed: 311 additions & 275 deletions

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ if(BUILD_RAYLIB_CPP_EXAMPLES)
5656
)
5757
endif()
5858
endif()
59+
60+
# ignore unused functions
61+
if (MSVC)
62+
target_compile_options(raylib_cpp INTERFACE /wd4505)
63+
else()
64+
target_compile_options(raylib_cpp INTERFACE -Wno-unused-function)
65+
endif()

examples/shaders/shaders_basic_lighting.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ int main(void)
4848

4949
// Define the camera to look into our 3d world
5050
raylib::Camera camera;
51-
camera.position = (Vector3){ 2.0f, 4.0f, 6.0f }; // Camera position
52-
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
53-
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
51+
camera.position = Vector3{ 2.0f, 4.0f, 6.0f }; // Camera position
52+
camera.target = Vector3{ 0.0f, 0.5f, 0.0f }; // Camera looking at point
53+
camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
5454
camera.fovy = 45.0f; // Camera field-of-view Y
5555
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
5656

@@ -70,10 +70,10 @@ int main(void)
7070

7171
// Create lights
7272
std::array<Light, MAX_LIGHTS> lights = {
73-
CreateLight(LIGHT_POINT, (Vector3) {-2, 1, -2}, Vector3Zero(), YELLOW, shader),
74-
CreateLight(LIGHT_POINT, (Vector3) {2, 1, 2}, Vector3Zero(), RED, shader),
75-
CreateLight(LIGHT_POINT, (Vector3) {-2, 1, 2}, Vector3Zero(), GREEN, shader),
76-
CreateLight(LIGHT_POINT, (Vector3) {2, 1, -2}, Vector3Zero(), BLUE, shader),
73+
CreateLight(LIGHT_POINT, Vector3 {-2, 1, -2}, Vector3Zero(), YELLOW, shader),
74+
CreateLight(LIGHT_POINT, Vector3 {2, 1, 2}, Vector3Zero(), RED, shader),
75+
CreateLight(LIGHT_POINT, Vector3 {-2, 1, 2}, Vector3Zero(), GREEN, shader),
76+
CreateLight(LIGHT_POINT, Vector3 {2, 1, -2}, Vector3Zero(), BLUE, shader),
7777
};
7878

7979
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@@ -110,7 +110,7 @@ int main(void)
110110

111111
BeginShaderMode(shader);
112112

113-
DrawPlane(Vector3Zero(), (Vector2) { 10.0, 10.0 }, WHITE);
113+
DrawPlane(Vector3Zero(), Vector2 { 10.0, 10.0 }, WHITE);
114114
DrawCube(Vector3Zero(), 2.0, 4.0, 2.0, WHITE);
115115

116116
EndShaderMode();

examples/shaders/shaders_basic_pbr.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ int main()
8888

8989
// Define the camera to look into our 3d world
9090
raylib::Camera camera;
91-
camera.position = (Vector3){ 2.0f, 2.0f, 6.0f }; // Camera position
92-
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
93-
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
91+
camera.position = Vector3{ 2.0f, 2.0f, 6.0f }; // Camera position
92+
camera.target = Vector3{ 0.0f, 0.5f, 0.0f }; // Camera looking at point
93+
camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
9494
camera.fovy = 45.0f; // Camera field-of-view Y
9595
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
9696

@@ -117,8 +117,8 @@ int main()
117117

118118
// Setup ambient color and intensity parameters
119119
float ambientIntensity = 0.02f;
120-
raylib::Color ambientColor = (Color){ 26, 32, 135, 255 };
121-
raylib::Vector3 ambientColorNormalized = (Vector3){ ambientColor.r/255.0f, ambientColor.g/255.0f, ambientColor.b/255.0f };
120+
raylib::Color ambientColor = Color{ 26, 32, 135, 255 };
121+
raylib::Vector3 ambientColorNormalized = Vector3{ ambientColor.r/255.0f, ambientColor.g/255.0f, ambientColor.b/255.0f };
122122
shader.SetValue(shader.GetLocation("ambientColor"), &ambientColorNormalized, SHADER_UNIFORM_VEC3);
123123
shader.SetValue(shader.GetLocation("ambient"), &ambientIntensity, SHADER_UNIFORM_FLOAT);
124124

@@ -142,7 +142,7 @@ int main()
142142
car.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.0f;
143143
car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.0f;
144144
car.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
145-
car.materials[0].maps[MATERIAL_MAP_EMISSION].color = (Color){ 255, 162, 0, 255 };
145+
car.materials[0].maps[MATERIAL_MAP_EMISSION].color = Color{ 255, 162, 0, 255 };
146146

147147
// Setup materials[0].maps default textures
148148
car.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = LoadTexture("resources/old_car_d.png");
@@ -172,15 +172,15 @@ int main()
172172

173173
// Models texture tiling parameter can be stored in the Material struct if required (CURRENTLY NOT USED)
174174
// NOTE: Material.params[4] are available for generic parameters storage (float)
175-
Vector2 carTextureTiling = (Vector2){ 0.5f, 0.5f };
176-
Vector2 floorTextureTiling = (Vector2){ 0.5f, 0.5f };
175+
Vector2 carTextureTiling = Vector2{ 0.5f, 0.5f };
176+
Vector2 floorTextureTiling = Vector2{ 0.5f, 0.5f };
177177

178178
// Create some lights
179179
std::array<Light, MAX_LIGHTS> lights = {
180-
CreateLight(0, LightType::POINT, (Vector3) {-1.0f, 1.0f, -2.0f}, (Vector3) {0.0f, 0.0f, 0.0f}, YELLOW, 4.0f, shader),
181-
CreateLight(1, LightType::POINT, (Vector3){ 2.0f, 1.0f, 1.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, GREEN, 3.3f, shader),
182-
CreateLight(2, LightType::POINT, (Vector3){ -2.0f, 1.0f, 1.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, RED, 8.3f, shader),
183-
CreateLight(3, LightType::POINT, (Vector3){ 1.0f, 1.0f, -2.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, BLUE, 2.0f, shader),
180+
CreateLight(0, LightType::POINT, Vector3{-1.0f, 1.0f, -2.0f}, Vector3{0.0f, 0.0f, 0.0f}, YELLOW, 4.0f, shader),
181+
CreateLight(1, LightType::POINT, Vector3{ 2.0f, 1.0f, 1.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, GREEN, 3.3f, shader),
182+
CreateLight(2, LightType::POINT, Vector3{ -2.0f, 1.0f, 1.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, RED, 8.3f, shader),
183+
CreateLight(3, LightType::POINT, Vector3{ 1.0f, 1.0f, -2.0f }, Vector3{ 0.0f, 0.0f, 0.0f }, BLUE, 2.0f, shader),
184184
};
185185

186186
// Setup material texture maps usage in shader
@@ -228,7 +228,7 @@ int main()
228228
raylib::Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
229229
SetShaderValue(shader, emissiveColorLoc, &floorEmissiveColor, SHADER_UNIFORM_VEC4);
230230

231-
DrawModel(floor, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
231+
DrawModel(floor, Vector3{ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
232232

233233
// Set old car model texture tiling, emissive color and emissive intensity parameters on shader
234234
SetShaderValue(shader, textureTilingLoc, &carTextureTiling, SHADER_UNIFORM_VEC2);
@@ -237,15 +237,15 @@ int main()
237237
float emissiveIntensity = 0.01f;
238238
SetShaderValue(shader, emissiveIntensityLoc, &emissiveIntensity, SHADER_UNIFORM_FLOAT);
239239

240-
car.Draw((Vector3){ 0.0f, 0.0f, 0.0f }, 0.005f, WHITE); // Draw car model
240+
car.Draw(Vector3{ 0.0f, 0.0f, 0.0f }, 0.005f, WHITE); // Draw car model
241241

242242
// Draw spheres to show the lights positions
243243
for (const auto& light : lights)
244244
{
245-
Color lightColor = (Color){ static_cast<unsigned char>(light.color[0]*255),
246-
static_cast<unsigned char>(light.color[1]*255),
247-
static_cast<unsigned char>(light.color[2]*255),
248-
static_cast<unsigned char>(light.color[3]*255) };
245+
Color lightColor = Color{ static_cast<unsigned char>(light.color[0]*255),
246+
static_cast<unsigned char>(light.color[1]*255),
247+
static_cast<unsigned char>(light.color[2]*255),
248+
static_cast<unsigned char>(light.color[3]*255) };
249249

250250
if (light.enabled) DrawSphereEx(light.position, 0.2f, 8, 8, lightColor);
251251
else DrawSphereWires(light.position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
@@ -267,12 +267,12 @@ int main()
267267
//--------------------------------------------------------------------------------------
268268
// Unbind (disconnect) shader from car.material[0]
269269
// to avoid UnloadMaterial() trying to unload it automatically
270-
car.materials[0].shader = (Shader){ 0 };
270+
car.materials[0].shader = Shader{ 0 };
271271
UnloadMaterial(car.materials[0]);
272272
car.materials[0].maps = NULL;
273273
//UnloadModel(car);
274274

275-
floor.materials[0].shader = (Shader){ 0 };
275+
floor.materials[0].shader = Shader{ 0 };
276276
UnloadMaterial(floor.materials[0]);
277277
floor.materials[0].maps = NULL;
278278
//UnloadModel(floor);

include/AudioStreamUnmanaged.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
8787
/**
8888
* Check if any audio stream buffers require refill.
8989
*/
90-
[[nodiscard]] bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
90+
RLCPP_NODISCARD bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
9191

9292
/**
9393
* Play audio stream.
@@ -116,7 +116,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
116116
/**
117117
* Check if audio stream is playing.
118118
*/
119-
[[nodiscard]] bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
119+
RLCPP_NODISCARD bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
120120

121121
/**
122122
* Stop audio stream.
@@ -182,7 +182,7 @@ class AudioStreamUnmanaged : public ::AudioStream {
182182
/**
183183
* Retrieve whether or not the audio stream is ready.
184184
*/
185-
[[nodiscard]] bool IsValid() const { return ::IsAudioStreamValid(*this); }
185+
RLCPP_NODISCARD bool IsValid() const { return ::IsAudioStreamValid(*this); }
186186

187187
protected:
188188
void set(const ::AudioStream& stream) {

include/BoundingBox.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ class BoundingBox : public ::BoundingBox {
5050
/**
5151
* Detect collision between two boxes
5252
*/
53-
[[nodiscard]] bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
53+
RLCPP_NODISCARD bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
5454

5555
/**
5656
* Detect collision between box and sphere
5757
*/
58-
[[nodiscard]] bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
58+
RLCPP_NODISCARD bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
5959

6060
/**
6161
* Detect collision between ray and bounding box
6262
*/
63-
[[nodiscard]] bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
63+
RLCPP_NODISCARD bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
6464

6565
/**
6666
* Get collision information between ray and bounding box

include/Camera2D.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ class Camera2D : public ::Camera2D {
4242
/**
4343
* Returns camera 2d transform matrix
4444
*/
45-
[[nodiscard]] Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
45+
RLCPP_NODISCARD Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
4646

4747
/**
4848
* Returns the world space position for a 2d camera screen space position
4949
*/
50-
[[nodiscard]] Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
50+
RLCPP_NODISCARD Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
5151

5252
/**
5353
* Returns the screen space position for a 2d world space position
5454
*/
55-
[[nodiscard]] Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
55+
RLCPP_NODISCARD Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
5656
protected:
5757
void set(const ::Camera2D& camera) {
5858
offset = camera.offset;

include/Color.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ class Color : public ::Color {
4343
/**
4444
* Returns hexadecimal value for a Color
4545
*/
46-
[[nodiscard]] int ToInt() const { return ::ColorToInt(*this); }
46+
RLCPP_NODISCARD int ToInt() const { return ::ColorToInt(*this); }
4747

4848
/**
4949
* Returns hexadecimal value for a Color
5050
*/
5151
explicit operator int() const { return ::ColorToInt(*this); }
5252

53-
[[nodiscard]] std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
53+
RLCPP_NODISCARD std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
5454

5555
explicit operator std::string() const { return ToString(); }
5656

5757
/**
5858
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
5959
*/
60-
[[nodiscard]] Color Fade(float alpha) const { return ::Fade(*this, alpha); }
60+
RLCPP_NODISCARD Color Fade(float alpha) const { return ::Fade(*this, alpha); }
6161

6262
/**
6363
* Returns Color normalized as float [0..1]
6464
*/
65-
[[nodiscard]] Vector4 Normalize() const { return ::ColorNormalize(*this); }
65+
RLCPP_NODISCARD Vector4 Normalize() const { return ::ColorNormalize(*this); }
6666

6767
/**
6868
* Returns Color from normalized values [0..1]
@@ -72,7 +72,7 @@ class Color : public ::Color {
7272
/**
7373
* Returns HSV values for a Color
7474
*/
75-
[[nodiscard]] Vector3 ToHSV() const { return ::ColorToHSV(*this); }
75+
RLCPP_NODISCARD Vector3 ToHSV() const { return ::ColorToHSV(*this); }
7676

7777
GETTERSETTER(unsigned char, R, r)
7878
GETTERSETTER(unsigned char, G, g)
@@ -206,7 +206,7 @@ class Color : public ::Color {
206206
/**
207207
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
208208
*/
209-
[[nodiscard]] Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
209+
RLCPP_NODISCARD Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
210210

211211
Color Lerp(::Color color2, float factor) {
212212
return ::ColorLerp(*this, color2, factor);
@@ -215,7 +215,7 @@ class Color : public ::Color {
215215
/**
216216
* Returns src alpha-blended into dst color with tint
217217
*/
218-
[[nodiscard]] Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
218+
RLCPP_NODISCARD Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
219219

220220
static Color LightGray() { return LIGHTGRAY; }
221221
static Color Gray() { return GRAY; }

include/FileText.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class FileText {
3030
GETTER(const char*, Data, data)
3131
GETTER(unsigned int, Length, length)
3232

33-
[[nodiscard]] const char* c_str() const { return data; }
33+
RLCPP_NODISCARD const char* c_str() const { return data; }
3434

35-
[[nodiscard]] std::string ToString() const { return data; }
35+
RLCPP_NODISCARD std::string ToString() const { return data; }
3636
explicit operator std::string() const { return data; }
3737

3838
void Load(const std::string& fileName) { Load(fileName.c_str()); }

include/FontUnmanaged.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class FontUnmanaged : public ::Font {
8787
* Get the texture atlas containing the glyphs.
8888
*/
8989
TextureUnmanaged GetTexture() { return texture; }
90-
[[nodiscard]] TextureUnmanaged GetTexture() const { return texture; }
90+
RLCPP_NODISCARD TextureUnmanaged GetTexture() const { return texture; }
9191

9292
/**
9393
* Set the texture atlas containing the glyphs.
@@ -167,7 +167,7 @@ class FontUnmanaged : public ::Font {
167167
/**
168168
* Returns if the font is ready to be used.
169169
*/
170-
[[nodiscard]] bool IsValid() const { return ::IsFontValid(*this); }
170+
RLCPP_NODISCARD bool IsValid() const { return ::IsFontValid(*this); }
171171

172172
/**
173173
* Draw text using font and additional parameters.
@@ -265,33 +265,33 @@ class FontUnmanaged : public ::Font {
265265
/**
266266
* Measure string size for Font.
267267
*/
268-
[[nodiscard]] Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
268+
RLCPP_NODISCARD Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
269269
return ::MeasureTextEx(*this, text, fontSize, spacing);
270270
}
271271

272272
/**
273273
* Measure string size for Font.
274274
*/
275-
[[nodiscard]] Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
275+
RLCPP_NODISCARD Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
276276
return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
277277
}
278278

279279
/**
280280
* Get index position for a unicode character on font.
281281
*/
282-
[[nodiscard]] int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
282+
RLCPP_NODISCARD int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
283283

284284
/**
285285
* Create an image from text (custom sprite font).
286286
*/
287-
[[nodiscard]] ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
287+
RLCPP_NODISCARD ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
288288
return ::ImageTextEx(*this, text, fontSize, spacing, tint);
289289
}
290290

291291
/**
292292
* Create an image from text (custom sprite font).
293293
*/
294-
[[nodiscard]] ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
294+
RLCPP_NODISCARD ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
295295
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
296296
}
297297

0 commit comments

Comments
 (0)