3d in SDL?

Started by
8 comments, last by nsto119 18 years, 4 months ago
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.
Advertisement
You can use OpenGL with SDL without too much trouble, so yes, you can. Come to think of it, you can use Direct3D with it as well.
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).
Ra
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]
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.
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).
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.
Well I have written 2 different apps that have arrays in them. It appears that Dev-C++ will not make an exe for anything that is using user-defined arrays.
oops wrong thread :S
writing a triangle rasterisation system with SDL would be like designing CAD software with a TI-83

This topic is closed to new replies.

Advertisement