Hi, not sure I'm at the right place ! I wrote the following code that should draw a line in the middle of the window. But the line is not always in the middle, sometime yes, sometine shifted to the right. I tried two different computers, but the problem appeared on both. Same problem also appeared with sprites. I'm working with Ubuntu 16.04, I compiled with Qt and SFML 2.3.2 (Ubuntu 16.04 repository). I really hope I made something wrong, and this problem is not a SFML bug. Here is my source code:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
// _____________________
// ::: Create window :::
// Create a window with the same pixel depth as the desktop
sf::VideoMode desktopMode = sf::VideoMode::getDesktopMode();
sf::RenderWindow window(sf::VideoMode( desktopMode.width,
desktopMode.height,
desktopMode.bitsPerPixel),
"SFML part 3",
sf::Style::Fullscreen);
// Enable vertical sync. (vsync)
window.setVerticalSyncEnabled (true);
sf::Vertex line[] =
{
sf::Vertex(sf::Vector2f(desktopMode.width/2, 0)),
sf::Vertex(sf::Vector2f(desktopMode.width/2, desktopMode.height))
};
// _________________
// ::: Main loop :::
sf::Clock timer;
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close the window if a key is pressed or if requested
if (event.type == sf::Event::Closed) window.close();
if (event.type == sf::Event::KeyPressed) window.close();
}
// Clear the window and apply grey background
window.clear( sf::Color(127,127,127));
window.draw(line, 2, sf::Lines);
// Update display and wait for vsync
window.display();
}
return 0;
}
Let say dozen of pixels. I investigated to understand. The problem comes from the window size. I added the following lines in my code :
std::cout << "desktopMode = \t" << desktopMode.width << "x" << desktopMode.height << " px" << std::endl;
std::cout << "window.getSize = \t" << window.getSize().x << "x" << window.getSize().y << " px" << std::endl;
Same code executed twice provides the following output (remember I'm working in full screen).
Starting /home/philippe/sources/sfml_tutorial/part_003/bin/part_003...
desktopMode = 1920x1080 px
window.getSize = 1855x1056 px
/home/philippe/sources/sfml_tutorial/part_003/bin/part_003 exited with code 0
Starting /home/philippe/sources/sfml_tutorial/part_003/bin/part_003...
desktopMode = 1920x1080 px
window.getSize = 1920x1080 px
/home/philippe/sources/sfml_tutorial/part_003/bin/part_003 exited with code 0
Hum hum ... strange ... Any idea ?
Argh ... can't compile with sfml 2.4.1 :
g++ main.o -o sfml-app -L/home/philippe/SFML-2.4.1/lib -lsfml-graphics -lsfml-window -lsfml-system
main.o: In function `main':
main.cpp:(.text+0x18c): undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'
collect2: error: ld returned 1 exit status
Can't figure out why loadFromFile is not linked. A conflict with the already installed SFML 2.3.2 ?