tags:

views:

77

answers:

1

Hello,

If you create a window by using SDL_SetVideoMode(), you are returned a surface, not a window handle. Is there a way to get the SDL_Window handle? I know there is a SDL_GetWindowFromID function, but I'm also not sure how to get the ID, other than the SDL_GetWindowID function, which would require me to already have the window handle.

Any suggestions? Note that it is very important that I maintain cross platform portability, so I prefer to stick with built in SDL functionality if at all possible.

If it helps any, I'm trying to get and set the window position and window size, and those functions require a window handle.

Thanks!

EDIT: I should mention also that I am changing video modes at the user's request, so I cannot just use the default ID of 1, since this ID changes every time I call SDL_SetVideoMode().

A: 

SDL_SetVideoMode returns a surface based on the video frame buffer, not on a window (just like SDL_GetVideoSurface). You seem to assume that all surfaces correspond to windows, but that is not the case.

Alex Martelli
I'm not using the surface handle it returns, other than to check that it isn't null (to check for errors in initialization). But the SDL_SetVideoMode function takes care of window creation as well. I'd like to get a pointer to the SDL_Window that it creates.
chrensli
@chrensli, I think you're wrong -- can you point me to the spot in the SDL docs where they say that SetVideoMode creates a window? Anyway, to get a full-screen window, why not just use the `SDL_Window` constructor with a parameter of `True` (that parameter's name is `fullscreen`, and it defaults to `False`).
Alex Martelli
http://www.libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode - The flags list contains two flags (SDL_NOFRAME and SDL_RESIZABLE) that seem entirely related to creating a window. But I'm also looking at the source code for this function, and it is using SDL_CreateWindow to create a window. I ended up doing something a bit hacky for the moment - I added an SDL_GetWindow function near the SDL_SetVideoMode function which returns the window handle I was trying to get. But that isn't a good thing to do. I could create a window myself, but there seems to be a lot involved in doing that.
chrensli
Also, most of the SDL/OpenGL tutorials I'm seeing are using nothing more than SDL_SetVideoMode to create their window, which is where I got the inclination to do this in the first place. The function is already properly creating a window for me, so I know it does at least that. And looking at the SDL source, I can see that it is storing the SDL_Window handle in a static variable, but it does not seem to make it available for public use, which is a shame. I'm not sure if there are long term negative consequences to what I did with creating the SDL_GetWindow function.
chrensli
I'm using SDL 1.3, the development branch. I selected this branch because I needed the SDL_SetWindowPosition which doesn't exist in 1.2. The majority of tutorials on the internet use SDL_SetVideoMode, but this is defined in the 1.3 compatibility layer for 1.2 code. Seeing as this is new development, I should be using the new code instead. Thanks for your time. I believe what I've stated about the SDL_SetVideoMode function creating a window is still correct, but it is now a moot point since I am not going to use that function anymore.
chrensli