From bc628c6b2822d7099540f6a2f579d9f12a2213bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Tue, 20 Apr 2021 15:59:24 +0200 Subject: [PATCH] Fix warnings in examples - Convert where necessary - Adjust type where reasonable - Use SYSTEM headers for gl.h, stb* and vulkan --- examples/X11/CMakeLists.txt | 3 ++ examples/X11/X11.cpp | 2 +- examples/island/CMakeLists.txt | 3 ++ examples/island/Island.cpp | 66 +++++++++++++++++++--------------- examples/joystick/Joystick.cpp | 8 ++--- examples/opengl/CMakeLists.txt | 3 ++ examples/opengl/OpenGL.cpp | 22 ++++++------ examples/shader/Shader.cpp | 20 +++++------ examples/tennis/Tennis.cpp | 10 +++--- examples/voip/Server.cpp | 4 +-- examples/vulkan/CMakeLists.txt | 3 ++ examples/vulkan/Vulkan.cpp | 48 +++++++++++++------------ examples/window/CMakeLists.txt | 3 ++ examples/window/Window.cpp | 14 ++++---- 14 files changed, 118 insertions(+), 91 deletions(-) diff --git a/examples/X11/CMakeLists.txt b/examples/X11/CMakeLists.txt index d4039c0e..0ff90aca 100644 --- a/examples/X11/CMakeLists.txt +++ b/examples/X11/CMakeLists.txt @@ -8,3 +8,6 @@ set(SRC ${SRCROOT}/X11.cpp) sfml_add_example(X11Example GUI_APP SOURCES ${SRC} DEPENDS sfml-window X11) + +# external dependency headers +target_include_directories(X11Example SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/examples/X11) \ No newline at end of file diff --git a/examples/X11/X11.cpp b/examples/X11/X11.cpp index 08ab24c1..76d52d37 100644 --- a/examples/X11/X11.cpp +++ b/examples/X11/X11.cpp @@ -5,7 +5,7 @@ #include #define GLAD_GL_IMPLEMENTATION -#include "gl.h" +#include #include #include diff --git a/examples/island/CMakeLists.txt b/examples/island/CMakeLists.txt index 3b063fb8..71a865d2 100644 --- a/examples/island/CMakeLists.txt +++ b/examples/island/CMakeLists.txt @@ -9,3 +9,6 @@ sfml_add_example(island GUI_APP SOURCES ${SRC} DEPENDS sfml-graphics RESOURCES_DIR resources) + +# external dependency headers +target_include_directories(island SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/examples/island) \ No newline at end of file diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 8d1bd3ea..d0165f10 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -3,7 +3,7 @@ // Headers //////////////////////////////////////////////////////////// #define STB_PERLIN_IMPLEMENTATION -#include "stb_perlin.h" +#include #include #include #include @@ -273,10 +273,10 @@ float getElevation(float x, float y) for (int i = 0; i < perlinOctaves; i++) { elevation += stb_perlin_noise3( - x * perlinFrequency * std::pow(perlinFrequencyBase, i), - y * perlinFrequency * std::pow(perlinFrequencyBase, i), + x * perlinFrequency * static_cast(std::pow(perlinFrequencyBase, i)), + y * perlinFrequency * static_cast(std::pow(perlinFrequencyBase, i)), 0, 0, 0, 0 - ) * std::pow(perlinFrequencyBase, -i); + ) * static_cast(std::pow(perlinFrequencyBase, -i)); } elevation = (elevation + 1.f) / 2.f; @@ -288,6 +288,11 @@ float getElevation(float x, float y) return elevation; } +float getElevation(unsigned int x, unsigned int y) +{ + return getElevation(static_cast(x), static_cast(y)); +} + //////////////////////////////////////////////////////////// /// Get the terrain moisture at the given coordinates. @@ -307,6 +312,11 @@ float getMoisture(float x, float y) return (moisture + 1.f) / 2.f; } +float getMoisture(unsigned int x, unsigned int y) +{ + return getMoisture(static_cast(x), static_cast(y)); +} + //////////////////////////////////////////////////////////// /// Get the lowlands terrain color for the given moisture. @@ -316,11 +326,11 @@ sf::Color getLowlandsTerrainColor(float moisture) { sf::Color color = moisture < 0.27f ? sf::Color(240, 240, 180) : - moisture < 0.3f ? sf::Color(240 - 240 * (moisture - 0.27f) / 0.03f, 240 - 40 * (moisture - 0.27f) / 0.03f, 180 - 180 * (moisture - 0.27f) / 0.03f) : + moisture < 0.3f ? sf::Color(240 - static_cast(240 * (moisture - 0.27f) / 0.03f), 240 - static_cast(40 * (moisture - 0.27f) / 0.03f), 180 - static_cast(180 * (moisture - 0.27f) / 0.03f)) : moisture < 0.4f ? sf::Color(0, 200, 0) : - moisture < 0.48f ? sf::Color(0, 200 - 40 * (moisture - 0.4f) / 0.08f, 0) : + moisture < 0.48f ? sf::Color(0, 200 - static_cast(40 * (moisture - 0.4f) / 0.08f), 0) : moisture < 0.6f ? sf::Color(0, 160, 0) : - moisture < 0.7f ? sf::Color(34 * (moisture - 0.6f) / 0.1f, 160 - 60 * (moisture - 0.6f) / 0.1f, 34 * (moisture - 0.6f) / 0.1f) : + moisture < 0.7f ? sf::Color(static_cast(34 * (moisture - 0.6f) / 0.1f), 160 - static_cast(60 * (moisture - 0.6f) / 0.1f), static_cast(34 * (moisture - 0.6f) / 0.1f)) : sf::Color(34, 100, 34); return color; @@ -338,13 +348,13 @@ sf::Color getHighlandsTerrainColor(float elevation, float moisture) sf::Color color = moisture < 0.6f ? sf::Color(112, 128, 144) : - sf::Color(112 + 110 * (moisture - 0.6f) / 0.4f, 128 + 56 * (moisture - 0.6f) / 0.4f, 144 - 9 * (moisture - 0.6f) / 0.4f); + sf::Color(112 + static_cast(110 * (moisture - 0.6f) / 0.4f), 128 + static_cast(56 * (moisture - 0.6f) / 0.4f), 144 - static_cast(9 * (moisture - 0.6f) / 0.4f)); float factor = std::min((elevation - 0.4f) / 0.1f, 1.f); - color.r = lowlandsColor.r * (1.f - factor) + color.r * factor; - color.g = lowlandsColor.g * (1.f - factor) + color.g * factor; - color.b = lowlandsColor.b * (1.f - factor) + color.b * factor; + color.r = static_cast(lowlandsColor.r * (1.f - factor) + color.r * factor); + color.g = static_cast(lowlandsColor.g * (1.f - factor) + color.g * factor); + color.b = static_cast(lowlandsColor.b * (1.f - factor) + color.b * factor); return color; } @@ -363,9 +373,9 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture) float factor = std::min((elevation - snowcapHeight) / 0.05f, 1.f); - color.r = highlandsColor.r * (1.f - factor) + color.r * factor; - color.g = highlandsColor.g * (1.f - factor) + color.g * factor; - color.b = highlandsColor.b * (1.f - factor) + color.b * factor; + color.r = static_cast(highlandsColor.r * (1.f - factor) + color.r * factor); + color.g = static_cast(highlandsColor.g * (1.f - factor) + color.g * factor); + color.b = static_cast(highlandsColor.b * (1.f - factor) + color.b * factor); return color; } @@ -379,9 +389,9 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture) sf::Color getTerrainColor(float elevation, float moisture) { sf::Color color = - elevation < 0.11f ? sf::Color(0, 0, elevation / 0.11f * 74.f + 181.0f) : - elevation < 0.14f ? sf::Color(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, 255) : - elevation < 0.16f ? sf::Color((elevation - 0.14f) * 128.f / 0.02f + 48.f, (elevation - 0.14f) * 128.f / 0.02f + 48.f, 127.0f + (0.16f - elevation) * 128.f / 0.02f) : + elevation < 0.11f ? sf::Color(0, 0, static_cast(elevation / 0.11f * 74.f + 181.0f)) : + elevation < 0.14f ? sf::Color(static_cast(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), static_cast(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), 255) : + elevation < 0.16f ? sf::Color(static_cast((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast(127.0f + (0.16f - elevation) * 128.f / 0.02f)) : elevation < 0.17f ? sf::Color(240, 230, 140) : elevation < 0.4f ? getLowlandsTerrainColor(moisture) : elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture) : @@ -397,7 +407,7 @@ sf::Color getTerrainColor(float elevation, float moisture) /// of the 4 adjacent neighbours. /// //////////////////////////////////////////////////////////// -sf::Vector2f computeNormal(int x, int y, float left, float right, float bottom, float top) +sf::Vector2f computeNormal(float left, float right, float bottom, float top) { sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor); sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor); @@ -438,9 +448,9 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem for (unsigned int y = rowStart; y < rowEnd; y++) { - for (int x = 0; x < resolutionX; x++) + for (unsigned int x = 0; x < resolutionX; x++) { - int arrayIndexBase = ((y - rowStart) * resolutionX + x) * 6; + unsigned int arrayIndexBase = ((y - rowStart) * resolutionX + x) * 6; // Top left corner (first triangle) if (x > 0) @@ -453,9 +463,9 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem } else { - vertices[arrayIndexBase + 0].position = sf::Vector2f(x * scalingFactorX, y * scalingFactorY); + vertices[arrayIndexBase + 0].position = sf::Vector2f(static_cast(x) * scalingFactorX, static_cast(y) * scalingFactorY); vertices[arrayIndexBase + 0].color = getTerrainColor(getElevation(x, y), getMoisture(x, y)); - vertices[arrayIndexBase + 0].texCoords = computeNormal(x, y, getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1)); + vertices[arrayIndexBase + 0].texCoords = computeNormal(getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1)); } // Bottom left corner (first triangle) @@ -465,15 +475,15 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem } else { - vertices[arrayIndexBase + 1].position = sf::Vector2f(x * scalingFactorX, (y + 1) * scalingFactorY); + vertices[arrayIndexBase + 1].position = sf::Vector2f(static_cast(x) * scalingFactorX, static_cast(y + 1) * scalingFactorY); vertices[arrayIndexBase + 1].color = getTerrainColor(getElevation(x, y + 1), getMoisture(x, y + 1)); - vertices[arrayIndexBase + 1].texCoords = computeNormal(x, y + 1, getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y)); + vertices[arrayIndexBase + 1].texCoords = computeNormal(getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y)); } // Bottom right corner (first triangle) - vertices[arrayIndexBase + 2].position = sf::Vector2f((x + 1) * scalingFactorX, (y + 1) * scalingFactorY); + vertices[arrayIndexBase + 2].position = sf::Vector2f(static_cast(x + 1) * scalingFactorX, static_cast(y + 1) * scalingFactorY); vertices[arrayIndexBase + 2].color = getTerrainColor(getElevation(x + 1, y + 1), getMoisture(x + 1, y + 1)); - vertices[arrayIndexBase + 2].texCoords = computeNormal(x + 1, y + 1, getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y)); + vertices[arrayIndexBase + 2].texCoords = computeNormal(getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y)); // Top left corner (second triangle) vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0]; @@ -488,9 +498,9 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem } else { - vertices[arrayIndexBase + 5].position = sf::Vector2f((x + 1) * scalingFactorX, y * scalingFactorY); + vertices[arrayIndexBase + 5].position = sf::Vector2f(static_cast(x + 1) * scalingFactorX, static_cast(y) * scalingFactorY); vertices[arrayIndexBase + 5].color = getTerrainColor(getElevation(x + 1, y), getMoisture(x + 1, y)); - vertices[arrayIndexBase + 5].texCoords = computeNormal(x + 1, y, getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1)); + vertices[arrayIndexBase + 5].texCoords = computeNormal(getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1)); } } } diff --git a/examples/joystick/Joystick.cpp b/examples/joystick/Joystick.cpp index 864ca057..d3a635ff 100644 --- a/examples/joystick/Joystick.cpp +++ b/examples/joystick/Joystick.cpp @@ -122,10 +122,10 @@ int main() { JoystickObject& object = texts[axislabels[i]]; - object.label.setPosition(5.f, 5.f + ((i + 4) * font.getLineSpacing(14))); + object.label.setPosition(5.f, 5.f + (static_cast(i + 4) * font.getLineSpacing(14))); object.label.setString(std::string(axislabels[i]) + ":"); - object.value.setPosition(80.f, 5.f + ((i + 4) * font.getLineSpacing(14))); + object.value.setPosition(80.f, 5.f + (static_cast(i + 4) * font.getLineSpacing(14))); object.value.setString("N/A"); } @@ -135,10 +135,10 @@ int main() sstr << "Button " << i; JoystickObject& object = texts[sstr.str()]; - object.label.setPosition(5.f, 5.f + ((sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))); + object.label.setPosition(5.f, 5.f + (static_cast(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))); object.label.setString(sstr.str() + ":"); - object.value.setPosition(80.f, 5.f + ((sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))); + object.value.setPosition(80.f, 5.f + (static_cast(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))); object.value.setString("N/A"); } diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt index d72a5ddd..fe71b784 100644 --- a/examples/opengl/CMakeLists.txt +++ b/examples/opengl/CMakeLists.txt @@ -17,3 +17,6 @@ sfml_add_example(opengl GUI_APP BUNDLE_RESOURCES ${RESOURCES} DEPENDS sfml-graphics RESOURCES_DIR resources) + +# external dependency headers +target_include_directories(opengl SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/examples/opengl) \ No newline at end of file diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 30a843f8..3f726fee 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -5,7 +5,7 @@ #include #define GLAD_GL_IMPLEMENTATION -#include "gl.h" +#include #ifdef SFML_SYSTEM_IOS #include @@ -100,12 +100,12 @@ int main() glDisable(GL_LIGHTING); // Configure the viewport (the same size as the window) - glViewport(0, 0, window.getSize().x, window.getSize().y); + glViewport(0, 0, static_cast(window.getSize().x), static_cast(window.getSize().y)); // Setup a perspective projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(window.getSize().x) / window.getSize().y; + GLfloat ratio = static_cast(window.getSize().x) / static_cast(window.getSize().y); #ifdef SFML_OPENGL_ES glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); #else @@ -237,22 +237,22 @@ int main() // Make the window the active window for OpenGL calls window.setActive(true); - glViewport(0, 0, event.size.width, event.size.height); + glViewport(0, 0, static_cast(event.size.width), static_cast(event.size.height)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(event.size.width) / event.size.height; + GLfloat newRatio = static_cast(event.size.width) / static_cast(event.size.height); #ifdef SFML_OPENGL_ES - glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustumf(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #else - glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustum(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #endif // Make the window no longer the active window for OpenGL calls window.setActive(false); sf::View view; - view.setSize(textureSize.x, textureSize.y); - view.setCenter(textureSize.x/2.f, textureSize.y/2.f); + view.setSize(sf::Vector2f(textureSize)); + view.setCenter(sf::Vector2f(textureSize) / 2.f); window.setView(view); } } @@ -277,8 +277,8 @@ int main() pos = sf::Mouse::getPosition(window); #endif - float x = pos.x * 200.f / window.getSize().x - 100.f; - float y = -pos.y * 200.f / window.getSize().y + 100.f; + float x = static_cast(pos.x) * 200.f / static_cast(window.getSize().x) - 100.f; + float y = -static_cast(pos.y) * 200.f / static_cast(window.getSize().y) + 100.f; // Apply some transformations glMatrixMode(GL_MODELVIEW); diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index ed75416a..3e885fd3 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -139,9 +139,9 @@ public: { float x = static_cast(std::rand() % 800); float y = static_cast(std::rand() % 600); - sf::Uint8 r = std::rand() % 255; - sf::Uint8 g = std::rand() % 255; - sf::Uint8 b = std::rand() % 255; + sf::Uint8 r = static_cast(std::rand() % 255); + sf::Uint8 g = static_cast(std::rand() % 255); + sf::Uint8 b = static_cast(std::rand() % 255); m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b))); } @@ -228,8 +228,8 @@ public: for (std::size_t i = 0; i < m_entities.size(); ++i) { sf::Vector2f position; - position.x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350; - position.y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250; + position.x = std::cos(0.25f * (time * static_cast(i + (m_entities.size() - i)))) * 300 + 350; + position.y = std::sin(0.25f * (time * static_cast((m_entities.size() - i) + i))) * 200 + 250; m_entities[i].setPosition(position); } @@ -282,8 +282,8 @@ public: { // Spread the coordinates from -480 to +480 // So they'll always fill the viewport at 800x600 - m_pointCloud[i].position.x = rand() % 960 - 480.f; - m_pointCloud[i].position.y = rand() % 960 - 480.f; + m_pointCloud[i].position.x = static_cast(rand() % 960) - 480.f; + m_pointCloud[i].position.y = static_cast(rand() % 960) - 480.f; } // Load the texture @@ -301,7 +301,7 @@ public: return true; } - void onUpdate(float time, float x, float y) + void onUpdate(float /*time*/, float x, float y) { // Reset our transformation matrix m_transform = sf::Transform::Identity; @@ -433,8 +433,8 @@ int main() } // Update the current example - float x = static_cast(sf::Mouse::getPosition(window).x) / window.getSize().x; - float y = static_cast(sf::Mouse::getPosition(window).y) / window.getSize().y; + float x = static_cast(sf::Mouse::getPosition(window).x) / static_cast(window.getSize().x); + float y = static_cast(sf::Mouse::getPosition(window).y) / static_cast(window.getSize().y); effects[current]->update(clock.getElapsedTime().asSeconds(), x, y); // Clear the window diff --git a/examples/tennis/Tennis.cpp b/examples/tennis/Tennis.cpp index 734098f3..ca4e2847 100644 --- a/examples/tennis/Tennis.cpp +++ b/examples/tennis/Tennis.cpp @@ -142,7 +142,7 @@ int main() do { // Make sure the ball initial angle is not too much vertical - ballAngle = (std::rand() % 360) * 2 * pi / 360; + ballAngle = static_cast(std::rand() % 360) * 2 * pi / 360; } while (std::abs(std::cos(ballAngle)) < 0.7f); } @@ -242,9 +242,9 @@ int main() ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2) { if (ball.getPosition().y > leftPaddle.getPosition().y) - ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180; + ballAngle = pi - ballAngle + static_cast(std::rand() % 20) * pi / 180; else - ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180; + ballAngle = pi - ballAngle - static_cast(std::rand() % 20) * pi / 180; ballSound.play(); ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y); @@ -257,9 +257,9 @@ int main() ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2) { if (ball.getPosition().y > rightPaddle.getPosition().y) - ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180; + ballAngle = pi - ballAngle + static_cast(std::rand() % 20) * pi / 180; else - ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180; + ballAngle = pi - ballAngle - static_cast(std::rand() % 20) * pi / 180; ballSound.play(); ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y); diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 9c705539..e0e1ee45 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -84,7 +84,7 @@ private: // (don't forget that we run in two separate threads) { sf::Lock lock(m_mutex); - m_tempBuffer.assign(m_samples.begin() + m_offset, m_samples.end()); + m_tempBuffer.assign(m_samples.begin() + static_cast::difference_type>(m_offset), m_samples.end()); } // Fill audio data to pass to the stream @@ -103,7 +103,7 @@ private: //////////////////////////////////////////////////////////// virtual void onSeek(sf::Time timeOffset) { - m_offset = timeOffset.asMilliseconds() * getSampleRate() * getChannelCount() / 1000; + m_offset = static_cast(timeOffset.asMilliseconds()) * getSampleRate() * getChannelCount() / 1000; } //////////////////////////////////////////////////////////// diff --git a/examples/vulkan/CMakeLists.txt b/examples/vulkan/CMakeLists.txt index 368cb8f7..e35c091d 100644 --- a/examples/vulkan/CMakeLists.txt +++ b/examples/vulkan/CMakeLists.txt @@ -9,3 +9,6 @@ sfml_add_example(vulkan GUI_APP SOURCES ${SRC} DEPENDS sfml-graphics RESOURCES_DIR resources) + +# external dependency headers +target_include_directories(vulkan SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/examples/vulkan) \ No newline at end of file diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 01c58edd..72ad3df5 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -3,7 +3,7 @@ // Headers //////////////////////////////////////////////////////////// #define GLAD_VULKAN_IMPLEMENTATION -#include "vulkan.h" +#include // Include graphics because we use sf::Image for loading images #include @@ -162,7 +162,7 @@ namespace // Helper function we pass to GLAD to load Vulkan functions via SFML GLADapiproc getVulkanFunction(const char* name) { - return reinterpret_cast(sf::Vulkan::getFunction(name)); + return sf::Vulkan::getFunction(name); } // Debug we pass to Vulkan to call when it detects warnings or errors @@ -341,7 +341,7 @@ public: vkWaitForFences(device, 1, &fences[i], VK_TRUE, std::numeric_limits::max()); if (commandBuffers.size()) - vkFreeCommandBuffers(device, commandPool, commandBuffers.size(), &commandBuffers[0]); + vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), &commandBuffers[0]); commandBuffers.clear(); @@ -472,9 +472,9 @@ public: VkInstanceCreateInfo instanceCreateInfo = VkInstanceCreateInfo(); instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instanceCreateInfo.pApplicationInfo = &applicationInfo; - instanceCreateInfo.enabledLayerCount = validationLayers.size(); + instanceCreateInfo.enabledLayerCount = static_cast(validationLayers.size()); instanceCreateInfo.ppEnabledLayerNames = &validationLayers[0]; - instanceCreateInfo.enabledExtensionCount = requiredExtentions.size(); + instanceCreateInfo.enabledExtensionCount = static_cast(requiredExtentions.size()); instanceCreateInfo.ppEnabledExtensionNames = &requiredExtentions[0]; // Try to create a Vulkan instance with debug report enabled @@ -485,7 +485,7 @@ public: { requiredExtentions.pop_back(); - instanceCreateInfo.enabledExtensionCount = requiredExtentions.size(); + instanceCreateInfo.enabledExtensionCount = static_cast(requiredExtentions.size()); instanceCreateInfo.ppEnabledExtensionNames = &requiredExtentions[0]; result = vkCreateInstance(&instanceCreateInfo, 0, &instance); @@ -665,11 +665,11 @@ public: { VkBool32 surfaceSupported = VK_FALSE; - vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, &surfaceSupported); + vkGetPhysicalDeviceSurfaceSupportKHR(gpu, static_cast(i), surface, &surfaceSupported); if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE)) { - queueFamilyIndex = i; + queueFamilyIndex = static_cast(i); break; } } @@ -685,7 +685,7 @@ public: VkDeviceQueueCreateInfo deviceQueueCreateInfo = VkDeviceQueueCreateInfo(); deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; deviceQueueCreateInfo.queueCount = 1; - deviceQueueCreateInfo.queueFamilyIndex = queueFamilyIndex; + deviceQueueCreateInfo.queueFamilyIndex = static_cast(queueFamilyIndex); deviceQueueCreateInfo.pQueuePriorities = &queuePriority; // Enable the swapchain extension @@ -711,7 +711,7 @@ public: } // Retrieve a handle to the logical device command queue - vkGetDeviceQueue(device, queueFamilyIndex, 0, &queue); + vkGetDeviceQueue(device, static_cast(queueFamilyIndex), 0, &queue); } // Query surface formats and set up swapchain @@ -1240,7 +1240,7 @@ public: // We want to be able to reset command buffers after submitting them VkCommandPoolCreateInfo commandPoolCreateInfo = VkCommandPoolCreateInfo(); commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - commandPoolCreateInfo.queueFamilyIndex = queueFamilyIndex; + commandPoolCreateInfo.queueFamilyIndex = static_cast(queueFamilyIndex); commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // Create our command pool @@ -1777,7 +1777,7 @@ public: } // Copy the image data into the buffer - std::memcpy(ptr, imageData.getPixelsPtr(), static_cast(imageSize)); + std::memcpy(ptr, imageData.getPixelsPtr(), imageSize); // Unmap the buffer vkUnmapMemory(device, stagingBufferMemory); @@ -2266,7 +2266,7 @@ public: semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; // Create a semaphore to track when an swapchain image is available for each frame in flight - for (int i = 0; i < maxFramesInFlight; i++) + for (std::size_t i = 0; i < maxFramesInFlight; i++) { imageAvailableSemaphores.push_back(0); @@ -2279,7 +2279,7 @@ public: } // Create a semaphore to track when rendering is complete for each frame in flight - for (int i = 0; i < maxFramesInFlight; i++) + for (std::size_t i = 0; i < maxFramesInFlight; i++) { renderFinishedSemaphores.push_back(0); @@ -2301,7 +2301,7 @@ public: fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; // Create a fence to track when queue submission is complete for each frame in flight - for (int i = 0; i < maxFramesInFlight; i++) + for (std::size_t i = 0; i < maxFramesInFlight; i++) { fences.push_back(0); @@ -2321,10 +2321,10 @@ public: // Construct the model matrix Matrix model = { - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f } }; matrixRotateX(model, elapsed * 59.0f * pi / 180.f); @@ -2332,8 +2332,10 @@ public: matrixRotateZ(model, elapsed * 109.0f * pi / 180.f); // Translate the model based on the mouse position - float x = clamp( sf::Mouse::getPosition(window).x * 2.f / window.getSize().x - 1.f, -1.0f, 1.0f) * 2.0f; - float y = clamp(-sf::Mouse::getPosition(window).y * 2.f / window.getSize().y + 1.f, -1.0f, 1.0f) * 1.5f; + sf::Vector2f mousePosition = sf::Vector2f(sf::Mouse::getPosition(window)); + sf::Vector2f windowSize = sf::Vector2f(window.getSize()); + float x = clamp( mousePosition.x * 2.f / windowSize.x - 1.f, -1.0f, 1.0f) * 2.0f; + float y = clamp(-mousePosition.y * 2.f / windowSize.y + 1.f, -1.0f, 1.0f) * 1.5f; model[3][0] -= x; model[3][2] += y; @@ -2493,8 +2495,8 @@ private: bool vulkanAvailable; - const int maxFramesInFlight; - int currentFrame; + const unsigned int maxFramesInFlight; + unsigned int currentFrame; bool swapchainOutOfDate; VkInstance instance; diff --git a/examples/window/CMakeLists.txt b/examples/window/CMakeLists.txt index f4ee1d13..ccb1d6c5 100644 --- a/examples/window/CMakeLists.txt +++ b/examples/window/CMakeLists.txt @@ -8,3 +8,6 @@ set(SRC ${SRCROOT}/Window.cpp) sfml_add_example(window GUI_APP SOURCES ${SRC} DEPENDS sfml-window) + +# external dependency headers +target_include_directories(window SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/examples/window) \ No newline at end of file diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index db7b0687..7bdaa399 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -4,7 +4,7 @@ #include #define GLAD_GL_IMPLEMENTATION -#include "gl.h" +#include #ifdef SFML_SYSTEM_IOS #include @@ -52,12 +52,12 @@ int main() glDisable(GL_TEXTURE_2D); // Configure the viewport (the same size as the window) - glViewport(0, 0, window.getSize().x, window.getSize().y); + glViewport(0, 0, static_cast(window.getSize().x), static_cast(window.getSize().y)); // Setup a perspective projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(window.getSize().x) / window.getSize().y; + GLfloat ratio = static_cast(window.getSize().x) / static_cast(window.getSize().y); #ifdef SFML_OPENGL_ES glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); #else @@ -142,14 +142,14 @@ int main() // Resize event: adjust the viewport if (event.type == sf::Event::Resized) { - glViewport(0, 0, event.size.width, event.size.height); + glViewport(0, 0, static_cast(event.size.width), static_cast(event.size.height)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(event.size.width) / event.size.height; + GLfloat newRatio = static_cast(event.size.width) / static_cast(event.size.height); #ifdef SFML_OPENGL_ES - glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustumf(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #else - glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustum(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #endif } }