GL_ARB_depth_texture

OpenGL Extensions allow us to use graphics hardware without delving into many specifics. The first one we will look at is fairly easy to use and understand, and it is a requirement for other extensions that do much more interesting manipulations. GL_ARB_depth_texture allows us to create a texture from the depth component of the scene. This will allow us to do shadow maps later on.

Set Up

In this example I will be using OglExt, but there are many different extension managers out there and all are easy to use. I like OglExt because it doesn’t require an initialization step like the OpenGL Extension Wrangler requires. I will also be using GLWindow as it is an easy to use OpenGL framework. This example works just as well in GLUT or any other window manager you can find. Here is the main file that we will be working with. Each step is outlined.

#include "GLWindow.h"
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <gl/OglExt.h>

#define SIZE 512

class DepthTexture : public GLWindow
{
public:
    GLuint texture;

    bool init()
    {
        // Check that extension is supported

        // Create texture
        // Make texture active
        // Fiddle with texture parameters

        // Initialize texture memory using DEPTH_TEXTURE for internal format and format

        return true;
    }

    void draw()
    {
        // clear the depth and color buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();

        // Set viewpoint

        // Draw scene that we will take the depth of

        // Copy the current depth buffer to the texture

        // clear the depth and color buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();

        // Set viewpoint
        // Draw a quad with the texture attached
    }
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    DepthTexture* window = new DepthTexture();

    // Set Window size
    window->starting_width = SIZE;
    window->starting_height = SIZE;
    window->mainLoop(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

Pages: 1 2

2 Comments »

22

Pingback by BitwiseOR » GL_ARB_shadow

January 9, 2006 @ 5:23 pm

[...] The GL_ARB_shadow extension allows us to create simple shadow maps. It requires the GL_ARB_depth_texture extension. For more information on the theory and implementation of shadow maps see NVidia’s hardware shadow maps document. [...]

23

Pingback by BitwiseOR » GL_ARB_shadow_funcs

January 10, 2006 @ 3:11 pm

[...] The GL_ARB_shadow_funcs extension requires GL_ARB_shadow and GL_ARB_depth_texture in order to have any effect. In the GL_ARB_shadow example on this site we use GL_LEQUAL when setting the GL_TEXTURE_COMPARE_FUNC_ARB texture parameter. GL_ARB_shadow allows this comparison function to be GL_GEQUAL as well, but not any of the other comparison functions. [...]

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>