SDL2 program only works if Renderer is created with SDL_RENDERER_SOFTWARE

跟風遠走 提交于 2019-11-28 02:24:48

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 :)

BWD

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
  • ...
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!