Jump to content
  • Advertisement
Sign in to follow this  
theNestruo

OpenGL Application stops rendering randomly

This topic is 5027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
I don't notice anything screwy with this posted code. The thing that comes to mind for me, since it appear (by the blackness) that it is still rendering, is that perhaps you are mult-ing something into the projection matrix without loading identity first. That can easily make things disappear. Maybe you're forgetting, in some weird (or not) case, to properly set the matrix mode... just a thought.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!