Spellcaster Studios

Make it happen…

Render to texture: OpenGL edition (Part II)

Today I mostly worked on getting the render to texture to work properly on OpenGL…

The nice part is that I didn’t have any kind of issue with the culling, all problems were due to the lack of Z-buffer:

screen387

On DirectX, if you set a render target but not set a depth buffer, it uses the one that was already set (usually the one created on startup). But on OpenGL, if you set a rendertarget, you have to actually give it a depth buffer explicitly. So I had to create some code that generated a depth buffer on startup and set that one. It’s a bit silly, in my opinion, but easy enough to solve after figuring out what was the problem…

Still had the problem with the floating point precision buffers on OpenGL.

The issue there was that the documentation was misleading… Most places I saw on the internet (including the Khronos group), said something like this:

internalFormat: Specifies the number of color components in the texture.”

So that’s what I was using to create the render target (setting it to 4, and using a component of type GL_FLOAT). Although gDEBugger was reporting the texture had the right format, it wasn’t working as intended… But then I found the MSDN entry for the same API call:

“internalformat: The number of color components in the texture. Must be 1, 2, 3, or 4, or one of the following symbolic constants: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12, or GL_RGBA16.”

A bit more complete and made obvious what the problem was!

After changing that parameter, everything worked fine:

screen388

Next step is applying a ambient occlusion on the data and store the result on a texture that we use on our shaders…

Now listening to “Aurora Consurgens” by “Angra”

Comment