Update examples for iOS including touch support, proper handling of window resize, launch screens and icons

This commit is contained in:
Jonny Paton 2019-01-18 15:04:03 +00:00 committed by Lukas Dürrenberger
parent 9f4a0c3c4f
commit 353c846c87
12 changed files with 141 additions and 9 deletions

View file

@ -220,13 +220,24 @@ int main()
// Adjust the viewport when the window is resized
if (event.type == sf::Event::Resized)
{
sf::Vector2u textureSize = backgroundTexture.getSize();
// Make the window the active window for OpenGL calls
window.setActive(true);
glViewport(0, 0, event.size.width, event.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat ratio = static_cast<float>(event.size.width) / event.size.height;
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
// 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);
window.setView(view);
}
}
@ -241,9 +252,17 @@ int main()
// Clear the depth buffer
glClear(GL_DEPTH_BUFFER_BIT);
// We get the position of the mouse cursor, so that we can move the box accordingly
float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
// We get the position of the mouse cursor (or touch), so that we can move the box accordingly
sf::Vector2i pos;
#ifdef SFML_SYSTEM_IOS
pos = sf::Touch::getPosition(0);
#else
pos = sf::Mouse::getPosition();
#endif
float x = pos.x * 200.f / window.getSize().x - 100.f;
float y = -pos.y * 200.f / window.getSize().y + 100.f;
// Apply some transformations
glMatrixMode(GL_MODELVIEW);