19 Aug 2012

OpenGL Screw-Ups

A list of embarrasing screw-ups I tend to waste time on (repeatedly) while writing OpenGL based rendering code. The list will surely grow as I continue working on Twiggy :P
This is generally stuff which doesn't show up with glGetError() of course.

Sampling a texture just returns black pixels in the fragment shader:

Most likely the texture is incomplete because the texture sampler states GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER hadn't been setup yet, or the FILTER states expects mipmaps but the texture has none.
Also on some platforms / drivers it is more efficient to setup those states before calling glTexImage2D().

Clearing a render target doesn't work as expected (eg the color buffer is cleared, but the depth buffer isn't):

glClear() is affected by the state of glColorMask(), glDepthMask(), and glStencilMask(). If glDepthMask() is set to GL_FALSE, the depth buffer won't be cleared even though glClear() is called with the GL_DEPTH_BUFFER_BIT set.

Also: http://www.opengl.org/wiki/Common_Mistakes


Unknown said...

I want to thank you for a very interesting blog. I am very glad that you've began to publish new posts.
Sorry to bother you, but I want to ask you. Can we expect a new version of Nebula Device 3 and when we can wait? Thank you.

Unknown said...

And, more important, can we expect to be able to actually download it? Even the link provided on this side is broken ... I (and I guess some more people) would be awesomely glad to download it.