Click here to Skip to main content
Click here to Skip to main content

Learning Modern OpenGL

By , 13 May 2014
Rate this:
Please Sign up or sign in to vote.
Shaders + Cube Env Map + Phong Lighting
Shaders + Cube Env Map + Phong Lighting

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.

Let us start!

Why Modern?

The first question I would like to answer why there is a term called 'modern OpenGL'. Is there 'old OpenGL ' as well?

Basically modern means "using programmable graphics pipeline", old means "fixed pipeline".

What is the difference? This is a quite 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
2.0 - September 2004
OpenGL Shading Language officially in the standard. Pixel buffer objects, sRGB
3.0 - August 2008
Deprecated features list, Frame buffer objects, floating point textures, transform feedback, Core Profile, Geometry shaders, synchronization objects. OpenGL 3.3 can be compared to DX 10
4.0 - March 2010
Tesselation shaders, draw indirect, ES2 compatibility, program binaries, separate shaders objects, Compute shaders. OpenGL 4.4 can be compared to DX 11.1 or even supersede it.

What you should learn?

I suggest the following topics for the beginning:

  • General knowledge about the computer graphics
  • Platform differences (PC vs Mobile vs Web vs Console)
  • Graphics Pipeline - steps
  • 3D Math - matrices, vectors, projections
  • Camera models
  • Shaders (Vertex and Fragment)
  • Texture projection
  • Basics of Buffers
  • Basic lighting models

Then:

  • Shaders (Geometry, Tessellation, Compute)
  • Advanced memory management with buffers
  • Shadows
  • Global Illumination
  • General Computing on GPU (OpenCL, CUDA, Compute shaders)
  • ...

I left the second list unfinished on purpose. By the time you reach these points you will definitely have a more clarified perspective on what you want to achieve and how to get where you want

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.

I suggest starting with a good beginner level book. One of the best is OpenGL Superbible. This was my first book about graphics programming. At that time I had the first edition! Now we have the 6th.

The structure:

  • Basics: first triangle, the graphics pipeline, math, buffers, shaders
  • Details: Vertex, Primitive and Fragment Processing, the framebuffer, compute shaders,
  • Techniques: lighting, shadows, cell shading, performance
  • Platform specifics

The last chapter, about OpenGL Platforms, gives a high (and low) level overview about OpenGL usage. We can find it not only in desktop platforms (among various operating systems), but even inmobile (OpenGL ES 2.0 and 3.0) and Web (WebGL in HTML5).

The book gives all the information needed to start and even become quite proficient with OpenGL. The writing style is great and no one should have problems with understanding it. The size is around 1000 pages so even more experienced user can use it as a reference.

It is also worth mentioning that there is a lot of online content that can help you. One of the best available tutorials about modern OpenGL (3.3+) comes from Jason L. McKesson in his arcsynthesis tutorials. Another good site is open.gl and lighthouse3d core.

Where to Continue?


Normal Mapping with GLSL

When you have the base and know how to use OpenGL then you can choose in what area you want to go.

Some time ago a person would usually go into rendering engine development - meaning more graphics effects. But today we also have web and mobile apps so your focus can be different.

For 'normal' graphics development I suggest investing some money in two books that appeared recently - two cookbooks actually!

One of them is OpenGL 4 Shading Language Cookbook and the second one is OpenGL Development Cookbook.

Cookbooks

The idea of programming recipes was quite new to me, but I liked it from the beginning. In both of 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!)
  • Chapter 5 about image processing and screen space effects (like blur and hdr).
  • Then there is a chapter about tesselation and geometry shaders.
  • Chapter 7 covers Shadows techniques.
  • Two other describe Noise and Particle animations
  • Then, the last one touches Compute shaders

Those topics create a very decent base for any graphics programmer.

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 alike 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.

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!

OpenGL is only API and there are lots of different language bindings.

So:

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 than it should be relatively easy to do it similarly in some different language.

Resources and Links

Conclusion


Water on GPU + Normal Mapping Source: Simple Water Simulation

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.

Have a nice journey with Modern OpenGL!

You can also see more about OpenGL at Bartek's blog: http://www.bfilipek.com/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Bartlomiej Filipek
Software Developer
Poland Poland
Software developer interested in creating great code and passionate about teaching.
 
Technologies I use(d): C++, C#, JavaScript, OpenGL, GLSL, DirectX, OpenCL, CUDA, Windows Api, MFC, Visual Studio and even HTML and CSS.
 
See my programming blog: www.bfilipek.com
Follow on   Twitter   Google+

Comments and Discussions

 
You must Sign In to use this message board.
    Spacing  Noise  Layout  Per page   
QuestionWhich OpenGL version to target for DX9.x graphics card? PinpremiumWong Shao Voon13-May-14 22:04 
AnswerRe: Which OpenGL version to target for DX9.x graphics card? PinmemberBartlomiej Filipek13-May-14 22:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140512.1 | Last Updated 14 May 2014
Article Copyright 2014 by Bartlomiej Filipek
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid