close
Jump to content

OpenGL Programming

50% developed
From Wikibooks, open books for an open world
OpenGL logo
OpenGL logo

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!

Introduction

[edit | edit source]
  1. About this book
  2. History and Evolution of OpenGL

Setting Up OpenGL

[edit | edit source]

Modern OpenGL

[edit | edit source]

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

Note:
At the time of this book's writing, OpenGL had made its big leap to OpenGL 2.0, or "Modern OpenGL". This update introduced pivotal changes to the standard - notably, the introduction to shaders and the initial release for GLSL. Rather than using the "fixed-function pipeline", programmers were able to create their own shaders.

Since then, OpenGL has gone through a number of overhauls - another notable one occurring with OpenGL 3.0, which deprecated much of the fixed-function pipeline and the direct-mode rendering (glBegin and glEnd).

This is notable because this book was written with OpenGL 2.0 in mind. As such, many of the snippets within, while by-large still supported via the "compatibility profile" in OpenGL 3.2+, are not considered "best practice" by today's standards.


The basics arc

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

Tutorial_drafts: ideas and notes for upcoming tutorials

The lighting arc

[edit | edit source]

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

01
BERJAYA
Diffuse Reflection: about per-vertex diffuse lighting and multiple light sources of different kinds 02
BERJAYA
Specular Highlights: about per-vertex lighting
03
BERJAYA
Two-Sided Surfaces (about two-sided per-vertex lighting) 04
BERJAYA
Smooth Specular Highlights (about per-pixel lighting)
05
BERJAYA
Two-Sided Smooth Surfaces (about two-sided per-pixel lighting) 06
BERJAYA
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.

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

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

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

There are more tutorials to port at the GLSL wikibook!

The scientific arc

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

And more to come.

Selected topics

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

The post-processing arc

[edit | edit source]
01
BERJAYA
Concepts: how to perform full-screen post-processing, first example with a simple animated wave 02
BERJAYA
???: next effect to be decided!

Mini-portal

[edit | edit source]

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

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

Glescraft

[edit | edit source]

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

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

Using the accumulation buffer

[edit | edit source]
01
BERJAYA
Tutorial 01: motion blur 02
BERJAYA
Tutorial 02: full-screen supersampling anti-aliasing
03
BERJAYA
Tutorial 03: depth of field 04
BERJAYA
Tutorial 04: order-independent transparency

Note: not all videocards support accumulation buffer

Cutting-edge OpenGL

[edit | edit source]

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

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

and lots of other features.

Code quality

[edit | edit source]
01
BERJAYA
Debugging: tips to help debug your OpenGL code 02
BERJAYA
Performance: measuring and improving your application performance.

Appendices

[edit | edit source]

Legacy OpenGL 1.x

[edit | edit source]

"Legacy" OpenGL is about OpenGL 1.x and OpenGL ES 1.x, with a fixed pipeline and no shaders.

Starting Tutorial

[edit | edit source]
  1. Setting Up A Programming Environment On WindowsBERJAYA
  2. Setting Up OpenGL In The Programming EnvironmentBERJAYA
  3. Drawing PrimitivesBERJAYA
    1. Immediate Mode
    2. Display Lists
    3. Vertex Arrays
  4. Basic TransformationsBERJAYA
    1. Translation
    2. Rotation
    3. Scaling
    4. Custom Transformations

Basics

[edit | edit source]
  1. Structure of a Typical OpenGL Application BERJAYA
  2. Drawing Rectangles BERJAYA
  3. Drawing Lines and Points
  4. Drawing Simple 2D Shapes BERJAYA
  5. OpenGL Naming Conventions BERJAYA
  6. Using Color BERJAYA
  7. Viewing Transformations BERJAYA
  8. Drawing Simple 3D Objects
  9. Perspective versus Orthographic Projections

Intermediate

[edit | edit source]
  1. Smoothing Polygons with Normals
  2. Adding Lights
  3. Using Materials
  4. Using Textures
  5. Using Mipmaps
  6. Drawing Complex Polygons Using Tessellation

Advanced

[edit | edit source]
  1. Optimizing OpenGL Code
  2. Drawing Shadows
  3. Drawing Using Quadrics
  4. Drawing Using NURBS and Curves
  5. Ambient Occlusion

Appendices

[edit | edit source]
  1. Coordinate Transformations
  2. Understanding Transformation Matrices
  3. OpenGL Library Reference. functions and type reference for gl.h glu.h and glut.h
  4. Why OpenGL Exists and What It's Good For
  5. Migrating from 1.x to 2.x: how to upgrade your code to use modern OpenGL
[edit | edit source]

Wikibooks

[edit | edit source]
  • GLSL Programming: book 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
  • Open source, cross-platform IDE's for exploring pixel-based graphics on the GPU using GLSL:

Ports

[edit | edit source]

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

Freely-licensed documentation and samples

[edit | edit source]

OpenGL 3.0+

[edit | edit source]

OpenGL 2.x

[edit | edit source]

OpenGL 1.x

[edit | edit source]
  • Paul's projects: OpenGL 1.x, two tutorials on shadow mapping and bump mapping, with code under the MIT license

OpenGL ES 2.0

[edit | edit source]

WebGL

[edit | edit source]

Non-freely-licensed documentation

[edit | edit source]

Websites

[edit | edit source]

Further reading

[edit | edit source]
  • 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 BERJAYA