Hey guys,
So I am using OpenGL to draw to an sf::Window in SFML2. The general working setup is something like this :
while(window->isOpen())
{
sf::Event event;
while (window->pollEvent(event))
{
// Request for closing the window
if (event.type == sf::Event::Closed)
window->close();
}
window->setActive();
//DO OPENGL STUFF HERE
window->display();
}
What I need to do is have a function inside another class that can actually handle the OpenGL portion of the code. Is this even possible in OpenGL? I tried doing something like this, but I get a SegFault when I try to call localWindow->setActive(); :
Renderer.hclass Renderer
{
private:
Window* localWindow;
public:
Renderer(sf::Window* inWindow)
{
localWindow = &inWindow;
}
void draw()
{
localWindow->setActive();
//OPENGL STUFF HERE!
}
}
Main.cpp#include "Renderer.h"
sf::Window* window;
Renderer renderer(window);
void main()
{
//Create new Settings and Window to point "window" to.
sf::ContextSettings settings;
settings.antialiasingLevel = 4;
settings.majorVersion = 3;
settings.minorVersion = 3;
sf::Window localWindow(sf::VideoMode(800,600), "OpenGL", sf::Style::Default, settings);
window = &localWindow;
graphics();
}
void graphics()
{
while(window->isOpen())
{
sf::Event event;
while (window->pollEvent(event))
{
// Request for closing the window
if (event.type == sf::Event::Closed)
window->close();
}
window->setActive();
renderer.draw();
window->display();
}
}