Open main menu

Wikibooks β

Welcome to the OpenGL Programming book. OpenGL is an API used for drawing 3D graphics. OpenGL is not a programming language; an OpenGL application is typically written in C or C++. What OpenGL does allow you to do is draw attractive, realistic 3D graphics with minimal effort. The API is typically used to interact with a GPU, to achieve hardware-accelerated rendering.

You are free, and encouraged, to share and contribute to this wikibook: it is written in the spirit of free documentation, that belongs to humanity. Feel free to make copies, teach it in school or professional classes, improve the text, write comments or even new sections.

We're looking for contributors. If you know about OpenGL, feel free to leave comments, expand TODO sections and write new ones!



Setting Up OpenGLEdit

Modern OpenGLEdit

"Modern" OpenGL is about OpenGL 2.1+, OpenGL ES 2.0+ and WebGL, with a programmable pipeline and shaders.

The basics arcEdit

Tutorial 01: newcomer's introduction, first dive into shaders 02
Tutorial 02: adding more robustness to our code, transparency
Tutorial 03: passing information to shaders: attributes, varying and uniforms 04
Tutorial 04: transformation matrices: positioning and rotating
Tutorial 05: adding the 3rd dimension: a cube, plus a camera 06
Tutorial 06: textures: displaying a wooden cube
OBJ format: loading Suzanne the monkey from Blender 08
Navigation: navigate in 3D space and manipulate objects in our model viewer

Tutorial_drafts: ideas and notes for upcoming tutorials

The lighting arcEdit

This series of tutorials is a C++ port of the GLSL wikibook Basic Lighting tutorials.

Diffuse Reflection: about per-vertex diffuse lighting and multiple light sources of different kinds 02
Specular Highlights: about per-vertex lighting
Two-Sided Surfaces (about two-sided per-vertex lighting) 04
Smooth Specular Highlights (about per-pixel lighting)
Two-Sided Smooth Surfaces (about two-sided per-pixel lighting) 06
Multiple Lights (about for-loops for handling multiple light sources)

This series of tutorials is a C++ port of the GLSL wikibook Basic Texturing tutorials.

Textured Spheres: about texturing a sphere 02
Lighting Textured Surfaces: about textures for diffuse lighting
Glossy Textures: about gloss mapping 04
Transparent Textures: about using alpha textures for discarding fragments, alpha testing, and blending
Layers of Textures: about multitexturing

This series of tutorials is a C++ port of the GLSL wikibook tutorials about Textures in 3D.

Lighting of Bumpy Surfaces: about normal mapping 02
Projection of Bumpy Surfaces: about parallax mapping
Cookies: about projective texture mapping for shaping light 04
Light Attenuation: about texture mapping for light attenuation and lookup tables in general
Projectors: about projective texture mapping for projectors

There are more tutorials to port at the GLSL wikibook!

The scientific arcEdit

Graph 01: plotting a simple function, using vertex buffer objects and point sprites 02
Graph 02: plotting a graph from data in a texture
Graph 03: plotting borders and axes, clipping 04
Graph 04: plotting a three-dimensional graph
Graph 05: plotting a surface with hidden line removal

And more to come.

Selected topicsEdit

Arcball: intuitive object rotation with the mouse 02
Bounding box: draw a cube around your object for editing or debugging purposes
2D-on-3D: hardware-accelerated 2D programming 04 Video Capture: capture your animation using apitrace (C++) or JavaScript (WebGL)
Tea time: generating an HD teapot from Bézier surfaces 06
Stencil buffer: masking and combining
Quadrics: creating simple shapes with a bit of maths 08
Basic text: rendering text using the FreeType library
Optimized text rendering: using a texture atlas containing all glyphs 10
Object selection: unprojecting coordinates and object identification using the stencil buffer
Anti-Aliasing: smoothing lines 12
Particle systems: differents kinds of particle systems

The post-processing arcEdit

Concepts: how to perform full-screen post-processing, first example with a simple animated wave 02
???: next effect to be decided!


This series shows how to implement a teleportation system similar to Valve's Portal, step-by-step, using OpenGL.

Mini-Portal: a first working see-through portal 02
Mini-Portal Smooth: smooth transition, understanding the camera
Mini-Portal Recursive: recursive portals - display portals within portals 04
Mini-Portal Optimization: optimization with scissors


This series shows how to render a voxel based world, similar to Minecraft.

Glescraft 1: basic voxel rendering 02
Glescraft 2: removing unnecessary voxel faces
Glescraft 3: texturing, lighting, fog, transparency 04
Glescraft 4: first person camera controls
Glescraft 5: drawing only what is on screen 06
Glescraft 6: adding and removing voxels
Glescraft 7: using geometry shaders

Using the accumulation bufferEdit

Tutorial 01: motion blur 02
Tutorial 02: full-screen supersampling anti-aliasing
Tutorial 03: depth of field 04
Tutorial 04: order-independent transparency

Note: not all videocards support accumulation buffer

Cutting-edge OpenGLEdit

If you do not need to target mobile devices or the web, you can upgrade to OpenGL 4.x. It notably introduces 3 new kinds of shaders: Geometry, Tessellation Control and Tessellation Evaluation.

Tutorial 01: modify and create vertices on the fly with geometry shaders 02
Tutorial 02: dynamic mesh quality with tesselation

and lots of other features.

Code qualityEdit

Debugging: tips to help debug your OpenGL code 02
Performance: measuring and improving your application performance.


Legacy OpenGL 1.xEdit

External linksEdit


Related WikiBooks:

  • GLSL Programming : wikibook on the use of the OpenGL Shading Language (GLSL) in Unity 3 and Blender 2.5, with much information on lighting and texturing
  • Blender 3D: Noob to Pro: comprehensive book on using the Blender 3D modeling environment
  • an open source, cross-platform IDE's for exploring pixel based graphics on the GPU using GLSL :


The following websites provide conversion of the tutorials to other programming languages or platforms:

Freely-licensed documentation and samplesEdit

Non-freely-licensed documentationEdit


Further readingEdit

  • OpenGL Architecture Review Board, et al: OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 2, Fifth Edition, Addison-Wesley, ISBN 0-321-33573-2
  • OpenGL Architecture Review Board, et al: OpenGL Reference Manual: The Official Reference Document to OpenGL, Version 1.4, Addison-Wesley, ISBN 0-321-17383-X
  • Wright, Richard S. Jr and Lipchak, Benjamin: OpenGL SuperBible, Third Edition, Sams Publishing, ISBN 0-672-32601-9

< OpenGL Programming

Browse & download complete code