Introduction

Ok... so you want to learn modern OpenGL. Great! But what does it really mean and what options are available? Do you have to buy expensive books about this technology, or maybe some basic online tutorials are enough?

In this article, I will try to answer some of the questions above and create a guide to a wonderful world of graphics programming using OpenGL.

What is the difference? This is quite a broad topic, but for now I think it is good to know that fixed pipeline was like a black box. You inserted the vertex data in the front (at the input) and you got triangles written to the framebuffer (screen) at the end. You could of course tweak this box to your needs but at some point, it was not enough.

Programmable pipeline is more like a white, transparent box where not only you put input data and wait for the result, but you can insert/change internal mechanisms as well. There is a general form of the pipeline, but a lot of parts are fully controlled by you - thanks to shaders.

Shader is a little program that can compute various things and is run on the GPU. It can transform vertices, calculate color of fragments, delete or add more triangles and even more.

To illustrate this idea, I prepared two images:

Idea of a fixed graphics pipeline

Idea of a programmable graphics pipeline

Although the images above are very very simplified, they show that programmable pipeline is much more flexible and more control is in the hands of a programmer. Thanks to shaders, one can create a lot of graphics effects that was not possible with fixed pipeline.

Currently, with new releases of graphics API (like OpenGL or DirectX), we get more and more control over the GPU. If we look at modern games' engines, we will see that great parts of it are run completely on GPU. Thus is it important to learn the modern way.

OpenGL Major Versions

Version

Important changes

1.1 - March 1997

Fixed pipeline! Note that the version 1.0 was released in 1992.

The latest 1.x version is 1.5 from July 2003 (includes, for instance, VBO and occlusion queries).

Where to Start?

When we understand our motivation, we are able to start learning. Sometimes it is quite a hard task though! There are plenty of available resources so a person can be lost and lose his/her initial passion.

OpenGL Superbible became a standard book for learning OpenGL, and actually I cannot suggest anything different that that. Going back into my history, this was my first book about graphics programming. At that time, I had the first edition! Now we have the 7th (released on August 2015)

The Structure

Basics: First triangle, the graphics pipeline, math, buffers, shaders. This is a nice journey through the pipeline so that you can get a overview of how it works.

Advanced techniques: compute shaders, pipeline monitoring, loading, and arbitrating access to data, artistic and non-photorealistic effects. AZDO Techniques and how to debug OpenGL Applications. There is even a chapter about not core, but very important extenstions like Sparse textures and bindless graphics.

The latest version of the book focuses on OpenGL 4.5. This is important because in OpenGL 4.5 we should be using direct state access functions rather than bind and update.

Older versions of the book contained chapters about Platform specifics.

The book gives all the information needed to start and even become quite proficient with OpenGL. The book is both for beginners but also for people very familiar with graphics APIs. as you can see, there are basic chapters, as well as very advanced topics. The writing style is great and no one should have problems with understanding it. The size is around 1000 pages. I guarantee that you'll be often returning to the content of this amazing book.

Cookbooks

The idea of programming recipes was quite new to me, but I liked it from the beginning. In both mentioned books, there are lots of different sub-chapters that could be read almost in any order. We usually start with some simpler examples and move towards advanced ones, but still the structure is more loose as with 'common' programming books.

OpenGL 4 Shading Language is a great resource for learning almost the newest version of OpenGL - 4.3. It was refreshed recently and the content got even better. We have the following topics covered:

The first two chapters introduce to GLSL and modern OpenGL

Another two about Lighting and Texture usage (for instance, immutable textures!)

The second book - OpenGL Development Cookbook - has a similar style as the first one. It uses OpenGL 3.3 - so a bit older, but still valid. The book describes similar areas: introduction to OpenGL, GLSL, lighting, shadows... but examples are different than in the first book. You can compare examples and get some new perspective and coding techniques.

What is important, OpenGL Development Cookbook adds some other valuable chapters to our graphics knowledge bag:

Volume rendering

Global illumination

3D Mesh file formats

Animation systems and physics

All in all, you could treat both of those books as one pack. BTW: you can read my full review of OpenGL Development Cookbook in a separate codeproject article.

Those two cookbooks have great value for me because they fill a niche among graphics programming books. At one side, we have introductory level books like SuberBible, on the other side there are more 'hardcore' books like GPU Pro or ShaderX (and recent OpenGL Insights). The cookbooks fall in the middle and are great resources for anyone with some good OpenGL knowledge who wants to go further.

Is C++ Always Needed?

As you have probably noticed, all of the mentioned books and websites used C++ as a language for code samples. C++ seems to be the most popular choice in this area. But if you know other languages, you are not doomed!

It is worth noticing that no matter what programming language you chose, the graphics theory is the same. So if you know how to make a graphics effect in one language, then it should be relatively easy to do it similarly in some different language.

The Hardware

Currently (December 2014, latest drivers) most of recent desktop GPUs will support OpenGL 4.* or at least 3.*.

AZDO

Some time ago (at GDC 2014) there was a great presentation delivered about achieving even more performance with OpenGL. This whole set of ideas is called AZDO - "Approaching Zero Driver Overhead". As the name suggests this approach focuses on minimalizm the driver work. Very often gpu has a lot of available power, but it has to wait for the driver to finish some work.

Short summary of techniques:

How to update buffers so that they do not create stalls in the pipeline (fe persistent_mapped_buffer, orphaning, multi buffering)

AZDO is complicated but powerful. It can unlock a lot of power in your engine. This is also a good starting point for new graphics API like do DirectX 12 or Vulkan - in which the driver will be minimalistic and all the work will be dependent on clients(programmers).

OpenGL Next and Vulkan?

Announced at GDC 2015 in San Francisco, and then officially published on February 16th 2016 (Khronos), Vulkan is a new API that should unlock even more power from the hardware.

From the official Khronos presentation:

As you can see with Vulkan we'll get more direct control over GPU/CPU. The driver work is minimized. Of course, Vulkan is multiplatform: from high end PC to low end mobile devices (Except for Mac OS). Theoretically, we should see more framerates, more object on the screen and better hardware utilization.

The flexibility and performance comes at some cost though. You get the control, but most of the things the driver did (synchronization, buffere management, shader management, multithreading, command buffers) will have to be handled by your engine. Large engines do such management anyway, thus they should benefit the most. But if you're doing a simple simulation, with basic rendering that can hurt. Even simple Vulkan demos contains hundreds of lines of code just for some basic stuff.

While not for everyone, Vulkan brings a lot of promises. It's completely new, so there is no overhead of the legacy functionality. If you take graphics programming seriously, please check out code samples and Vulkan examples.

Conclusion

In this article, I tried to give you enough resources to start and make good progress with graphics programming. OpenGL is a very popular technology right now. A lot of new possibilities will be available for anyone with decent graphics API experience. You can not only make AAA game engines, but also move into web or mobile development. And with Vulkan there's even more (low level) fun!

best wishes and good luck with the app. In the article I've focused mostly on desktop OpenGL, but in these days with OpenGL ES 3.0 on mobile devices we have also lots of techniques to use. This is huge OpenGL win that it can be used in so many platforms.

I have some experiences with 3D programming with DirectX. There is a question of which I'm always finding a chance to get the answer.

Since this article is about GPU programming and I have seen many papers talking about accelerating applications with GPU, like image processing, I wonder how, and what kind of apps this technique can be used to speed up things.

I would appreciate your help if you can provide me some clues or points.

Your question is a quite broad topic. In general, you can gain perf improvements in problems that are highly parallel. Since GPU has lots of small cores it's best suited for computing independent tasks. If the problem is more linear then normal CPU would be better.
So as you see most of image processing algorithms are perfect for GPU (you usually compute something for each pixel in the image)

Of coarse, the old OpenGL will still be there, but it won't be compatible with Vulkan. I think a lot of developers will switch though, for two reasons:
1) Vulkan seems more complicated, but in reality it's easier to use because it's more logical. The global state concept of OpenGL is very confusing. It's much more logical working with command buffers and you don't have to tie yourself in knots trying to reduce draw calls.
2) current hardware is already compatible with Vulkan - no need to buy a new GPU.

Having said that Vulkan hasn't been released yet, so somethings are not very clear. In particular, it's not clear if Apple will support it and that would be a major blow to Vulkan if they decided not to.

correct
Vulkan will have probably more tools and also has nice idea of swappable layers - for instance debug/validation layer (that could be used in development, but removed for the final release).
I am also very excited about this new technology.