Hi, in OSX for sfml2, how do i create a window, close it, and recreate it again??
I did something like:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
void WindowFunction()
{
// Create the main window
sf::ContextSettings Settings;
Settings.DepthBits = 24; // Request a 24 bits depth buffer
Settings.StencilBits = 8; // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = 0; // Request 2 levels of antialiasing
Settings.MajorVersion = 3;
Settings.MinorVersion = 3;
sf::Window App(sf::VideoMode(1024, 768, 32), "SFML OpenGL", sf::Style::Close, Settings);
Settings = App.GetSettings();
std::cout << "DepthBits " << Settings.DepthBits << "\n";
std::cout << "StencilBits " << Settings.StencilBits << "\n";
std::cout << "Antialiasing Level " << Settings.AntialiasingLevel << "\n";
std::cout << "Opengl Version " << Settings.MajorVersion << "." << Settings.MinorVersion << "\n";
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(0.176f, 0.196f, 0.667f, 0.0f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because active window is always the same,
// but don't forget it if you use multiple windows or controls
//App.SetActive(true);
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Finally, display rendered frame on screen
App.Display();
//App.SetActive(false);
}
}
int main()
{
WindowFunction();
WindowFunction();
return EXIT_SUCCESS;
}
if i press 'esc' to close the first window, it aborts with a seg fault. If I press the 'cross' button at the top left corner of the first window, it aborts with a pure virtual function call error.
regards