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.
////////////////////////////////////////////////////////////
// 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;
}