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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Kondie

Pages: [1]
1
SFML website / IRC Seems to be Down?
« on: October 29, 2018, 04:18:16 am »
https://chat.sfml-dev.org/

This is the link to the IRC given here: https://www.sfml-dev.org/community.php

Doesn't seem to be working currently, and just shows a default web page.

2
General / Re: Image of Sprite Skipping on Screen
« on: February 24, 2018, 05:51:38 am »
Actually Fallahn helped me with a little shader, and it looks like scrolling the texture in OpenGL still had issues. Extremely odd. It definitely performed better in more cases, but still wasn't stopping the jittering.

Overall, what I found was that certain video mode settings helped. For example, restricting the window to v-sync while in fullscreen mode stopped the jittering. And setting the framerate to that of my monitor while in windowed helped as well. The best performance was achieved in fullscreen v-sync with no noticeable jittering after playing around in it for quite some time. Disabling threaded optimization was also a necessity to entirely preventing this skipping for me. Note that this was all after interpolation was added as well, as without it, I did notice that the jittering would happen.

Hope this helps anyone who comes across this issue in the future. In the end I was still able to go with SFML, and I highly recommend it. Some of the best documentation, cleanest code, and most helpful forums I've seen out there. :)

Update: 10/27/2018

An update many months in advance for anybody who comes across this issue in the future, this video here was very helpful:

To summarize, it looks like this is just a problem with dual monitor setups where the refresh rate is greater than 60 hz in Windows 10 (or Windows 7 with Aero). As I've gotten further into my engine, I decided to spend some time researching this topic in hopes that I would find a solution, but I have not. Fullscreen definitely seems to lessen the issue significantly, and sometimes the disabling multi-threading as mentioned in here helped as well. But completely getting rid of the jittering doesn't seem to be possible in this kind of setup. Still works perfectly fine on my laptop @ 60 hz though.

3
General / Re: Image of Sprite Skipping on Screen
« on: February 18, 2018, 12:27:27 am »
After a few hours of troubleshooting in IRC it seems that this issue is with setTextureRect on some Nvidia cards (1060, 1070, and MX150 confirmed). The code works fine on many other machines. I'll be taking fallahn's suggestion, and implementing a scrolling background through OpenGL shaders, but I do believe the setTextureRect issue should be looked into.

@Hapax to clarify, interpolation only solved the jumps in some cases. Switching to fullscreen with interpolation caused them to return.

4
General / Re: Image of Sprite Skipping on Screen
« on: February 17, 2018, 08:17:48 pm »
So, one thing to comment about your statement there about int vs float is that the jittering isn't just the background jumping forward. If you look at the gif, it literally moves 1 step back, then 2 steps forward. I had a statement implemented to tell me if the previous position was ever less than the current, and it only triggered when the modulus operator set in.

Regardless, I took your advice and implemented the scrolling background into a quad. It exhibits the exact same jittering behavior as before. Here is the code that I made:

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML");

   //window.setVerticalSyncEnabled(true);
   window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("tileable_space.jpg"))
      exit(1);
   background.setRepeated(true);

   sf::VertexArray quad(sf::Quads, 4);
   
   // Defining the 4 points on the screen
   quad[0].position = sf::Vector2f(0, 0);
   quad[1].position = sf::Vector2f(window.getSize().x, 0);
   quad[2].position = sf::Vector2f(window.getSize().x, window.getSize().y);
   quad[3].position = sf::Vector2f(0, window.getSize().y);

   sf::Clock clock;

   float xspeed = 0, yspeed = 0;

   const int TICKS_PER_SECOND = 50;
   const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
   const int MAX_FRAMESKIP = 5;

   int loops;
   float next_game_tick = clock.getElapsedTime().asMilliseconds();
   float interpolation;

   float posx = 0, posy = 0;
   while (window.isOpen()) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
         case sf::Event::Closed:
            window.close();
            break;
         case sf::Event::Resized:
            window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
            break;
         }
      }

      loops = 0;
      while (clock.getElapsedTime().asMilliseconds() > next_game_tick && loops < MAX_FRAMESKIP) {

         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            xspeed = 5;
         } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            xspeed = -5;
         } else xspeed = 0;

         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            yspeed = -5;
         } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            yspeed = 5;
         } else yspeed = 0;

         posx = std::fmod(posx + xspeed, background.getSize().x);
         posy = std::fmod(posy + yspeed, background.getSize().y);

         next_game_tick += SKIP_TICKS;
         ++loops;

      }

      interpolation = (float)(clock.getElapsedTime().asMilliseconds() + SKIP_TICKS - next_game_tick)
         / (float)SKIP_TICKS;

      quad[0].texCoords = sf::Vector2f(posx, posy);
      quad[1].texCoords = sf::Vector2f(posx + background.getSize().x, posy);
      quad[2].texCoords = sf::Vector2f(posx + background.getSize().x, posy + background.getSize().y);
      quad[3].texCoords = sf::Vector2f(posx, posy + background.getSize().y);

      window.clear();
      window.draw(quad, &background);
      window.display();

   }

}

If it works perfectly fine for you, I'm absolutely defeated here.

5
General / Re: Image of Sprite Skipping on Screen
« on: February 17, 2018, 03:52:30 pm »
@hapax If you look at my most recent code post, that's exactly what I've done. So, does nobody else get skipping from the setTextureRect version of that code? Could be a driver issue.

@dimitry I understand that, and I believe that was due to something with timing, which is why I implemented the interpolation to smooth things out, which worked for the most part.

6
General / Re: Image of Sprite Jittering on Screen
« on: February 17, 2018, 07:01:56 am »
So, I decided to try my hand at implementing interpolation, courtesy of this fellow: http://www.koonsolo.com/news/dewitters-gameloop/, to see if that could be the issue.

It definitely made things smoother, but I actually think there is a problem with the performance of setTextureRect for sf::Sprite objects. This picture is almost buttery smooth when using the stars.setPosition line, but switching to stars.setTextureRect yields the exact same jittering as shown in the gifs above:

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

#include <iostream>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML");

   //window.setVerticalSyncEnabled(true);
   window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("tileable_space.jpg"))
      exit(1);
   background.setRepeated(true);
   sf::Sprite stars(background);

   sf::Clock clock;

   float xspeed = 0, yspeed = 0;

   const int TICKS_PER_SECOND = 50;
   const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
   const int MAX_FRAMESKIP = 5;

   int loops;
   float next_game_tick = clock.getElapsedTime().asMilliseconds();
   float interpolation;

   float posx = 0, posy = 0;
   //int window_x = window.getSize().x, window_y = window.getSize().y, background_x = background.getSize().x;
   while (window.isOpen()) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
         case sf::Event::Closed:
            window.close();
            break;
         case sf::Event::Resized:
            window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
            break;
         }
      }

      loops = 0;
      while (clock.getElapsedTime().asMilliseconds() > next_game_tick && loops < MAX_FRAMESKIP) {

         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            xspeed = 5;
         } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            xspeed = -5;
         } else xspeed = 0;

         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            yspeed = -5;
         } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            yspeed = 5;
         } else yspeed = 0;
         
         posx += xspeed;
         posy += yspeed;

         next_game_tick += SKIP_TICKS;
         ++ loops;

      }

      interpolation = (float) (clock.getElapsedTime().asMilliseconds() + SKIP_TICKS - next_game_tick)
                  / (float) SKIP_TICKS;

      stars.setPosition(posx + (xspeed * interpolation), posy + (yspeed * interpolation));
      //stars.setTextureRect(sf::IntRect(std::fmod(posx, background.getSize().x), std::fmod(posy, background.getSize().y), 900, 600));


      window.clear();
      window.draw(stars);
      window.display();

   }

}

Is there some information I'm missing about performance degradation from the use of the setTextureRect command? Is it best to avoid it for scrolling backgrounds? I changed the last two parameters of its IntRect to be fixed just to make sure that the screen size request wasn't somehow causing the skipping. At this point, the cause of the performance degradation is beyond my scope, and it appears to be something within SFML.

7
General / Re: Image of Sprite Skipping on Screen
« on: February 16, 2018, 10:34:11 pm »
Alright, well thanks anyways. If anyone has ideas, I'm more than willing to try them. I've spent a good portion of time learning SFML. I have a long history with C++, and a brief history with OpenGL. This is my ideal framework to develop a game with from all the research I've done, so I'm pretty desperate here.

8
General / Re: Image of Sprite Skipping on Screen
« on: February 16, 2018, 10:05:24 pm »
I appreciate the attempt to help, but I'd rather not run a random exe that has been sent to me. If you provide the source for the "smooth_test" executable I'd be more than happy to run it.

9
General / Re: Image of Sprite Skipping on Screen
« on: February 16, 2018, 04:19:00 pm »
As I stated in most of my posts above, I've tried that along with every other combination of suggestions for frame rate issues like this that I could find. Thank you for the suggestion, though. Anymore ideas anyone? Am I just SOL on using SFML?

