Do I (really) need openGL?

Started by
15 comments, last by Irlan Robson 10 years, 7 months ago
I'm afraid some of these posts are a little misleading.

SDL and it's ilk are not written on top of OpenGL. SDL can be used to get an OpenGL context, but SDL itself does not use OpenGL.

If you're using SDL without OpenGL, you end up drawing to a frame buffer, bypassing the GPU entirely. The way a frame buffer works depends on the OS and the underlying hardware. On many computers, the GPU also ends up drawing to a framebuffer, and all framebuffers are rendered directly to the screen by a video chip (not a GPU).

Either way, if you write pure SDL code, you're not using OpenGL or the GPU.

Stephen M. Webb
Professional Free Software Developer

Advertisement

Either way, if you write pure SDL code, you're not using OpenGL or the GPU.

Don't be so sure about that. A modern OS will use either OpenGL or D3D to even accelerate it's desktop rendering, so ultimately, and even if you do a completely pure software renderer, the OS itself will be sending it through a 3D API which will use the GPU. It may be just "put all of this into a render target and present it", or it may be further up the pipeline, but while you may not be using it directly yourself, you don't have control over what the OS does.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

SDL 1.x used software rendering by default.
I've heard, perhaps incorrectly, that SDL 2 uses OpenGL by default.

SFML (another 2D C++ library) uses OpenGL by default, and definitely is built ontop of OpenGL.

You can perfectly use OpenGL for 2D games, but you don't need to. It'd be easier to use something like SDL or SFML, which may or may not be using OpenGL under the hood to take advantage of the videocard. To do '2D' with these '3D' APIs, they just draw rectangles facing the screen, among other things, allowing them to still use the super-optimized drawing routines of the specialized hardware (the videocard). We could have (and have had in the past) hardware specialized for 2D drawing, but 3D videocards work fast enough for 2D that we no longer have the need for specialized 2D hardware, preferring (to save on the cost of computer hardware) to just do 2D on the 3D hardware and/or with 2D-specialized software. 2D rendering is rather simple after all, and is kinda a 'solved' problem (where with 3D we still hit performance limitations, and continually need to produce better hardware to meet the demands of new software).

You can use SDL or SFML without manually using OpenGL functions and make 2D games just fine.
Even when you move to 3D, you don't *have to* use OpenGL. You might just decide use a 3D engine that wraps OpenGL (or DirectX, an alternative).

OpenGL and DirectX define common APIs for accessing the messy videocard-specific interfaces to the videocards in a consistent way. SFML and some other APIs and 3D rendering engines then wrap OpenGL and DirectX to provide a nicer interface and more higher-level features. By 'higher level' I mean they provide convenience functions and classes that allow you to do common tasks in fewer lines of code than OpenGL and DirectX, in their generalized low-level nature, would require. E.g. doing something in one or two lines of code that might require 20 or 30 lines of OpenGL or DirectX.

So to answer your question, "Do I really need OpenGL?", no, you don't really need to learn OpenGL, but in most your projects you'll likely be using something that itself uses DirectX or OpenGL (or uses something that uses something else that uses OpenGL or DirectX, or... ad infinitum).


I've heard, perhaps incorrectly, that SDL 2 uses OpenGL by default.

There are two ways to render with SDL 2, one via the old surface API and one with the accelerated rendering API. The latter will use D3D on Windows by default, OpenGL or OpenGL ES elsewhere, and a software renderer when neither available. The renderer is configurable during initialization so, for example, an OpenGL renderer can be created on Windows.

In practice, though, I've noticed a lot of people on the SDL mailing list recommending just avoiding the rendering API and create your own in OpenGL, using SDL for context creation and event management. As I understand it, there were some restrictions on the implementation in order to keep the software renderer on par with the hardware stuff. That may change in the future. For now, it's usable for simple 2D (probably for a wide range of games), but anyone wanting to take advantage of the hardware for special effects would need to roll their own.

Thank you all for your input, this is being quite insightful.

I created a pointer of type Toilet so I don't have to go to the bathroom as often.

Probably the guy that posted that, doesn't know anything about OpenGL and it's using another graphics library to do the job. sleep.png

OpenGL can be used to render 2D stuffs too.smile.png

Multi-platform? Answer: Yes, its a must.

Windows? Answer: Yes, along with DirectX. cool.png

This topic is closed to new replies.

Advertisement