I'm lacking the bridge between SDL_Window and SDL_Surface

Hi, I’m exploring the new features of 1.3, created some windows, already know how to create surfaces, and blit between them, etc.
The problem is although I browsed the wiki, can’t figure out how to blit a surface or texture to a renderer target (SDL_Window )
There is a tutorial that explains well how to create a GL context from a SDL_Window, so OpenGL rendering to a window is easy.
But with SDL_Surfaces, how it’s done?

You have to convert the surface to a texture, and the texture can interact with
the window.________________________________
From: petruzanautico@yahoo.com.ar (Ernesto Borio)
Subject: [SDL] I’m lacking the bridge between SDL_Window and SDL_Surface

Hi, I’m exploring the new features of 1.3, created some windows, already know
how to create surfaces, and blit between them, etc.
The problem is although I browsed the wiki, can’t figure out how to blit a
surface or texture to a renderer target (SDL_Window )
There is a tutorial that explains well how to create a GL context from a
SDL_Window, so OpenGL rendering to a window is easy.
But with SDL_Surfaces, how it’s done?

Ok so the workflow would be: load an image into a surface, copy the surface into a texture, render the texture to a window?

Correct.On Sat, Jan 8, 2011 at 3:52 PM, petruza wrote:

Ok so the workflow would be: load an image into a surface, copy the
surface into a texture, render the texture to a window?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Here’s the process in its most basic form:

  1. SDL_Init to initialize SDL
  2. SDL_CreateWindow to create a window
  3. SDL_CreateRenderer to initialize the window’s renderer (see below notes)
  4. IMG_Load / SDL_LoadBMP to load an image to a surface
  5. SDL_CreateTextureFromSurface to create a texture from a surface (see below notes)
  6. begin event and render loop
  7. SDL_RenderClear to clear the video buffer
  8. SDL_RenderCopy to render a texture to the screen
  9. SDL_RenderPresent to update the screen
  10. end of event and render loop
  11. SDL_DestroyRenderer to clean up the renderer
  12. SDL_DestroyWindow to close and free up the window
  13. SDL_Quit to clean up SDL

Make sure to check for errors before continuing with your code.
When calling SDL_CreateRenderer; if you aren’t picky on which to use simply use -1 for the engine number and 0 for the flags; and SDL will simply use the first one (D3D on Windows, OGL on Linux; dunno about Mac or other platforms)
Use 0 for the first argument to SDL_CreateTextureFromSurface. This way, you don’t need to worry about what texture formats the renderer supports (it’s different between renderers and possibly systems). Presently SDL_CreateTextureFromSurface ignores color key, but that should be fixed quickly.

Hopefully I helped.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

Nathaniel J Fries wrote:

[…]When calling SDL_CreateRenderer; if you aren’t picky on which to use simply use -1 for the engine number and 0 for the flags; and SDL will simply use the first one (D3D on Windows, OGL on Linux; dunno about Mac or other platforms)[…]

Thanks for the extensive list!

So, that’s what the driver index refers to? is there a way to force the app to use OpenGL on every platform? how can I get the info on what driver is each one? ( I tried it on my Mac OSX 10.6 and there are two drivers, but dunno which one is which )

petruza wrote:

Nathaniel J Fries wrote:

[…]When calling SDL_CreateRenderer; if you aren’t picky on which to use simply use -1 for the engine number and 0 for the flags; and SDL will simply use the first one (D3D on Windows, OGL on Linux; dunno about Mac or other platforms)[…]

Thanks for the extensive list!

So, that’s what the driver index refers to? is there a way to force the app to use OpenGL on every platform? how can I get the info on what driver is each one? ( I tried it on my Mac OSX 10.6 and there are two drivers, but dunno which one is which )

You can iterate the graphic drivers using SDL_GetRenderDriverInfo (http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDriverInfo). The number of available graphics drivers can be obtained from SDL_GetNumRenderDrivers (http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers). Then use strcmp on the driver info’s “name” field. The OpenGL value was “opengl” IIRC. It may be better to use strstr for “gl” to account for platforms with GLES instead of GL; too.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/