Sign in to follow this  
rejak

scene flickers while scene rendering

Recommended Posts

The scene flickers if i rotate the camera with the mouse, sometimes if I release the mouse it keeps black until i rotate the camera again. If i release the mouse in a moment where the scene renders correctly, then the next frames are also rendered correctly.

void Graphics_Engine::render(Hex_Board::hex_tile const * const * const tiles_list, uint16_t tiles_count)
{
    double x, y, x_i, y_i;
    double angle;

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    camera->update();
    glColor3f( 0.0f, 1.0f, 0.0f);


    for (uint16_t i = 0; i < tiles_count; i++)
    {
        glBegin(GL_LINE_LOOP);
        x = sqrt(3.) * (tiles_list[i]->q + tiles_list[i]->r/2.);
        y = 3./2. * tiles_list[i]->r;

        for (uint8_t i = 0; i < 6; i++)
        {
            angle = 2. * M_PI / 6. * (i + 0.5);
            x_i = x + cos(angle);
            y_i = y + sin(angle);
            glVertex3f(x_i, y_i, 0);
        }
        glEnd();
    }

    SDL_RenderPresent(renderer);
    glClear(GL_COLOR_BUFFER_BIT);
}
void Camera::update()
{

    gluLookAt(pos[0], pos[1], pos[2],
              tar[0], tar[1], tar[2],
              up[0], up[1], up[2]);
}

Share this post


Link to post
Share on other sites

Just a wild guess from opengl beginner, shouldn't glClear code be on top of rendering function? Can you give as a screenshot of scene flickering? Maybe you need to clear depth buffer too? Maybe z-fighting occurs? Maybe near and far values aren't set correctly?

Edited by zgintasz

Share this post


Link to post
Share on other sites
Theres no need for screenshots, the flickering appears if i rotate the camera, at one frame you have a perfectly rendered scene the other frame you have a blank black screen.

glClear clears the rendering buffer, so if you use doublebuffering it's indifferent if you call it at the top of the render function or on the bottom. Even it is on the bottom of the rendering function, it's before the next rendering function call.

To be on the safe side i tried writing it on the top of the render function and it didn't made any differences, just the same flickering.

Share this post


Link to post
Share on other sites
void Camera::rotate_mouse(int16_t x, int16_t y)
{
    glm::dvec3 rel = pos-tar;

    rel = glm::rotateX(rel, (double)y/10.0f);
    rel = glm::rotateY(rel, (double)x/10.0f);

    tar=pos+rel;
    //update();
    //rotate((double)y/100.0f, glm::dvec3(1.0f, 0.0f, 0.0f));
    //rotate((double)x/100.0f, glm::dvec3(0.0f, 1.0f, 0.0f));

}
while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
        case SDL_MOUSEMOTION:
            if (dragging)
            {
                graphics->get_camera()->rotate_mouse(event.motion.xrel, event.motion.yrel);
            }
            break;

        }
    }
void Camera::update()
{
    gluLookAt(pos[0], pos[1], pos[2],
              tar[0], tar[1], tar[2],
              up[0], up[1], up[2]);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this