7
\$\begingroup\$

I have been studying SDL for a few weeks and I have succeeded in making a 2D Ping-Pong game, but I want to get started in 3D development, and I'd like to know if SDL is capable (and suitable) for 3D game development, or I must use OpenGL?

\$\endgroup\$
4
  • \$\begingroup\$ Have you done some research on the subject? You can use SDL and OpenGL together. \$\endgroup\$ Commented May 27, 2012 at 10:36
  • \$\begingroup\$ @SamHocevar In some forums i have seen that some people use SDL with OpenGL, but do you know any tutorials on that topic? \$\endgroup\$ Commented May 27, 2012 at 13:57
  • \$\begingroup\$ We can't recommend tutorial in this SE \$\endgroup\$
    – Bálint
    Commented Jul 10, 2016 at 19:24
  • \$\begingroup\$ Most relevant questions in this site are closed with "off-topic", what are moderators thinking about??? \$\endgroup\$
    – user124631
    Commented Nov 25, 2020 at 20:52

3 Answers 3

9
\$\begingroup\$

SDL isn't a 3D graphics engine. As is stated in its homepage:

Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.

That "3D hardware via OpenGL" basically means that SDL contains some helper functions to ease cross-platform usage of OpenGL, but you'd still need to learn and code raw OpenGL (which isn't a bad choice if you want to better understand 3D graphics). If you'd like a higher level approach, you should look at some complete 3D engines, such as Ogre or Irrlicht. They use OpenGL underneath (or Direct3D on Windows), but provide easier API with lots of stuff like model loading and scene graph.

\$\endgroup\$
6
\$\begingroup\$

SDL by itself is not meant for 3D (you can make your own software renderer but you wouldn't get very far with it) however SDL does come with an OpenGL wrapper/addon so you can use SDL's windowing, audio, and input system while using OpenGL. Refer to the link in the other post (SDL + OpenGL) for more info and use nehe.gamedev.net for OpenGL tutorials.

\$\endgroup\$
2
  • \$\begingroup\$ TeamFortress 2 was made with SDL \$\endgroup\$ Commented Jul 16, 2015 at 22:45
  • 3
    \$\begingroup\$ Team Fortress 2 (on OSX+Linux, Windows is DX) was made with SDL using their OpenGL wrapper (described above) \$\endgroup\$
    – CobaltHex
    Commented Jul 17, 2015 at 0:51
3
\$\begingroup\$

If you can draw triangles, then you can technically create a 3d engine with it.

However, this involves the same amount of math as you need to do OpenGL if not more.

First, you need to define positions in 3 dimensional space. This is done by using 3d vectors. To render a triangle, you need 3 vectors, one for each vertex of the triangle.

Now, to project a point from 3d to 2d, you just need to divide the x and y positions of the point with the z position. If you done this, then you have a 3d triangle. Congrats.

However, if you render multiple triangles, you notice triangles at the back can overlap the triangles in the front. To solve this you need to sort each triangles based on the distance of it from the camera.

To rotate a model, you need to multiply each vertex of it with a rotation matrix.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .