DelinWorks / Rebound

Rebound is a 2D Platformer Game in C++ || Has a featureful editor! allows anyone to create levels and share them online! devbuild available!
5 stars 0 forks source link

FPS above 60 #3

Closed johnspeny closed 1 year ago

johnspeny commented 1 year ago

I appreciate your effort, this not really an issue just a question on FPS. I am not advanced yet in graphics programming but on the route to it. I have never gotten beyond 60 FPS on axmole. I see with this demo its possible how is that?. A brief answer is okay.

DelinWorks commented 1 year ago

Thanks for asking! You can use the setAnimationInterval function, this function takes a frametime value, so If you want to have 120 fps then you have to pass a float fraction of 1.0 / 120.0 and that will make the game render at that framerate.

// this will render the game at 30 fps, cool for cinematic experiences
Director::getInstance()->setAnimationInterval(1.0f / 30);

For desktop computers (Windows, linux) If you don't know the refresh rate of the GPU the user is running you can get that value using glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate This will give you the speed at which the GPU updates the monitor NOT the monitor's hertz.

This is good for limiting the framerate but causes stuttering because a 144hz display on a 144fps can cause stuttering and horizontal lines because there is no vertical sync. To enable VSYNC you can tell glfw to do so by calling glfwSwapInterval(1); this will enable VSYNC and the display won't have jittery lines (It would also cap the framerate to the GPU's refresh rate) and glfwSwapInterval(0); to turn off VSYNC.

for mobile phones that support 120fps you unfortunately can't get the information about update rate, but you can run the game at 120fps in mobile devices by just setting the interval to 0.

// The phone's OS will cap the fps by the displays refresh rate so setting this value to 0
// will tell the OS to update the context as fast as the display of the phone can go.
// or what the user has set the refresh rate of the phone in the settings.
Director::getInstance()->setAnimationInterval(0);

Hope that helps <3 Feel free to ask!

aismann commented 1 year ago

@DelinWorks Maybe a Q&A for axmol?