O'Reilly logo

OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition by Bill M. Licea-Kane, John M. Kessenich, Graham Sellers, Dave Shreiner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Shadow Map

The first step is to create a texture map of depth values as seen from the light’s point of view. You create this by rendering the scene with the viewpoint located at the light’s position. Before we can render depth into a depth texture, we need to create the depth texture and attach it to a framebuffer object. Example 7.15 shows how to do this. This code is included in the initialization sequence for the application.

Example 7.15. Creating a Framebuffer Object with a Depth Attachment

// Create a depth textureglGenTextures(1, &depth_texture);glBindTexture(GL_TEXTURE_2D, depth_texture);// Allocate storage for the texture dataglTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,             DEPTH_TEXTURE_SIZE, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required