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

Author Topic: Screen has no synchronization.  (Read 2151 times)

0 Members and 1 Guest are viewing this topic.

Pixel_Outlaw

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Screen has no synchronization.
« on: January 14, 2011, 03:50:25 am »
What is the proper way to set the refresh rate to 60 frames per second and also ensure there is no screen tearing? I seem to recall the two functions "don't get along".

This is the problem:
http://img834.imageshack.us/img834/7626/screenshotsu.png

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Screen has no synchronization.
« Reply #1 on: January 14, 2011, 05:34:14 am »
Could you post a complete and minimal example that produces the problem, please?

Pixel_Outlaw

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Screen has no synchronization.
« Reply #2 on: January 14, 2011, 06:03:27 am »
Certainly, I don't know what I was thinking not posting code too.

Code: [Select]


#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600),"nothing");
    App.SetFramerateLimit(60);

// Start the game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            if (Event.Type == sf::Event::MouseMoved)
                App.Close();

            if (Event.Type == sf::Event::KeyPressed)
                App.Close();

        }

        // Clear screen
        App.Clear();

        // Draw the sprite
        for(int i = 0; i < 100; i++)
        {
            sf::Shape new_shape = sf::Shape::Circle(rand() % 800, rand() % 600, rand() % 32 + 32,sf::Color(rand() % 255, rand() % 255, rand() % 255, 128));

            if(rand() % 2)
            {
                new_shape.SetBlendMode(sf::Blend::Add);
            }

            App.Draw(new_shape);
        }
        // Update the window
        App.Display();
    }

    return EXIT_SUCCESS;
}


I was told earlier that SetFramerateLimit() should not be used with UseVerticalSync(). Ideally I want my game to both render at 60 frames per second and also not tear the screen because verticle synching is not enabled. I want the events in the game to be locked into cycles rather than time so even when frame rate changes from machine to machine game events will be on a per frame update basis.

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
Screen has no synchronization.
« Reply #3 on: January 17, 2011, 09:18:46 am »
Either introdice a pause of ~16ms each loop (gets ~62-63FPS on a good computer), or the best way, even if you don't want to, is to use VerticalSync WITHOUT setting a framerate limit. This is provided as a method of synchronising the frame rate and monitor's refresh rate. This WILL reduce tearing, and looks like your best option. Sorry if that's not what you wanted to hear :?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Screen has no synchronization.
« Reply #4 on: January 17, 2011, 11:36:19 am »
Using Vertical sync will force the application to run at the same frequency of the display(For most it is 60FPS and some 50FPS) so if you set vertical sync you will run at MAX that frequency. Why do you care about what frequency it is really? If you do it right you should work with delta time.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything