使用SDL2绘制多个SDL_Texture时闪烁

时间:2016-08-30 20:36:42

标签: textures sdl-2

我已经设置了一个SDL2渲染器,我有两个纹理,我试图在屏幕上绘制。当我单独这样做时,它的工作正常。但是当我把它们两个画在一起时,纹理就会闪烁。这是后台缓冲区的问题吗?还有什么我需要做的才能启用双缓冲区吗?

这就是我正在做的事情:

    Renderer::m_Renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (Renderer::m_Renderer == nullptr){
        SDL_DestroyWindow(win);
        std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
    }

    while (!m_bQuit) {
        m_tCurrentFrameTime = clock();

        // Input
        while (SDL_PollEvent(&m_Event)) {
            switch (m_Event.type) {
                case SDL_QUIT:
                    m_bQuit = true;
                    break;

                default:
                    break;
            }
        }

       // Update

    SDL_RenderCopyEx(m_Renderer, m_tBackgroundTexture, NULL, &m_rRect, m_fRotation, NULL, SDL_FLIP_NONE);
    SDL_RenderPresent(Renderer::getRenderer());

    SDL_RenderCopyEx(m_Renderer, m_tCharacterTexture, NULL, &m_rRect, m_fRotation, NULL, SDL_FLIP_NONE);
    SDL_RenderPresent(m_Renderer);


        // Clear screen
        SDL_RenderClear(m_Renderer);
    }

1 个答案:

答案 0 :(得分:3)

渲染两个纹理然后 <div>,而不是每个SDL_RenderPresent()

所以:

SDL_RenderPresent()