PDA

View Full Version : OpenGL and threads



vgo
02-03-2007, 03:27 PM
I just don't seem to get my rendering thread working in SDL. I have a similar thing working perfectly with Windows API + OpenGL, but when I try to mix threads with OpenGL I get "invalid operation" from every single call to any OpenGL function.

I create my thread like this:


ThreadID := SDL_CreateThread(@ThreadFunc, nil);


And the ThreadFunc looks like this:


function ThreadFunc: Integer;
begin
RenderThread.Execute;
Result := 1;
end;


RenderThread is an instance of a class that handles FPS limitation etc and calls the rendering procedure in the game engine which does all the actual rendering.

The problem is that every single OpenGL call that I've tried works BEFORE SDL_CreateThread, but inside the thread every call generates an error and I have no idea whatsoever what the hell is going on!?!?!?!?

EDIT:

To clarify, this generates error:


function ThreadFunc: Integer;
begin
glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT );
glCheckForError();
glMatrixMode(GL_MODELVIEW);
glCheckForError();
glLoadIdentity();
glCheckForError();
Result := 1;
end;