If you're inside the event loop you shouldn't directly call sf::Keyboard::isKeyPressed but use events instead.
Real-time input and events are two different systems and should mostly kept separated...
Global variables are never suggested, even for testing.
So your code should look more like this:
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
// Setup SFML.
sf::RenderWindow renderer;
renderer.create(sf::VideoMode(800, 600, 32), "Example Title");
renderer.setVerticalSyncEnabled(true);
sf::View view;
view = renderer.getDefaultView();
renderer.setView(view);
sf::Sprite player, background;
sf::Texture playerTex, backgroundTex;
unsigned int fps = 0;
sf::Clock fpsClock;
// Load stuff.
playerTex.loadFromFile("player.png");
player.setTexture(playerTex);
backgroundTex.loadFromFile("background.png");
background.setTexture(backgroundTex);
while(renderer.isOpen())
{
/* Logic */
// Input
sf::Event event;
while(renderer.pollEvent(event))
{
if((event.type == sf::Event::Closed))
renderer.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::C) && sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
renderer.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
player.setPosition(player.getPosition().x - 10, player.getPosition().y);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
player.setPosition(player.getPosition().x + 10, player.getPosition().y);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
player.setPosition(player.getPosition().x, player.getPosition().y - 10);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
player.setPosition(player.getPosition().x, player.getPosition().y + 10);
// Re-center the view on the player.
view.setCenter(player.getPosition().x, player.getPosition().y);
renderer.setView(view);
/* Rendering */
renderer.clear();
renderer.draw(background);
renderer.draw(player);
// Render the frame.
renderer.display();
if(fpsClock.getElapsedTime().asMilliseconds() > 1000)
{
std::cout << "FPS: " << fps << std::endl;
fps = 0;
fpsClock.restart();
}
else
fps++;
}
return 0;
}
I don't see any kind of tearing...
http://www.youtube.com/watch?v=n5GipBgpgx4The rendering is okay, so I'm not sure what's going on here. Since it's Linux, I'd guess some driver issues...