10
General / Re: Image of Sprite Skipping on Screen
« on: February 16, 2018, 07:26:39 am »
Still produces the same skipping. Even with removing the timer. Here are both code snippets:

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   int refresh_rate = 60;

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars_square.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   float posx = 0;
   float currentspeed = 0;
   float picture_speed = 30;
   // ---------- //

   sf::Clock clock;
   float current_time = clock.getElapsedTime().asSeconds();
   float frame_time = 0;

   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;
               
         }
      }

      float new_time = clock.getElapsedTime().asSeconds();
      frame_time = new_time - current_time;
      current_time = new_time;

      stars.setPosition(posx, 0);

      posx = std::fmod(posx + (picture_speed * frame_time), background.getSize().x);

      window.clear();
      window.draw(stars);
      window.display();

   }

}

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   int refresh_rate = 60;

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars_square.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   float posx = 0;
   // ---------- //

   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;
               
         }
      }

      stars.setPosition(posx, 0);

      posx += .01;

      window.clear();
      window.draw(stars);
      window.display();

   }

}

11
General / Re: Image of Sprite Skipping on Screen
« on: February 16, 2018, 02:51:03 am »
Yes, that's correct. The big jump is the gif looping, and the real issue is the slight stuttering. It's extremely noticeable at times when it repeatedly stutters.

So, I checked and ensured that my graphics drivers weren't forcing v-sync, and turned it off completely just to make sure, even though my GPU was running at an extremely high percentage, just to be safe lol.

The next step was implementing the variable delta time step from here: https://gafferongames.com/post/fix_your_timestep/, which... still lead to the stuttering issue with all combinations of what I've previously tried: threaded optimization, forced v-sync, setting the window frame limit, setting the window to v-sync...

Here's a visual:


Here's the code:
Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   int refresh_rate = 60;

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars_square.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   float posx = 0;
   float currentspeed = 0;
   float picture_speed = 30;
   // ---------- //

   sf::Clock clock;
   float current_time = clock.getElapsedTime().asSeconds();
   float frame_time = 0;
   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;

         }
      }

      float new_time = clock.getElapsedTime().asSeconds();
      frame_time = new_time - current_time;
      current_time = new_time;

      stars.setTextureRect(sf::IntRect(posx, 0, window.getSize().x, window.getSize().y));

      posx = std::fmod(posx + (picture_speed * frame_time), background.getSize().x);

      window.clear();
      window.draw(stars);
      window.display();

   }

}

Anymore ideas? Really appreciate the help so far, guys.

As a side note, just to double check that the skipping wasn't due to the value of posx never increasing or somehow moving back (no idea what would cause this, but figured I'd check), I added in a cout statement.

Here is the output:
Quote
posx is <= what it was before
0.00170898 <= 399.996
posx is <= what it was before
0.00354004 <= 400
posx is <= what it was before
0.00378418 <= 399.998
posx is <= what it was before
0.00219727 <= 399.998
posx is <= what it was before
0.00317383 <= 399.999
posx is <= what it was before
0.0057373 <= 399.992

And here's the code I added to the loop:
Quote
      posx = std::fmod(posx + (picture_speed * frame_time), background.getSize().x);

      if (posx <= previous_posx) std::cout << "\nposx is <= what it was before\n" << posx << " <= " << previous_posx;

      window.clear();
      window.draw(stars);
      window.display();

So, that's not the issue as far as I can tell.

Edit: So I tried out a few of the games here https://www.youtube.com/watch?time_continue=191&v=zH_omFPqMO4 that require smooth movement and every single one of them gave me the skipping issue when trying all of the things I mentioned here to remedy it. So, I'm beginning to think it's a hardware issue. However, absolutely no other games do this for me except those that utilize SFML.

Aaaaaand this game https://eigen.itch.io/pioneers exhibits the same behavior...

12
General / Re: Image of Sprite Skipping on Screen
« on: February 15, 2018, 06:23:34 pm »
I was under the impression that wouldn't help me either because I am now relying on the the frame rate for how smooth the texture scrolls. It was skipping for me before, which is why I attempted to add in the clock, as I thought the lack of one might be why it was skipping in the first place.

The following code still produces a skipping image when trying all combinations previously mentioned:

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars_square.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   // ---------- //

   int posx = 0;
   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;
         }
      }

      stars.setTextureRect(sf::IntRect(posx, 0, window.getSize().x, window.getSize().y));
      posx = (posx + 1) % (background.getSize().x);

      window.clear();
      window.draw(stars);
      window.display();

   }

}

