2

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?

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133

2 Answers2

4

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().

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • Ah..see I was wondering about that, since that's what the page for the extension mentioned, but I couldn't find GL_STENCIL_COMPONENT anywhere in the glext.h I have, so I figured maybe they renamed it or something. For instance, it's not in [this](https://www.opengl.org/registry/api/GL/glext.h) header, which has the defines for 4.3... – Ramon Johannessen Jul 17 '15 at 04:47
  • You don't happen to know where it's defined to you? I can't seem to find it defined anywhere! – Ramon Johannessen Jul 17 '15 at 05:23
  • @RamonJohannessen Good call. It turns out that the man page is broken, and that value does in fact not exist. See the new version of the answer. – Reto Koradi Jul 17 '15 at 05:45
  • Oh yeah that's it, good find! What a pain. Well thanks for assistance! – Ramon Johannessen Jul 17 '15 at 05:57
0

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.

3Ducker
  • 346
  • 1
  • 9