scene flickers while scene rendering

Started by
5 comments, last by rejak 10 years, 8 months ago
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]);
}
Advertisement

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?

Game I'm making - GANGFORT, Google Play, iTunes

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.

I don't see anything wrong with your code, the problem is most likely somewhere else. Can you show how you do that rotation with mouse?

Derp


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]);
}

Just a guess, does it work if you change pos-tar to tar-pos?

Derp

thaaaaaaaaaaaaaaaaaaaaaaaaaaaanks Sponji

and for me: MEGA FACEPALM

This topic is closed to new replies.

Advertisement