Hi. My OpenGL application is randomly stopping rendering (black image), and continues after moving/resizing the window, by example. It's not WM_PAINT related, because I've set the window background color to white and OpenGL clear color to black, and the application shows a black window when the bug happens.
Here is some source code:
for (;;) {
if (aplicacionActiva) {
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message==WM_QUIT) {
exitCode=(int) msg.wParam;
break;
}
TranslateMessage (&msg);
DispatchMessage (&msg);
} else {
Scene_Render ();
SwapBuffers (hDC);
App_MainLoop ();
}
} else {
if (GetMessage (&msg, NULL, 0, 0)==0) {
exitCode=(int) msg.wParam;
break;
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
And the relevant functions:
void Scene_Render (void) {
struct stModelContainer *it;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Camera_ApplyTransform();
for (it=modelList; it!=NULL; it=it->next)
Model3D_RenderAllInstances (it->model);
}
void Camera_ApplyTransform (void) {
if (!camera)
return;
glCallList (camera->transformDisplayList);
}
void Model3D_RenderAllInstances (Model3D model) {
Instance3D i;
glCallList (model->material);
for (i=model->instances->next; !i->controlNode; i=i->next) {
glPushMatrix ();
glTranslatef (i->position[0], i->position[1], i->position[2]);
glRotatef (i->rotations[0], 1.0f, 0.0f, 0.0f);
glRotatef (i->rotations[1], 0.0f, 1.0f, 0.0f);
glRotatef (i->rotations[2], 0.0f, 0.0f, 1.0f);
glCallList (model->frameBase + i->currentFrame);
glPopMatrix ();
}
}
int App_MainLoop (void) {
int x,z;
unsigned int y;
x=rand() % MAX_ANCHO;
z=rand() % MAX_LARGO;
y=altura[x][z];
if (y<MAX_ALTO) {
Instance3D i=Model3D_Instantiate (model[rand() % 3]);
Instance3D_SetPosition (i, (float) (2*x-MAX_ANCHO),
(float) y,
(float) (2*z-MAX_LARGO));
Instance3D_SetRotations (i, 0.0f, 0.0f, 0.0f);
Instance3D_SetCurrentFrame (i, 0);
altura[x][z]++;
}
return 1;
}
Notes:
- camera->transformDisplayList is compiled just once at the beginning of the application, and it's not modified when moving or resizing the window (so the problem is not there).
- App_MainLoop just create a new instace of a random model (there are 3 moedls loaded: they're cubes) and places it in the scene filling a block (like 3D tetris, but with only-one-block pieces).
Any ideas why it's that happening?