Jump to content
  • Advertisement
Sign in to follow this  
rejak

scene flickers while scene rendering

This topic is 1887 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

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
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?

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

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?

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
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!