[home]

Anton's OpenGL 4 Notes

About a year ago I started teaching myself OpenGL 4.2 for teaching. This was new, because most of my graphics experience was with older "fixed-function" libraries that work mostly on the CPU. OpenGL 4 is very different to OpenGL 2.1. In code there is no more glBegin() and glEnd(). The problem-solving approach is also different, as most algorithms are implemented in shader programmes where your algorithm is designed to suit the hardware.

It is very hard to find reliable information on programming with OpenGL 4.x, so I intend to update these pages as a series of mini-tutorials for common techniques, and also to discuss some of the weird, wonderful, and frustrating coding issues that I run into... hopefully with solutions!

I usually say something on Twitter Follow @capnramses when I write a new article. Please let me know if you spot a mistake.

I'm currently re-writing my tutorials. Only the tutorials with thumbnails are finished - in the mean-time you might like to check out my previous OpenGL 4 wiki for tutorials on the the missing topics.

I'm also using these techniques in a video game that I'm making called Crongdor the Barbarian which you can read more about at www.crongdor.com

Latest Changes
10 May 2013 - Normal Mapping tutorial
08 May 2013 - Distance fog tutorial.
07 May 2013 - Spotlights article. Added a diagram to Overlay article. Added notes to Vertex Buffers about how enabling attributes works. Fixed bug in attribute binding code in Overlays tutorial.
03 May 2013 - Overlay Panels.
01 May 2013 - Particle article. Mac notes in Hello Triangle.

Basics

"Hello Triangle" easy. 2 hours. Minimal code to draw a triangle using simple shaders and vertex buffers.
Extended Initialisation easy. 2 hours. Specifying OpenGL version, configuring the display, getting driver information, extension handling with GLEW, and adding a frames-per-second counter.
Shaders moderate. 2 hours. Shaders determine the style of rendering.
Vertex Buffers easy. 2 hours. Vertex buffers hold the mesh data to render. We add a vertex buffer with colours to our triangle and show vertex-fragment interpolation.

Transformation

Matrices and Vectors moderate. 2 hours. A light introduction to using vectors and matrices in OpenGL 4 for moving, scaling, and rotating, and some basic animation.
Virtual Camera moderate. 2-4 hours. Building a transformation pipeline to add viewpoint and perspective to a scene.
Quaternion Quick-Start moderate. 2-4 hours. A simple explanation of quaternions, and how to write your own quaternion code for 3d (actually 4d) rotation. Useful for full rotation (rolling balls, wheels, etc.), and interpolating rotations in animation.
Ray-Based Picking moderate. a couple of hours. Cast rays from mouse pointer to various primitive "bounding" shapes.

Lighting and Texture Maps

Phong Lighting moderate. ~1 day. Shading a scene with virtual lights.
Texture Maps moderate. 2-3 hours Loading images from files. Texture coordinates. Sampling textures in shaders. Mip-maps and filtering.

Tips and Tricks

Screen Capture easy. 1 hour. Simple function to save a screenshot to a file.
Video Capture moderate. 2 hours code. 2 hours processing. Extending the screen capture function to create a video from a regular series of screen dumps.
Debugging Shaders easy. 2 hours Methods for graphically "debugging" a shader programme part-by-part.

Mesh Files

Importing a Mesh File easy. 2-4 hours Choosing a file format, exporting a mesh, importing with the AssImp library, and copying into vertex buffers.

More Advanced Lighting and Texture Effects

Multi-Texturing easy. 1 hour Blending textures together for various effects.
Using Textures for Lighting Coefficients easy. 2 hours Specular Maps, Diffuse Maps, Emission Maps, and Ambient Occlusion Maps.
Fragment Rejection easy. 30 minutes They'll get over it. Tell a fragment not to draw at all for "all or nothing" transparency.
Alpha Blending for Transparency easy. 1 hour Techniques for managing geometry with transparent or semi-transparent parts.
Spotlights and Directional Lights easy. 1 hour. Some variations on lighting directions for interesting effects.
Distance Fog easy. 1 hour. Add fog, gloomy darkness, or a subtle colour fade to aid the perception of distance.
Normal Mapping moderate. 1 day. A "bump mapping" lighting technique/optical illusion - the easy way (using tools).

New Shader Stages

Geometry Shaders easy. a couple of hours. Extrude or delete geometry on-the-fly using a geometry shader.
Tessellation Shaders moderate. a few hours. Automatically generate more detail inside surfaces using new GPU hardware.

2D Rendering

Overlay Panels easy. an hour For debugging and user interfaces.
Sprite Sheets and 2d Animation moderate. several hours.
Bitmap Fonts moderate. a day or so per font. Using a font atlas and hand-drawing custom fonts.
Making a Font Atlas Generator Tool moderate. a day or so. Using the FreeType library to generate a font atlas and layout meta-data from a font file.

Animation

Vertex Displacement Animation easy. ~2 hours. Using functions in a vertex shader to do effects like waves.
Particle Systems moderate. ~4 hours Create special effects in canned systems.
Hardware Skinning hard. several days Deforming a mesh by manipulating a "skeleton"/armature.
Morph Target Animation (slides) moderate. 4 hours Using interpolation between animation "targets".

Multi-Pass Rendering

Switching Framebuffer moderate. 2-3 hours. The foundation of all multi-pass technques. Render to a texture instead of the screen. Reuse that texture. Just need to type it up...
Post-Processing Effects fiddly interface. about a day Create fancy filters to do effects over the whole screen after everything is rendered. Just need to type it up...
Colour-Based Picking fiddly interface. about a day. Render unique things to special colours (but don't show them). Test which special colour the mouse cursors is over. Just need to type it up...
Screen-Space Ambient Occlusion (SSAO) about a day A post-processing effect that fakes subtle shadows around concave areas. Just need to type it up...
Deferred Shading fiddly interface. about a day. Compute lighting in 2d (once per pixel, not once per overlapping fragment). Enables use of large numbers of lights per scene. Just need to type it up...
Texture Projection Shadows minefield! ~1 week. Projecting shadows using the depth buffer. Not updated yet - old version here

Optimisations

Instanced Rendering and Batched Geometry easy-moderate. a few hours. Render lots of copies of the same object in a GPU-efficient way. Compare 2 approaches. Not updated yet - old version here

Things That I'll Probably Do Eventually

Useful References