Hello SFML community,
I've had an annoying bug in my program since I began it months ago. So, my program randomly "stutters", below is a video demonstrating what I mean:
http://streamable.com/9ajq63
Here is my source code, that validates the issue:
#include <SFML/Graphics.hpp>
// This is for multi-graphics cards in a laptop, bug happens with or without this
#ifdef _WIN32
extern "C" {
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
__declspec(
dllexport) unsigned int AmdPowerXpressRequestHighPerformance = 0x1;
}
#endif
int main () {
sf::ContextSettings settings;
settings.antialiasingLevel = 0;
sf::RenderWindow renderWindow(
{ 2560, 1440 },
"FunTitleForForum",
sf::Style::Default,
settings
);
renderWindow.setVerticalSyncEnabled( true );
sf::Texture textureTEMP;
textureTEMP.loadFromFile("../Source/TextureManager/TileMap/atlas_48x.png" );
sf::Sprite spriteTEMP { textureTEMP };
sf::View gameView;
gameView.setSize( renderWindow.getDefaultView().getSize());
renderWindow.setView( gameView );
sf::Event event {};
while ( renderWindow.isOpen()) {
while ( renderWindow.pollEvent( event )) {
if ( event.type == sf::Event::Closed ) {
renderWindow.close();
}
}
if ( sf::Keyboard::isKeyPressed( sf::Keyboard::D )) {
gameView.move( 10, 0 );
} else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::A )) {
gameView.move( -10, 0 );
}
renderWindow.clear();
renderWindow.setView( gameView );
renderWindow.draw( spriteTEMP );
renderWindow.display();
}
return 0;
}
Here is what I have tried (not in any order):
Set all textures to smooth
Implement timestep manually
Use kairos timestep library
Making sure compiler version and sfml version match
Rebuilding sfml
Statically linking sfml instead of dynamically linking
One note is that I have a 144hz screen output, and if you need any more additional info please let me know!
Hello everyone,
I'm struggling exactly with the same issue, and for very basic lines of code. This draws a rectangle with a rectilinear uniform trajectory (analytical position based on the current frametime).
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(1600, 900), "SFML works!");
sf::Clock globalClock;
sf::RectangleShape rectangle({100, 100});
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
rectangle.setPosition(globalClock.getElapsedTime().asSeconds()*sf::Vector2f(600,300));
window.clear();
window.draw(rectangle);
window.display();
}
return 0;
}
I won't post any video or gif but it's exactly like what you see in these links :
https://en.sfml-dev.org/forums/index.php?topic=16449.0 (https://en.sfml-dev.org/forums/index.php?topic=16449.0)
http://streamable.com/9ajq63 (http://streamable.com/9ajq63)
Enabling/disabling vertical sync or setting a frame limit doesn't solve the problem.
My config is :
OS Name : Ubuntu 20.04.4 LTS
OS Type : 64 bit
GNOME Version : 3.36.8
Windowing System : X11
Processor : Intel® Core™ i9-9880H CPU @ 2.30GHz × 16
Gaphics : NVIDIA Corporation TU117GLM [Quadro T2000 Mobile / Max-Q]
I've read on different posts that it could be due to threaded optimization of Nvidia, but it seems it is off by default on Linux. At least there is no direct access to this option for all applications in NVIDIA X SERVER Settings, but if I try to set an application profile for my game I can see there is a boolean GLTHREADEDOPTIMIZATIONS and its value is false by default...
I really don't know what to do and any help would be useful :)
Thank you!