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

Author Topic: Vsync and Intel HD 3000  (Read 6264 times)

0 Members and 1 Guest are viewing this topic.

Randy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Vsync and Intel HD 3000
« on: November 21, 2011, 11:51:18 pm »
Vsync doesn't want to work it seems. I'm in windowed mode with OpenGL using SFML2. Enabling/disabling VSync seems to have no effect on effective FSP. VSync is app controlled from the Intel gfx options. Shouldn't the thread halt at window.Display() if VSync is enabled?. Using x64 Win7.
Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>

using std::cout;
using std::endl;

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
bool enable=true;
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(1200, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.EnableVerticalSync(enable);
    //window.SetFramerateLimit(55);
    // Create a sprite for the background

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Bind our texture

    // Create a clock for measuring the time elapsed
    sf::Clock clock;

    // Start game loop
    int t=clock.GetElapsedTime();
    int i=0;
    while (window.IsOpened())
    {
        window.EnableVerticalSync(enable);

        // Process events
        sf::Event event;
        while (window.PollEvent(event))
        {
            // Close window : exit
            if (event.Type == sf::Event::Closed)
                window.Close();

            // Escape key : exit
            if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
                window.Close();

            if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::V))
                cout<<(enable^=1)<<endl;

            // Adjust the viewport when the window is resized
            if (event.Type == sf::Event::Resized)
                glViewport(0, 0, event.Size.Width, event.Size.Height);
        }

        // Clear the depth buffer
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        // We get the position of the mouse cursor, so that we can move the box accordingly
        float x =  sf::Mouse::GetPosition(window).x * 200.f / window.GetWidth()  - 100.f;
        float y = -sf::Mouse::GetPosition(window).y * 200.f / window.GetHeight() + 100.f;

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(x, y, -100.f);
        glRotatef(clock.GetElapsedTime() * 0.05f, 1.f, 0.f, 0.f);
        glRotatef(clock.GetElapsedTime() * 0.03f, 0.f, 1.f, 0.f);
        glRotatef(clock.GetElapsedTime() * 0.09f, 0.f, 0.f, 1.f);

        // Draw a cube
        float size = 20.f;
        glBegin(GL_QUADS);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(-size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(-size, -size,  size);

            glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, -size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, size,  size);

        glEnd();

        // Draw some text on top of our OpenGL object
//        window.SaveGLStates();
//        sf::Text text("SFML / OpenGL demo");
//        text.SetPosition(250.f, 450.f);
//        text.SetColor(sf::Color(255, 255, 255, 170));
//        window.Draw(text);
//        window.RestoreGLStates();

        // Finally, display the rendered frame on screen
        window.Display();
        //glFinish();
        if(clock.GetElapsedTime()-t>=1000)
        {
            cout<<"VSync "<<enable<<" FPS "<<i<<endl;
            t=clock.GetElapsedTime();
            i=0;
        }
        i++;
    }

    // Don't forget to destroy our texture

    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Vsync and Intel HD 3000
« Reply #1 on: November 22, 2011, 07:42:52 am »
How do you see that it doesn't work?
Laurent Gomila - SFML developer

Randy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Vsync and Intel HD 3000
« Reply #2 on: November 22, 2011, 11:46:23 am »
Code: [Select]
if(clock.GetElapsedTime()-t>=1000)
        {
            cout<<"VSync "<<enable<<" FPS "<<i<<endl;
            t=clock.GetElapsedTime();
            i=0;
        }
        i++;


i is the frame counter and the program writes to console each second. As I understand if VSync is enabled it should wait at window.Display() for the refresh rate sync witch is 60 Hz on my PC but the console shows I get 900 fps.
Link to zip. You can toggle VSync with v.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Vsync and Intel HD 3000
« Reply #3 on: November 22, 2011, 11:59:48 am »
Have you tried to enable/disable it once, rather than every frame?
Laurent Gomila - SFML developer

Randy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Vsync and Intel HD 3000
« Reply #4 on: November 22, 2011, 12:22:40 pm »
Yeah, I added the VSync toggle later. It used to be on by default:
Code: [Select]
sf::RenderWindow window(sf::VideoMode(1200, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.EnableVerticalSync(enable);

Suprisingly forcing VSync on from the gfx settings has no effect either. Either I have no idea what I am doing, Intel drivers are defective or it's the windowed mode. It doesn't work in SDL either...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Vsync and Intel HD 3000
« Reply #5 on: November 22, 2011, 12:30:05 pm »
Ok so it's definitely a driver problem.
Laurent Gomila - SFML developer

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Vsync and Intel HD 3000
« Reply #6 on: November 22, 2011, 06:44:50 pm »
I have the same problem with my notebook with an intel hd graphics card.
I just use both Vsync and setframelimit, so it will work fine on every system.

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Vsync and Intel HD 3000
« Reply #7 on: November 23, 2011, 03:32:16 am »
Although it's not the same card I also have this problem on two other intel cards, as seen in this topic:
http://www.sfml-dev.org/forum/viewtopic.php?t=4347&highlight=

Could the problem be the same?

Vsync works with directx applications just not with SFML.

Quote from: "P@u1"
I have the same problem with my notebook with an intel hd graphics card.
I just use both Vsync and setframelimit, so it will work fine on every system.

I think SetFrameTime has priority over vsync so it won't matter if you use it but I could be wrong!

Randy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Vsync and Intel HD 3000
« Reply #8 on: November 23, 2011, 03:12:21 pm »
Yeah, I tested this on an older Intel machine and got the same problem, worked fine on a machine with an nVidia card. It's also funny how disabling/enabling Aero has an effect on FPS and tearing, at least on some other programs I found on the Interners. My uneducated guess it's a problem with the OGL implementation.