Does anyone know anything about threads?

I’m trying to display a splash screen while I’m loading my textures so that the user isn’t just looking at a blank screen for a few seconds. Here are parts of my code:

DWORD WINAPI TextureThread(LPVOID lpParam)
{

if (!LoadPlanetGLTexture() | | !LoadMoonGLTextures() | | !LoadRingGLTexture() | | !LoadSunGLTexture()) // Load texture
{
return false;
}

return true;
}

DWORD WINAPI LoadingThread(LPVOID lpParam)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1.0f, 1.0f, 1.0f);

if (!LoadStarGLTexture())
{
return false;
}

DrawStarField();

return true;
}

void startup()
{
DWORD iID[2];
DWORD dwThrdParam = 1;

HANDLE hThread[2];

hThread[0] = CreateThread(NULL,0,TextureThread,&dwThrdParam,NULL,&iID[0]);
hThread[1] = CreateThread(NULL,0,LoadingThread,&dwThrdParam,NULL,&iID[1]);

WaitForMultipleObjects(2,hThread,TRUE,INFINITE);
}

I call startup from my WinMain routine. However nothing appears to even happen. Right away it goes to start drawing the scene without loading any textures. It’s like it completely skips this two threads but for a split second I think I see the starfield texture flash but I cannot be sure.

What am I doing wrong?

Thank You.

[This message has been edited by Rhaegar (edited 04-02-2003).]

[This message has been edited by Rhaegar (edited 04-02-2003).]

An OpenGL rendering context is tied to a specific thread, which means you can’t just call GL-functions from other threads like that. First you have to move the rendering context over to the other thread (look up wglMakeCurrent), and second, you can only have the rendering context current in one, and only one, thread and any given time. What that means is that you cannot load textures and draw a starfield at the same time (assuming the starfield uses OpenGL).

You could use wglShareLists which would allow both threads to use the same display lists and texture names/space but separate contexts.

Nuts. This is going to be a lot more complex than I thought. Ok well thanks for the insight.

I had a similar problem with my texture loading taking ages. What I did was to draw a Loading.. Please wait scene and call SwapBuffers before calling the texture loading routines.

This shows a loading message while loading the textures. It isn’'t snazzy or animated, but its better than a black screen.