Giter Site home page Giter Site logo

144hz and VSync about tilengine HOT 5 OPEN

megamarc avatar megamarc commented on September 1, 2024
144hz and VSync

from tilengine.

Comments (5)

megamarc avatar megamarc commented on September 1, 2024

Hi!
By default TLN_CreateWindow() sets vsync flag. If it's not working for you, you should modify Window.c and remove CWF_VSYNC from line 426:
https://github.com/megamarc/Tilengine/blob/master/src/Window.c#L426

Then you'll have to do frame throttling on your game loop to adjust to your target frame rate, for example using SDL_Delay() + SDL_GetTicks() if you're using libSDL.

from tilengine.

turric4n avatar turric4n commented on September 1, 2024

Thanks Marc,

Please take a look here :

https://stackoverflow.com/questions/40854974/sdl-opengl-game-runs-too-fast-on-144hz-screen-cant-use-vsync

Today 144hz screens are common things under gaming scene, so, ther is my two cents :

  • Why VSync is not working? It's quite strange.
  • That code will do the job?
int32_t tickInteval = 1000/FPS; // frequency in Hz to period in ms
uint32_t lastUpdateTime = 0;
int32_t deltaTime = 0;
while (running) { // running condition
    uint32_t currentTime = SDL_GetTicks();
    deltaTime = currentTime - lastUpdateTime;

    int32_t timeToSleep = tickInteval - deltaTime;
    if(timeToSleep > 0)
    {
        SDL_Delay(timeToSleep); // energy saving
    }

    update(deltaTime); // game logic
    lastUpdateTime = currentTime;
}


from tilengine.

megamarc avatar megamarc commented on September 1, 2024

Hi again,
Your frame throttling should work, the basic idea is measuring the time it takes to process one frame (game logic, render, etc) and delay/sleep until the time to next frame at your target FPS.
Why is vsync not working for you? I don't know as I don't have such 144 Hz monitor, mine is standard 60 Hz. But I guess is more related to G-sync and adaptive refresh rates than to a fixed 60/144 Hz issue. SDL2 just asks the underlying graphics API to enable vsync, but it's ultimately graphics driver and hardware to do the job.

from tilengine.

turric4n avatar turric4n commented on September 1, 2024

Hi again,
Your frame throttling should work, the basic idea is measuring the time it takes to process one frame (game logic, render, etc) and delay/sleep until the time to next frame at your target FPS.
Why is vsync not working for you? I don't know as I don't have such 144 Hz monitor, mine is standard 60 Hz. But I guess is more related to G-sync and adaptive refresh rates than to a fixed 60/144 Hz issue. SDL2 just asks the underlying graphics API to enable vsync, but it's ultimately graphics driver and hardware to do the job.

Thanks Mark, I will take a look over Nvidia low level things like GSync and how affect to SDL2 Window handling.

Because Tilengine demos are affected too, we need to think about maintaining compatibility with more screen refresh frequencies before making serious projects.

Greetings

from tilengine.

megamarc avatar megamarc commented on September 1, 2024

Maybe this article on how SDL2 handles adaptive sync may help:
https://wiki.libsdl.org/SDL_GL_SetSwapInterval
However this is not a tilengine issue, but a general windowing/vsync one on modern monitors.

from tilengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.