Sign in to follow this  
donjonson

Using SDL for window Creation?

Recommended Posts

I am wondering if there is any disadvantage to using SDL for window Creation even if my game uses directX for all the graphics rendering. Right now I am creating my window using all that windows api garbage. it seems rather convoluted just to create a window. Can you easily make a GUI with SDL?

Share this post


Link to post
Share on other sites
SDL generally expects to have one window and only one window. It may be possible to make more, but I haven't tried, and it would probably be rather strange to do.

You can NOT mix SDL and DirectX. It's not a situation of one handles the drawing and the other handles the windows, it's a situation of each trying to do everything itself; drawing, window-management, sound, the whole shebang.

There are GUI packages for SDL out there, but they aren't wrappers for the Windows API, they're entirely new GUI's, meant to be drawn as part of a game. If you want a Windows-ish GUI without the Windows API, look at other GUI toolkits like GTK, wxWindows, TK, things like that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
Both the original poster and Icefox might want to read this.

Direct3D 9.0 with SDL


The whole purpose of SDL is to have a portable application.
If you use DX and SDL, you are kind of.. well, defy the purpose of SDL.
Why not just use OpenGL with it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Raduprv
Quote:
Original post by Kylotan
Both the original poster and Icefox might want to read this.

Direct3D 9.0 with SDL


The whole purpose of SDL is to have a portable application.
If you use DX and SDL, you are kind of.. well, defy the purpose of SDL.
Why not just use OpenGL with it?


Because some people prefer DirectX over OpenGL, but they despise the Win32 API, so they look for easier solutions (SDL, or they write their own wrappers (however this is time-consuming, and why not just use something that's already there?)). Also, just because SDL is cross-platform doesn't mean you HAVE to use it's crossplatform capabilities, and somebody who preferes DirectX obviously isn't too interested in cross-platform work.

Share this post


Link to post
Share on other sites
SDL's API is pretty similar with the Win32 API (it's procedural, for example). I can't see how you can hate Win32 but like SDL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Raduprv
SDL's API is pretty similar with the Win32 API (it's procedural, for example). I can't see how you can hate Win32 but like SDL.


Well, mostly it's because SDL only takes about 2 lines of code to get a window up on the screen (well, 3 if you count declaring an SDL_Surface), wheras with the Win32 API it takes a couple of hundred lines to do the same thing (unless you're using MessageBox, but you can't use that with DirectX). Sure, they're both procedural, but one looks nicer and takes less code, and the other one takes up lots more space and looks rather cryptic to the majority of people.

Share this post


Link to post
Share on other sites
Yes, but most of the programmers already have a copy and apste ready code to create the basic stuff (set up an window, get the surface, etc.)
And, unless it's a quick prototype, your init code is far, far smaller than the rest of your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Raduprv
Yes, but most of the programmers already have a copy and apste ready code to create the basic stuff (set up an window, get the surface, etc.)
And, unless it's a quick prototype, your init code is far, far smaller than the rest of your code.


Good point. I guess it's just a matter of choice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Raduprv
The whole purpose of SDL is to have a portable application.
If you use DX and SDL, you are kind of.. well, defy the purpose of SDL.
Why not just use OpenGL with it?


I'm going to have to disagree with you on this one [smile]

Reasons why I would want to use DX and SDL:

1. Smaller base code size:
In ~163 (Without of comments and with code that does fonts) lines of code, you can setup SDL and D3D and have a framework ready to run and use. Compare this to traditional methods, and it's quite an improvement (roughly 1/3 of that required with NeHe 3D, which is just a blank window).

2. Easier Input:
Input with SDL is quite easy compared to DirectInput and you can make an input system that can nearly rival that of DI with a lot less code. I know because I've had to write input libraries for both APIs. Yes, with SDL, you will not have access to Force Feedback, but then again, I don't recall using it when I made the DI class [wink]. For mouse and keyboard, you can get the same thing that DI provides with SDL.

3. Easier Sound:
With SDL you have access to SDL_Sound and SDL_Mixer. Then there are other libaries that you can use, such as SMPEG that you can use for MP3 if needed, Timidity for MIDI, then OGG and Wav are supported by default. There is no messing around with DirectSound or DirectMusic, or having to jump though the DirectShow hoop (something I see done a lot in the DX forum).

4. 'Extras':
With SDL you have easy access to threads, the CDROM device, networking (SDL_net), and SDL_RWops. Extra features like these you can add in to use in your game with relative ease. Of course with networking now with DX, you will have to use something other than DirectPlay.

5. Access to Win32:
With SDL you still have access to all the Win32 stuff. For example, if you need the windows HWND, it's easily obtainable! With that you can then do all the window movement, sizing, and anything else you want with it.

6. Comparison of DX and OGL easier:
We all know that DX and OpenGL do not work the same on all cards. YOu can have OGL code that works fine on NVIDIA, but messes up on ATI cards, and vice versa. Most of the time, people don't bother testing both APIS, but if you were to, doing it via SDL would require a lot less code and more reason to than if you used Win32. (I acknowledge this is not the best supported argument, so please no one debate me on this)

Well that's what I think, to each their own though [grin]. I think SDL provides a good interface to both API's and if utilized correctly, you can get some niec stuff made with it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this