调整窗口大小时出现白条

问题描述 投票:0回答:1

enter image description here

我正在尝试使用以下代码使用 SDL3 创建一个窗口

#include "SDL3/SDL.h"
#include "SDL3/SDL_system.h"

int main(){
    unsigned int sdlFlags = 0;
    sdlFlags |= SDL_WINDOW_RESIZABLE;
    sdlFlags |= SDL_WINDOW_BORDERLESS;
    sdlWindow = SDL_CreateWindow(InTitle, InWidth, InHeight, sdlFlags);
    while(true){
        SDL_PollEvent(&sdlEvent);
        switch (sdlEvent.type)
        {
            case SDL_EVENT_WINDOW_CLOSE_REQUESTED:  break;
        }

    }
}

但是当您尝试调整窗口大小时,会出现白色条纹并不会消失

从SDL2切换到SDL3时出现问题

c++ window sdl sdl-3
1个回答
0
投票

清除窗口内容。这可以使用 Vulkan 等渲染 API 来完成,或者间接使用 SDL 自己的抽象渲染功能来完成,扩展原始问题的代码,如下所示:

#include "SDL3/SDL.h"
#include "SDL3/SDL_system.h"

int main(){
    unsigned int sdlFlags = 0;
    sdlFlags |= SDL_WINDOW_RESIZABLE;
    sdlFlags |= SDL_WINDOW_BORDERLESS;
    SDL_Window* sdlWindow = SDL_CreateWindow(InTitle, InWidth, InHeight, sdlFlags);
    SDL_Renderer* sdlRenderer = SDL_CreateRenderer(sdlwindow, NULL);
    SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255); // opaque black

    while(true){
        SDL_PollEvent(&sdlEvent);
        switch (sdlEvent.type)
        {
            case SDL_EVENT_WINDOW_CLOSE_REQUESTED:  break;
        }
        // Draw the window contents, starting by clearing it:
        SDL_RenderClear(sdlRenderer);
        // Draw stuff...
        // Show the rendered contents in the window:
        SDL_RenderPresent(sdlRenderer);

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.