Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

2D OpenGL vs SDL2 Advanced Rendering

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Versatus   Members   


Posted 09 October 2013 - 01:03 AM

Hi GameDev! I just joined today. I have been doing some research around OpenGL and 2D games. What I can't figure out is how it would be beneficial to use OpenGL instead of just SDL2's accelerated rendering. I have found that both Terraria and Awesomenaughts use OpenGL. I can understand why they would have used OpenGL before SDL2 but now it seems that SDL2s advanced texture rendering is sufficient.

So if this is not the case then they must be using OpenGL for shaders or particle effects. Particle effects I guess I can understand but shaders I do not. Shaders work with vertices and vectors and seem to inherently require 3Dimensional space.

For example, if I am to make a game with lighting, it seems to me that I can achieve this with alpha blending/color modulation and maybe some raytracing and use SDL2 to render this on screen. I can't see how it wound be possible to do this with OpenGL as light calculations must involve vectors and bouncing off walls in 3d space. It would mean that I would somehow have to translate my 2d tilespace into 3d meshes with vertices and then load shader programs that would understand the nature of my flatspace. Which sseems odd and maybe slower to use an entire mesh per tile or sprite.

I don't mind learning OpenGL, I just want to make sure it's worth it! Maybe I made the mistake of learning SDL2's advanced rendering first, as its just so simple to use.

Any information from the eexperienced would be greatly appreciated. Thanks for reading and am excited to have joined GameDev!

#2 BitMaster   Members   


Posted 09 October 2013 - 02:17 AM

Shaders have nothing to do with rendering 3d. You feed a bunch of geometry to OpenGL and that is rendered to 2d. Whether the source geometry is 2d, 3d or actually n-dimensional is of no concern.
What you do with your shaders is entirely up to you too. If you want lighting, then you will probably have to add some additional meta data with your tiles. If you just want some fancy blending and some glow effects then you can do that too. It should be noted that all effects which you could achieve with some texture combiner work can also be done in shaders, usually far simpler too. You can also do a lot of things you could not do before.

Also note, that if you look at any modern smartphone, they will be using OpenGL ES 2 for rendering their entire UI. OpenGL ES 2 is somewhere between desktop OpenGL 2 and OpenGL 3 (plus a few tidbits minus a few other tidbits) and requires you to use shaders (the fixed function pipeline does not exist there at all).

Can you use shaders for a purely 2d game? Definitely.
Will it be useful for what exactly you have in mind? Impossible to answer for an outsider.

Edited by BitMaster, 09 October 2013 - 02:18 AM.

#3 mhagain   Members   


Posted 09 October 2013 - 03:26 AM

SDL2's accelerated rendering is nothing more than a software wrapper around OpenGL or Direct3D.  By using OpenGL (or D3D for that matter) you bypass the wrapper and get to use the underlying API directly, which can give you more control but at the expense of greater complexity.  Whether or not you need that extra control is a question only you can answer.


In the case of your lighting example, it's perfectly possible to do this via OpenGL, and I can say this (and you can believe it) with extreme confidence because (as I've noted) that's how SDL2 does it too.


Right now SDL2 is working fine for you, so I don't think you need to consider using something else for the moment.  As you do more work, get more experience, get more ideas for cool stuff you'd like to do, you're going to start running into obstacles and things that SDL2 can't do so well.  At that point the greater control of the underlying API will be needed, and maybe a good starting point for you might be to look at the SDL source code and understand how they did it, in conjunction with some more specific learning material.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

#4 Versatus   Members   


Posted 09 October 2013 - 11:48 AM

Perfect answers, thanks alot guys for the insight. Knowing that SDL uses OpenGL under the hood(notably depending on the environment context I am sure) is all I really need to know, as SDL is going to inherit whatever performance cost their is with OpenGL anyway theoretically. I believe then it's best if I just get started cracking on with OpenGL as I suspect I am going to need shaders and other features in the future. As I have the source for SDL I shall study it and see how it works. Thanks!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.