SDL2 program only works if Renderer is created with SDL_RENDERER_SOFTWARE

前端 未结 2 1922
别跟我提以往
别跟我提以往 2020-12-07 06:19

I\'ve written a program using C++ and SDL2 which:

  1. creates a window
  2. gets the window\'s surface
  3. creates a renderer for the window
  4. rend
相关标签:
2条回答
  • 2020-12-07 06:33

    Try adding SDL_RENDERER_PRESENTVSYNC to your renderer's flag (Proposed by someone here).

    C++ seems to be the programming language you're using but for those looking for a fully working SDL2.0.8-based C program that does not use GetWindowSurface(), please take a look here:

    Mainly,

    • initWindowAndRenderer
    • drawText
    • drawImage
    • drawVideo
    • setBgColor
    • drawVideo
    • ...
    0 讨论(0)
  • 2020-12-07 06:37

    The SDL_GetWindowSurface() header comment specifically prohibits using it with the SDL_Renderer functionality:

    /**
     *  \brief Get the SDL surface associated with the window.
     *
     *  \return The window's framebuffer surface, or NULL on error.
     *
     *  A new surface will be created with the optimal format for the window,
     *  if necessary. This surface will be freed when the window is destroyed.
     *
     *  \note You may not combine this with 3D or the rendering API on this window.
     *
     *  \sa SDL_UpdateWindowSurface()
     *  \sa SDL_UpdateWindowSurfaceRects()
     */
    extern DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window * window);
    

    Use SDL_RENDERER_TARGETTEXTURE & SDL_SetRenderTarget() if you want to capture SDL_Renderer output.

    You can use SDL_GetRendererInfo() to query a compatible texture format. Or just blast ahead with SDL_PIXELFORMAT_ARGB8888 like testrendertarget.c does and hope for the best :)

    0 讨论(0)
提交回复
热议问题