This is my code:
// Project.
#include "main.hpp"
// Third-Party Libraries.
// OpenGL.
#include "GL/glu.h"
// SFML.
#include "SFML/Window.hpp"
using sf::VideoMode;
using sf::Window;
using std::string;
Main::Main(GLsizei width, GLsizei height)
{
glEnable(GL_DEPTH_TEST);
reshape(width, height);
}
void Main::reshape(GLsizei width, GLsizei height)
{
m_width = width;
m_height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, width/height, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
void Main::render()
{
glLoadIdentity();
gluLookAt(0.0, 1.0, 6.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(2.0, 2.5, -1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-3.5, -2.5, -1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(2.0, -4.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(-1.0, 2.0, 0.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(-3.0, -0.5, 0.0);
glColor3f(0.0, 1.0, 1.0);
glVertex3f(-1.5, -3.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glVertex3f(1.0, -2.0, 0.0);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);
glEnd();
}
/**
* Main function.
*/
int main(int argc, char* argv[])
{
GLsizei width = 1600;
GLsizei height = 900;
GLsizei color = 32;
bool fullscreen = false;
string appName = "OpenGL Tests";
// Create the application window with an OpenGL context to draw on.
Window window(VideoMode(width, height, color), appName);
window.setVerticalSyncEnabled(true);
// Interface initialization.
Main app(width, height);
// Main loop.
while (window.isOpen())
{
app.render();
glFlush();
window.display();
// Event handling.
sf::Event event;
while(window.pollEvent(event))
{
if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::F)
{
fullscreen = !fullscreen;
if (fullscreen)
{
VideoMode videoMode = sf::VideoMode::getDesktopMode();
if (videoMode.isValid())
{
window.create(videoMode, appName, sf::Style::Fullscreen);
}
}
else
{
VideoMode videoMode(width, height, color);
if (videoMode.isValid())
{
window.create(videoMode, appName);
}
}
}
}
else if (event.type == sf::Event::Resized)
{
app.reshape((GLsizei) event.size.width, (GLsizei) event.size.height);
}
else if (event.type == sf::Event::Closed)
{
window.close(); break;
}
}
}
return 0;
}
It works just fine in windowed mode, but when I turn on the fullscreen mode by pressing F, the screen turns black and the figures rendered with OpenGL are not there. I can only see the system cursor.
Then, I press F again and I get back to the windowed mode normally. I can still see the figures, and I can resize the window and get them repainted correctly.
I am working under
Chakra Linux using
SFML 2.0 RC 1.