GL_ARB_shadow
init()
The init method is simple. Create the depth texture and set it up to do comparisons. The rest is initializing the current state that we will work in. You know: initialize floats, enable depth testing, check for extensions.
bool init()
{
if(!glexExtensionsSupported("GL_ARB_depth_texture GL_ARB_shadow"))
{
return false;
}
glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
glEnable(GL_DEPTH_TEST);
// Create texture
glGenTextures(1, &texture);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
// Fiddle with parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
// Initialize texture memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SIZE, SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
rotation = 0.0f;
return true;
}
update()
The update method just increases the amount of rotation in order to animate the scene.
void update(DWORD val)
{
GLWindow::update(val);
rotation += 0.7f;
}