Skip to content

Instantly share code, notes, and snippets.

@tomgalvin594
Last active August 29, 2015 14:11
Show Gist options
  • Save tomgalvin594/ab67b962cf10c809cb68 to your computer and use it in GitHub Desktop.
Save tomgalvin594/ab67b962cf10c809cb68 to your computer and use it in GitHub Desktop.
Retina Display Issue with SFML on OS X 10.9
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
int main()
{
// Create the window
sf::RenderWindow window(sf::VideoMode(640, 480), "Demo App", sf::Style::Titlebar | sf::Style::Close | sf::Style::Resize);
// Create a simple shape
sf::RectangleShape rectangle(sf::Vector2f(640,480));
rectangle.setFillColor(sf::Color::Red); // You will see red if the shader doesn't work
// Load the shader
sf::Shader shader;
shader.loadFromFile("shader.frag", sf::Shader::Fragment);
shader.setParameter("window_width", 640.f);
shader.setParameter("window_height", 480.f);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::KeyPressed) {
switch(event.key.code) {
case sf::Keyboard::Escape:
window.close();
default:
break;
}
}
if (event.type == sf::Event::Resized)
{
shader.setParameter("window_width", event.size.width);
shader.setParameter("window_height", event.size.height);
}
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(rectangle, &shader);
window.display();
}
return 0;
}
uniform float window_width;
uniform float window_height;
void main()
{
// Calculate the normalized position on the screen.
// (0,0) is bottom left
// (1,1) is top right
vec2 pos = vec2(gl_FragCoord.x / window_width, gl_FragCoord.y / window_height);
// Map the red component to the x value and the green component to the y value
gl_FragColor = vec4(pos.x, pos.y, 0.0, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment