Ramon Johannessen
Ramon Johannessen

Reputation: 183

How to utilize GL_ARB_stencil_texturing

From what I've read, to sample the stencil texture in the shader I need to set the GL_DEPTH_STENCIL_TEXTURE_MODE, so I did this:

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_COMPONENTS);

but I get an invalid enum... Why would that be?

Upvotes: 2

Views: 478

Answers (2)

Reto Koradi
Reto Koradi

Reputation: 54592

According to the man page, the correct enum value for this call would be GL_STENCIL_COMPONENT, not GL_STENCIL_COMPONENTS (note the trailing S).

As it turns out, the man page is wrong. Which unfortunately is not unusual. If you look it up in the spec (e.g. table 8.17 on page 225 in the OpenGL 4.5 spec document), the valid values for DEPTH_STENCIL_TEXTURE_MODE are GL_DEPTH_COMPONENT and GL_STENCIL_INDEX.

Based on this, the call should be:

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);

This feature requires OpenGL 4.3 or higher.

GL_STENCIL_COMPONENTS is a valid argument for glGetInternvalFormativ(), but not for glTexParameteri().

Upvotes: 4

3Ducker
3Ducker

Reputation: 346

I assume you only intialized functions from the core dll file opengl32.dll and only added gl.h or maybe glu.h headers. These headers do not load functions from the graphics driver only from the external direct link library file. If you go through the functions defined in the opengl32.dll you may not find all the functions you may want to use, for instance functions related to vertex buffers. And nevertheless some constant may not be defined in the gl.h you may reference, for instance the GL_DEPTH_STENCIL_TEXTURE_MODE. These functions may be loaded by the appropriate loading method according to the operaton system, in windows you may use wglGetProcAddress. For further information, read this article. Also these constants may be defined somewhere else.

Fortunately there is GLEW for you that has already done that work, if you search for GL_DEPTH_STENCIL_TEXTURE_MODE in glew.h you may find 0x90EA assigned to it. If you want to use only the constants you don't have to initialize GLEW, but if you do, you at least have to call glewInit.

Upvotes: 0

Related Questions