Skip to main content
GameDev.net gamedev.net
🔒 Locked

Could SDL render in another window?

Started by Mari_p Jan 16, 2007 at 8:29 AM 4 replies 4.8k views
Original Post
Mari_p
Mari_p
Hi, Is there a way 'of forcing' SDL to render in another window? That is, does SDL provide a function where we could pass a window handle in? Thanks in advance
coding penguin
coding penguin
Quote:
Original post by Mari_p
Hi,

Is there a way 'of forcing' SDL to render in another window? That is, does SDL provide a function where we could pass a window handle in?

Thanks in advance


you mean render with SDL to window created in winapi? i don't think it's possible... why you want do that? why you don't create window with SDL?
ciroknight
ciroknight
Mari_p: No, SDL for the most part is windowing-system agnostic (it has a few routines to modify its own windows, but that's as far as it goes; it can't even make its own window frame disappear, for example). This is because it has to use different toolkits on different operating systems.

However, this shouldn't discourage you, especially if you're just using SDL to render something, then bring it into your program. It's entirely possible to have SDL draw everything to an off-screen buffer, then just grab that buffer and run with it (use it however you like). In theory, depending on the operating system, you could overwrite the pixel data of the other window or widget within a window with the pixel data from the SDL.

The function you're looking for is SDL_CreateRGBSurfaceFrom(), and for reference, the pixel data of an image surface is stored in SDL_Surface->pixels (so you could memcpy it, for example). These are nice to know, because sometimes you'll want to use a buffer you've already drawn something to in software and load it as an SDL_Surface, or if you're wanting to implement a screenshot routine, you can copy the pixel data and save it as a file.

Hope that gives you a starting point.
Mari_p
Mari_p
Quote:
Original post by lulul
why you want do that? why you don't create window with SDL?

Thanks for replying, lulul.

It is not for games... I would like SDL could render in the forms of VB, Delphi and C#. I already did that using Direct3D and work perfectly.


ciroknight: Thank you very much for the valuable reply. I will look at SDL_CreateRGBSurfaceFrom() function.
rip-off
rip-off
Quote:
Original post by ciroknight
it can't even make its own window frame disappear, for example


Sure it can, use SDL_NOFRAME


You can use the env variable SDL_WINDOWID to tell SDL which window to use. It is a bit of a hack, im not sure if you can change where SDL will draw inside the window or does it assume control of the entire window, which may be what you are trying do.

Using SDL as an offscreen renderer is probably the best way to use SDL to draw to certain areas of an existing window.
let_bound
let_bound
Quote:
Original post by Mari_p
Hi,

Is there a way 'of forcing' SDL to render in another window? That is, does SDL provide a function where we could pass a window handle in?

Thanks in advance


Yes. Get the window ID (on Windows, that's the HWND), and set the environment variable SDL_WINDOWID before calling SDL_SetVideoMode. I'd post a link, but the SDL website is just slow today, and my knowledge of Windows programming is rusty to say the least (I'm a *NIX head and I code mostly in OCaml lately).

There is an example for Win32 at http://www.maccormack.net/~djm/sdl_win32_demo/.

You can find a list of the environment variables used by SDL at http://www.libsdl.org/cgi/docwiki.cgi/Environment_20variables.


Quote:
Original post by ciroknight
However, this shouldn't discourage you, especially if you're just using SDL to render something, then bring it into your program. It's entirely possible to have SDL draw everything to an off-screen buffer, then just grab that buffer and run with it (use it however you like). In theory, depending on the operating system, you could overwrite the pixel data of the other window or widget within a window with the pixel data from the SDL.

The function you're looking for is SDL_CreateRGBSurfaceFrom(), and for reference, the pixel data of an image surface is stored in SDL_Surface->pixels (so you could memcpy it, for example). These are nice to know, because sometimes you'll want to use a buffer you've already drawn something to in software and load it as an SDL_Surface, or if you're wanting to implement a screenshot routine, you can copy the pixel data and save it as a file.


If I understand what you're saying, and what the OP wants, this won't work. SDL_CreateRGBSurfaceFrom requires that SDL_SetVideoMode has been called first, and that call will open its own window. AFAIK the only way around that is the above hack, short of modifying the SDL source code.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.