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