Sign in to follow this  

3d in SDL?

This topic is 4393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am a noob to the programming scene, and I am about to start learning SDL but I was wondering if you can do 3D graphics in SDL or not. Sorry if this questions is stupid but I'm trying to learn. Thanks for the help.

Share this post


Link to post
Share on other sites
Yes, you can. SDL has an OpenGL interface, so you can use the normal OpenGL calls from within (although you'll need to work around it if you want to use extensions).

Share this post


Link to post
Share on other sites
With SDL, no you cannot do 3D with it's drawing functionality. However, you can do 3D in either OpenGL or DirectX, both of which you can use though SDL to reduce the amount of code you need for setting up the window and creating your contexts. Since you are just starting out, you should first pick between OpenGL and DirectX (there are a lot of threads scattered across the forum about the pros/cons of each) then you can choose a framework for either to make it simplier. With OpenGL you have a wider range of frameworks that eliminate a lot of setup code, but such frameworks do exist for DirectX, SDL being one of them.

[edit]Whoa...magical posts appearing before mine [wink]

Share this post


Link to post
Share on other sites
Well, of course you can do 3D in pure SDL without anything else :) All you need to do 3D is a way to plot pixels on screen. Of course, if you want hardware accelerated 3D, you are going to need OpenGL on top of SDL.

Share this post


Link to post
Share on other sites
Yes, it IS possible to write your own algorithms to simulate 3D perspective in 2D projections, though it can be quite tricky, and particularly with depth swapping. It's not necessary and probably not worth the trouble besides practing your math skills, just saying that you CAN do this. There are many examples of Flash using simple 3D engines, though they bog down quickly when a lot of movie clips are used (Flash seems to hate doing a lot of math).

Share this post


Link to post
Share on other sites
If you decide to use OpenGl with SDL you either look at this example:
http://gpwiki.org/index.php/C:Using_SDL_with_OpenGL
Or just download the SDL code for the Nehe tutorials.
Using SDL with OpenGl is almost like normal OpenGl with some nice additions like Input or that you can manipulate the SDL_surfaces before converting them to OpenGl textures)
One warning: Most SDL+OpenGl tutorials use wrong texture coordinates (images would be vertically fliped if blitted with normal coordinates after converting) though you might need the right coordinates when rendering to a texture for example.
To avoid this you can either write a second function to draw vertizes with flipped texture coordinates or flip the images with a software routine before converting.

Share this post


Link to post
Share on other sites

This topic is 4393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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