book
OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition
by Dave Shreiner, Graham Sellers, John M. Kessenich, Bill M. Licea-Kane
March 2013
Intermediate to advanced
984 pages
26h 18m
English
Content preview from OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth EditionBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial



Lattice
Here’s a little bit of a gimmick. In this example, we show how not to draw the object procedurally.
In this example, we look at how the discard command can be used in a fragment shader to achieve some interesting effects. The discard command causes fragments to be discarded rather than used to update the framebuffer. We use this to draw geometry with “holes”. The vertex shader is the exact same vertex shader used for stripes (“Regular Patterns”). The fragment shader is shown in Example 8.8.
Example 8.8. Fragment Shader for Procedurally Discarding Part of an Object
in vec3 DiffuseColor;in vec3 SpecularColor;in vec2 TexCoordout vec3 FragColor;uniform vec2 Scale;uniform vec2 Threshold;uniform vec3 SurfaceColor; ...