Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw at wrong position  (Read 3341 times)

0 Members and 1 Guest are viewing this topic.

cinqlair

  • Newbie
  • *
  • Posts: 5
    • View Profile
Draw at wrong position
« on: December 18, 2016, 07:08:04 pm »
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;
}


 
« Last Edit: December 18, 2016, 07:21:40 pm by cinqlair »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Draw at wrong position
« Reply #1 on: December 18, 2016, 07:30:24 pm »
Shifted to the right how exactly?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cinqlair

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Draw at wrong position
« Reply #2 on: December 18, 2016, 07:42:20 pm »
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 ?
« Last Edit: December 18, 2016, 07:45:28 pm by cinqlair »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Draw at wrong position
« Reply #3 on: December 18, 2016, 08:20:03 pm »
Try SFML 2.4.1, we've fixed at least one bug in that direction.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cinqlair

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Draw at wrong position
« Reply #4 on: December 18, 2016, 10:36:05 pm »
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 ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Draw at wrong position
« Reply #5 on: December 19, 2016, 01:47:50 am »
Maybe you need to build SFML with the C++11 flag.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cinqlair

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Draw at wrong position
« Reply #6 on: December 19, 2016, 08:34:43 am »
Maybe we should remove the S at the beginning of SFML  ;)

Anyway, thank you very much for your quick and relevant answers.
« Last Edit: December 19, 2016, 08:36:44 am by cinqlair »

K.F

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: Draw at wrong position
« Reply #7 on: December 19, 2016, 02:47:28 pm »
Maybe we should remove the S at the beginning of SFML  ;)

Unfortunately, this library is aimed at programmers. :p

There are already compiled binaries if you can't build it yourself:

http://www.sfml-dev.org/download/sfml/2.4.1/
« Last Edit: December 19, 2016, 02:49:43 pm by K.F »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Re: Draw at wrong position
« Reply #8 on: December 19, 2016, 04:49:14 pm »
Compiled binaries if you can't build it yourself:

http://www.sfml-dev.org/download/sfml/2.4.1/
Then again, we don't recommend using pre-compiled binaries for Linux systems, since the dependencies can vary. But you're right that being able to build a library is part of being a (C++) programmer. If you craft anything, you'll also have to know, how to use your tools, the same applies to programming. Know what a compiler and linker do and how they work. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cinqlair

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Draw at wrong position
« Reply #9 on: December 21, 2016, 09:35:29 pm »
Thank you for your replies. I already tried the binaries from http://www.sfml-dev.org/download/sfml/2.4.1/. Unfortunately, it didn't work. I have been able to compile the green circle example linked with SFML2.4.1, but the application crashed when launched. I think it is a problem with dependencies.

Yes, of course, I can compile SFML from the source codes (for those who tease me about my programming skills, have a look at my most significant accomplishments : http://5lair.free.fr or www.lucidarme.me ;-) ). I try to keep my development computer clean and avoid installing too much packages. SFML needs a lot of dependencies. I'll do it after the holidays on another computer.

By the way, maybe the binaries v2.4.1 for Ubuntu 16.04 may interrest other developers ? How to share ? I'm also thinking in contributing in the dev : in my opinion, multi-display support is a severe lack in SFML ... I think this missing functionality prevent the development of professional apps.