Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been teaching myself the OpenGL library for a while now, and want to start making a game. However, for an easier introduction, I want to start with something 2D, such as a top down Pokemon-style game.

Is this a good plan, or is OpenGL made specifically for 3D?

share|improve this question
I think that one benefit that using OpenGL for 2D has, is that you get the benefit of shaders. These could be useful for achieving special effects. Another benefit, is that if you already know OpenGL, you will already be familiar with the API. – Aidan Mueller Feb 24 '14 at 6:06
up vote 37 down vote accepted

OpenGL is quite appropriate for 2D games. Although it is generally used for 3D, the same functionality can be used for 2D games. That is to say, anything you can do with 3D OpenGL will be applicable with "2D" OpenGL.

Some further information can be found at this location.

2D OpenGL is achieved in the same manner that 3D OpenGL is. 2D OpenGL is only the application of a technique, that is, rendering the scene on a flat plane, then using and orthographic projection instead of a perspective projection, which, depending on your setup, could distort the scene.

An example:

Ortho vs perspective

(a) is a scene in an orthographic projection. (b) is the same scene, using a perspective projection. In a 2D game, this can cause mis-positioning of sprites if their depth is altered (which, depending on how you go about development, may be the case). Using a perspective projection also makes aligning things in screen coordinates more difficult.

In addition, OpenGL carries many, many, many benefits with it. Primarily, hardware acceleration is a huge plus. There's also a much finer degree of control over what the graphics card does and how it goes about it, allowing for case-specific optimizations

share|improve this answer
Thankyou very much! I just wanted confirmation that it would be OK to do this. – w4etwetewtwet Jul 15 '13 at 16:37
If you have the aptitude and interest to use OpenGL for 2D, it will bring you plenty of rewards that only OpenGL can give. Blistering performance, cross-platform compatibility... Think of it this way. Almost all other choices for 2D would be built on top of OpenGL anyway. It's a great opportunity to cut out some "middlemen" – Steven Lu Jul 15 '13 at 23:03
@StevenLu and not to mention, being slightly more of a real programmer – Outurnate Jul 15 '13 at 23:05
Great read! Thanks for linking that. Yup: coding your 2D with straight OpenGL is just more badass so that is why you should do it. – Steven Lu Jul 15 '13 at 23:33
You should provide more information to this answer rather than just a link. Maybe explain why GL works for 2D (orthographic views) and what advantages it brings (hardware acceleration, shader effects). – Sean Middleditch Jul 16 '13 at 21:23

OpenGL as the name states is a graphics library. Although it is developed with 3d in mind, there are no hardcoded assumptions in the library that you'll be using 3d. Moreover, thanks to it's 3d capabilities, several things that would be hard to do in a strictly 2d approach are trivial. Examples:

  • Z-sorting is simplified by using 3d coordinates the depth buffer (watch out for transparency though)
  • sprite rotation and scaling is basically for free as you're using textured quads that are independent of the resolution
  • if you're willing to restrict yourself to OpenGL 2.0 capable graphics cards you can take advantage of shaders, which will simplify writing special effects a lot (blurs, particle effects, image manipulation, color substitution) -- not to mention that it will be a lot faster than done CPU-side

This is only a few advantages that come from the top of my head, I guess there are several others.

share|improve this answer
Please do restrict yourself to OpenGL 2.0 (or greater) capable graphics cards, OpenGL 2.0 was released in 2004, even that is pretty outdated. – Slicedpan Jul 16 '13 at 8:32
@Slicedpan, unfortunately some laptops/netbooks still come with Intel cards that have GL 1.4 max support -- personally I decided to ditch them, but some people (especially when making simple games) might want to support them. – Kornel Kisielewicz Jul 16 '13 at 13:59

While OpenGL is a 3D API, you can still use it to make 2D games. You can fake a 2D environment in 3D through various techniques, such as contraining data to a plane.

However, there is limited support in the actual API for doing this in an obvious fashion (there's no "turn on 2D mode" function, for example). The ways in which you'd simulate it (which you can find in many tutorials online) may be difficult to fully understand without some understanding of the 3D pipeline that is actually being used under the hood.

It sounds like you have been looking at OpenGL for a while and so probably have a decent grasp of those fundamentals. However, if you feel shaky on them you may want to start with your game by using a 2D library that is built on top of OpenGL, such as cocos2d. It will give you some experience with what 2D APIs generally should look like and still gets you the benefits of a hardware-accelerated 3D back-end, if you feel like you aren't quite ready to tackle the whole thing on your own.

share|improve this answer
OpenGL is in some sense a 2D API – user7610 Oct 31 '14 at 11:10

Many 2d graphic libraries like SDL or SFML make use of OpenGL hardware acceleration. This gives you the performance benefit of OpenGL, but abstracts the nasty low-level details behind a much simpler API.

share|improve this answer

I now have a lot of experience in OpenGl programming, and I can tell you it is a pain. In the past when I started programming I was very productive in simple environments like BlitzBasic. Then I started to go into the next step with learning C++ and OpenGl. And when you do not have a good teacher or people to ask, you will permanently run into the black screen. The biggest problem is the state hell of OpenGl. There are tons of switches that you can swap to change the state of opengl. And some switches depend on other switches. for example glGet(GL_TEXTURE_BINDING_2D) depends on glGet(GL_ACTIVE_TEXTURE). And the documentation which state depends on which other state is not the best. Many operations like texture loading requires you to change this state which very often leads to the breakage of other code that requires the old state. And then there is this problem that OpenGl as implementation dependant behavior, so that your program runs on your machine but on the other machine all you see is black. All you can do here is guessing what is wrong in your 10000 lines of code. So if you like frustration then yes use OpenGl for 2D things. To all other people, don't do it if you don't need it. You can get productive in OpenGl, but it will cost you a lot of your time and nerves. Propably more than you want to spend.

share|improve this answer

Unity3D uses OpenGL, and I use it for 2D and 2.5D platformers. Unity3D is essentially a 3D Gaming Engine, but is also is used for 2D and 2.5D games as well. You can have x, y, z planes and only limit the movement or rotation to 2 of those planes, creating a 2D atmosphere in essentially a 3D world.

share|improve this answer
Great, my first downvote. Glad to see gamedev has haters too. – ApolloSoftware Jul 16 '13 at 18:57
I guess illustrating a point through real world examples is frowned upon. Very professional. – ApolloSoftware Jul 16 '13 at 18:58
Amit, downvotes do not indicate "haters". Downvotes are simply a way for the community to convey their opinion of questions and answers. It's not personal to you, so try not to take it that way. I agree that the downvoter should have commented on the reason for the downvote, since you don't know how to improve the answer without feedback. I'll tell you why I think it was downvoted. Just because one individual uses OpenGL for 2D games, does not mean on a whole that it's appropriate. You also need to give reasons as to why it's appropriate. – Byte56 Jul 16 '13 at 20:19
Thanks Byte56 for the explanation. I was conveying my frustration with the downvote cause I felt my answer was pertinent to the situation at hand since it was indeed plausible. The question asker was inquiring as to "is OpenGL made specifically for 3D?", I was merely trying to negate that notion by my own real world experiences. – ApolloSoftware Jul 16 '13 at 20:34
Yeah, not sure why people are downvoting; the "uses OpenGL" bit I felt should be clarified with "uses OpenGL on platforms that require it" (it uses Direct3D or console-specific APIs everywhere but iOS/Anrdoid/OSX/Linux), but that's more a clarification than a correction. – Sean Middleditch Jul 16 '13 at 21:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.