Setting the framerate to my monitor, running in release mode, and turning off threaded optimization yielded the best results. However, after a few seconds there is still noticeable skipping of the image on my screen.

If there are any glaringly obvious errors that I've missed here I would really appreciate a tip. I've been working on this for hours now, so it could be as simple as needing someone else to read my code to find the dumb mistake.

13
General / Re: Image of Sprite Skipping on Screen
« on: February 15, 2018, 05:25:04 pm »
Well, I took your advice on this and changed the main loop to the following:

Quote
      while (passed_time.asSeconds() >= frame_time) {

         stars.setTextureRect(sf::IntRect(posx, 0, window.getSize().x, window.getSize().y));

         //std::cout << "POSX: " << posx + 2 << " % " << background.getSize().x << "\n";
         posx = (posx + 2) % (background.getSize().x);
         //std::cout << " = " << posx << "\n\n";

         window.clear();
         window.draw(stars);
         window.display();

         passed_time -= sf::seconds(frame_time);

      }

The lag is noticeably better, but still present. It's as if every few seconds the image decides it would like to take 1 jump back, and 2 jumps forward. This is after I tried all combinations of, once again, disabling threaded optimization, running in release, and the various frame modifiers that are commented out in the code of my original post.

I've commented out the cout statements in the loop above, but added them in after trying the previous steps to see if there were any consistencies in the textures wrapped position vs when the frame lag appears. I found none.

Is it possibly some faulty logic with my clock?

14
General / Image of Sprite Skipping on Screen
« on: February 15, 2018, 05:32:40 am »
EDIT: TO ANYONE READING THIS, IT IS NOT THE BIG JUMP THAT IS THE ISSUE. THAT'S JUST THE GIF LOOPING. THE PROBLEM IS THE JITTERING OF THE IMAGE, BACK AND FORTH IF YOU LOOK CLOSELY.

Hey, everyone. So this is something that I believe might be a bug, however, I have only been using SFML for about a week now, so I could definitely be doing something wrong.

First of all, let's get my hardware and software specifications out of the way:
RAM: 16GB DDR3
CPU: i5-3570k
GPU: GTX 1060 6GB, most recent drivers 390.77
Monitor #1: 2560 x 1440 @ 144fps w/ G-Sync
Monitor #2: 1280 x 1024 @ 60fps

OS: Windows 10, v. 1709, build 16299
IDE: Visual Studio 2015
SFML Version: 2.4.2

So, here is the problem I'm having. When I try to modify the position of anything related to a sprite, the image of the sprite appears to "jump" back and forth, and I've provided an image of how it looks for me below.



Here is the code that reproduces this problem for me:

Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   int refresh_rate = 60;
   float frame_time = (float) 1 / (float) 60;

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   int posx = 0;
   // ---------- //

   sf::Clock clock;
   sf::Time passed_time;
   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;
         }
      }

      passed_time += clock.restart();
      while (passed_time.asSeconds() >= frame_time) {

         stars.setTextureRect(sf::IntRect(posx, 0, window.getSize().x, window.getSize().y));
         posx += 2;

         window.clear();
         window.draw(stars);
         window.display();

         passed_time -= sf::seconds(frame_time);

      }

   }

}

I've read the entire FAQ and documentation provided for SFML over the last week from https://www.sfml-dev.org/learn.php

I thought that I might be doing something wrong, and here are outside resources I've utilized so far to try and understand, and come up with, this code above, other than my 3 years of C++ experience in university:
https://gafferongames.com/post/fix_your_timestep/
https://maksimdan.gitbooks.io/sfml-and-gamedevelopement/content/frame_rate.html
https://gamedev.stackexchange.com/questions/97675/sfml-game-loop-and-fps-problems

None of these seemed to fix the skipping problem, and after some more Googling, I found that some people had an issue with Nvidia's "Threaded Optimization" setting, however this had no measurable effect on performance for me when switched from "auto" to "off."

I had also seen that some people had an issue similar to mine depending on what their framerate was set to. So, I tried every possible combination of enabling vertical sync, limiting the frame rate, changing my threading optimization, and changing from debug to release.

None of these were able to remedy the issue. If it is something obvious, please let me know. I've been re-reading the documentation and tutorials for hours (from 7pm - 11pm just today) and would really appreciate any step in the right direction.

Thank you.  :)

Pages: [1]