解决QT 中使用SDL多次创建窗口不能渲染画面

Posted 顾文繁

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决QT 中使用SDL多次创建窗口不能渲染画面相关的知识,希望对你有一定的参考价值。

在QT中多次绑定创建窗口句柄会出现不能渲染的问题。

win_ = SDL_CreateWindowFrom(this->win_id_);

原因是SDL中SDL_CreateWindowFrom的源码中

void
SDL_DestroyWindow(SDL_Window * window)

    SDL_VideoDisplay *display;

    CHECK_WINDOW_MAGIC(window, );

    /* Restore video mode, etc. */
    SDL_HideWindow(window);/*注意这个地方哦*/

    /* Make sure this window no longer has focus */
    if (SDL_GetKeyboardFocus() == window) 
        SDL_SetKeyboardFocus(NULL);
    
    if (SDL_GetMouseFocus() == window) 
        SDL_SetMouseFocus(NULL);
    

    /* make no context current if this is the current context window. */
    if (window->flags & SDL_WINDOW_OPENGL) 
        if (_this->current_glwin == window) 
            SDL_GL_MakeCurrent(window, NULL);
        
    

    if (window->surface) 
        window->surface->flags &= ~SDL_DONTFREE;
        SDL_FreeSurface(window->surface);
    
    if (_this->DestroyWindowFramebuffer) 
        _this->DestroyWindowFramebuffer(_this, window);
    
    if (_this->DestroyWindow) 
        _this->DestroyWindow(_this, window);
    
    if (window->flags & SDL_WINDOW_OPENGL) 
        SDL_GL_UnloadLibrary();
    

    display = SDL_GetDisplayForWindow(window);
    if (display->fullscreen_window == window) 
        display->fullscreen_window = NULL;
    

    /* Now invalidate magic */
    window->magic = NULL;

    /* Free memory associated with the window */
    SDL_free(window->title);
    SDL_FreeSurface(window->icon);
    SDL_free(window->gamma);
    while (window->data) 
        SDL_WindowUserData *data = window->data;

        window->data = data->next;
        SDL_free(data->name);
        SDL_free(data);
    

    /* Unlink the window from the list */
    if (window->next) 
        window->next->prev = window->prev;
    
    if (window->prev) 
        window->prev->next = window->next;
     else 
        _this->windows = window->next;
    

    SDL_free(window);

有这么一段SDL_HideWindow(window);代码,因此需要解决办法就是在创建好窗口以后需要调用

SDL_ShowWindow(window);
这里的window是创建的窗口句柄。
上面的源代码参考https://www.cnblogs.com/lihaiping/p/4324315.html

以上是关于解决QT 中使用SDL多次创建窗口不能渲染画面的主要内容,如果未能解决你的问题,请参考以下文章

第十三章 视频播放器开发之渲染背景

ffmpeg 播放音视频,time_base解决音频同步问题,SDL渲染画面

QT下SDL窗口创建案例

QT下SDL窗口创建案例

SDL学习

渲染时如何使 SDL2 0,0 定位在窗口的中心?