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

Author Topic: OpenGL application lag  (Read 6228 times)

0 Members and 1 Guest are viewing this topic.

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
OpenGL application lag
« on: January 06, 2014, 07:55:18 pm »
Hi,

I have a problem with my OpenGL application because i get some lag.
I set the VSync to true and the lag is reduced a lot but it is still present.
I set the limit of the frames to 60 and i get 16-17 millisecond elapsed time every frame.
The CPU usage is low  (5-10%) and the RAM usage is about 20 Mb.
I tested the application on 3 different computers (All macintosh) and the problem persist.

Specs of computers:

Mackbook pro 13"
OS : Maverick
Graphic Card : GeeForce 320M

Mackbook air 11"
OS : Maverick
Graphic Card : Intel HD 5000

Hackintosh
OS : MAverick
Graphic Card : AMD Radeon HD 6500;


BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #1 on: January 06, 2014, 08:27:34 pm »
Provide with minimal example code.

60 fps = 16.66... sec per frame so that and everything else seams good.
I do not see the issue you getting "lag" with openGL application, are you using network?
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #2 on: January 06, 2014, 08:46:49 pm »


Here a minimal code with a rotating quad that is a little bit laggy:

    sf::RenderWindow window(sf::VideoMode(800, 600), "Virtual Shock Testing",sf::Style::Default,settings);
   
    glEnable( GL_BLEND );
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   
    window.setVerticalSyncEnabled(true);
    window.setFramerateLimit(60);
   
    //--- OPENGL INITIALIZE ---
    //Perspective
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho (0, 800, 600,0, 0, 1);
    glViewport(0,0,800,600);
    glMatrixMode (GL_MODELVIEW);
   
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
   
    sf::Time time;
    sf::Clock clock;
   
    SpriteBatch spritebatch;
    Sprite test;
   
    test.SetColor(Color(1,0,0,1));
    test.SetTexture(0);
    test.SetTextureSource(Rectf(0,0,1,1));
    float rotation = 0;
   
    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Escape pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
        }
       
        rotation+=0.0001*time.asMicroseconds()/1000.00;
       
        test.SetPosition(Rect(200,200,400,400),Vector2i(400,400),rotation);
       
        window.clear();
       
        spritebatch.Begin();
        spritebatch.Draw(test);
        spritebatch.End();
       
        window.display();
       
        time = clock.restart();
    }
 

I'm not using network.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #3 on: January 06, 2014, 09:00:35 pm »
The code is not compilable without spriteBatch class.
Looking deeper i see sf::Sprite has a line using
"SetColor"
The current version of sfml is using
"sf::Sprite::setColor"
if you are using older version of sfml be sure to note that.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: OpenGL application lag
« Reply #4 on: January 06, 2014, 09:58:16 pm »
    window.setVerticalSyncEnabled(true);
    window.setFramerateLimit(60);
 
Using both is most likely wrong. Using two independent timers for waiting will cause jitter from lost frames.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10919
    • View Profile
    • development blog
    • Email
Re: OpenGL application lag
« Reply #5 on: January 06, 2014, 10:35:49 pm »
Looking deeper i see sf::Sprite has a line using
"SetColor"
The current version of sfml is using
"sf::Sprite::setColor"
if you are using older version of sfml be sure to note that.
You looked wrong, it's the sprite batch class. He's using SFML 2.x. ;)
Also 60fps = 0.0166.. seconds = 16.66.. milliseconds

As wintertime said and as written in the tutorials don't mix the two options.

At best would be an recording of the issue, however the question is, if it's still visible on a recording.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #6 on: January 09, 2014, 05:44:24 pm »
This video shows my issue:


It's not mine but happen exactly the same thing, whit VSYNC and on 3 different MAC computers as I wrote above.

In the code I posted you can not see the Spritebatch class and the Sprite class...
I simply put every Sprite in a Sprite array and i draw everything with spritebatch.end() with Vertex array.

Sorry if I made any mistakes in writing, I'm Italian.
« Last Edit: January 09, 2014, 05:51:27 pm by Carlo Meroni »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10919
    • View Profile
    • development blog
    • Email
Re: OpenGL application lag
« Reply #7 on: January 09, 2014, 05:50:52 pm »
This video shows my issue:

Well, now I'm confused. The video shows an issue where you can see some "tiles" getting pulled apart (i.e. the line gets broken) and from the comment it was an issue with the Nvidia driver.
Do you get that as well and call it "lag" or how does it show your issue? ???
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #8 on: January 09, 2014, 06:03:37 pm »
It happens something like that, all the objects that are moving, (like rotating or simply when moving the view using glulookat() ) they move like the speed is irregular, like there is a delay or something like that.
In the video the movement of the view is not smooth.



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10919
    • View Profile
    • development blog
    • Email
Re: OpenGL application lag
« Reply #9 on: January 09, 2014, 06:16:39 pm »
It happens something like that, all the objects that are moving, (like rotating or simply when moving the view using glulookat() ) they move like the speed is irregular, like there is a delay or something like that.
So if there was a line moving, it would get "cut" in segments?

In the video the movement of the view is not smooth.
His view doesn't move smoothly, because he's moving it with events. Notice the one small movement, then the pause and then the repeating movement + he might not have used the smartest movement code. Hard to say + I'm too lazy to dig out the old topic. I just know, that it worked flawless on my system:
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #10 on: January 09, 2014, 07:16:00 pm »
I made a video:
Watch carefully at the logo that rotates and the view when is moving.


AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: OpenGL application lag
« Reply #11 on: January 09, 2014, 07:49:54 pm »
3Things I would check:

  • Check if you have constant 60 fps. There is a good fps"timer" in the wiki
  • Try to implement a gameloop with fixed timestamps. Maybe there are some rounding issues when you multiply the frametime
  • Check the driver for some "weird" settings


AlexAUT

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #12 on: January 09, 2014, 08:06:01 pm »
What is your os?
I can send you application for you to test i believe i had 32bit one somewhere.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Carlo Meroni

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: OpenGL application lag
« Reply #13 on: January 09, 2014, 08:26:44 pm »
I have a costant 60 FPS. The elapsed time for each frame look like that (in microsecond) :

17680
17675
17282
17679
16684
16999
17678
17390
.....

I checked and there are no rounding issues.
For the drivers settings... OS X Mavericks does not allow users to touch the graphics card driver.
I tried to use glflush () and glfinish () after every draw but there is no difference.

Maybe i'm drawing in a wrong way?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10919
    • View Profile
    • development blog
    • Email
Re: OpenGL application lag
« Reply #14 on: January 10, 2014, 09:31:08 am »
If you have a consistent FPS rate, it's really odd that you get micro stuttering.

Could you check how it performance in fullscreen mode?
And what happens if you move the view only on integer basis (1, 2, 3, 4 instead of 1.1, 1.2, 1.3,...)?

Btw. looks awesome! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything