I've found plenty of stuff out there about multithreading, OGL and SFML, yet I had only partial success in inmplementing it. I'm currently working in test project to comprehend things and I actually managed to get it done..
Wait I didn't tell what.. I setup my raw OGL view, then in main loop I draw green point through thread, I switch back render a red point, display window.. Before switching to thread I deactivate window context in main thread, activate it in second thread, do my drawing, deactivate, get back to main thread and reactivate. Everything is synchronized with glFinish in second thread and sf::Thread::Wait in main thread so I'm sure nothing gets corrupted.. And it works, I get green point, a red point, but it is sloooooow as.. well I can't really expres that.
Basically it displays a frame then get stucked for about 5 seconds (everything.. even whole event system is frozen so I can't move a window). I noticed this behaviour in the dark age of mine when I recreated whole context on every launch of second thread. Also it had serious memory leaks. And the same behaviour (both leaks and long jumps to/from thread) I get now with only activating or deactivating.
This is my test code:
#include <GL\glew.h>
#include <GL\GLU.h>
#include <GL\GL.h>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <SFML\Graphics.hpp>
void fun(sf::RenderWindow* win){
win->setActive(true);
glBegin(GL_POINTS);
glVertex2f(50,50);
glEnd();
glFinish();
win->setActive(false);
}
int main(){
sf::RenderWindow win(sf::VideoMode(200,200), "Context sharing", sf::Style::Close);
//setup view
gluOrtho2D(0,200,200,0);
glPointSize(10);
sf::Thread tr(fun,&win);
sf::Event ev;
while(win.isOpen()){
while(win.pollEvent(ev)){
switch(ev.type){
case sf::Event::Closed:
win.close();
break;
default:
break;
}
}
//clear buffer
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
//render green point from thread
glColor3f(0,1,0);
win.setActive(false);
tr.launch();
tr.wait();
win.setActive(true);
//render red point to check if working
glColor3f(1,0,0);
glBegin(GL_POINTS);
glVertex2f(75,75);
glEnd();
//display it
win.display();
}
return 0;
}
If I get it right I might give that code to wiki if you like as only resource on this "Loading images in a thread (and displaying progress)" is now greyed out and can't be accessed.