tags:

views:

10

answers:

1

Basically, my program uses frame buffer object to render to a 3D texture. If the 3D texture which I attach to fbo is in GL_RGB8 format, which is 24 bits per texel, there is no problem. Only 8-bits of them are used. The problem happens when I try to use GL_ALPHA8 (8 bits per texel) as the internal format for the 3D texture, the rendering result is blank. The cg fragment shader which I used to render to fbo looks like this:

void F_PureDecoder(
    float3 vIndexCoord : TEXCOORD0,   
    out float color :COLOR)
{
        ... ...
    color=float4(fL3,fL3,fL3,fL3);
}

Am I doing something wrong or fbo doesn't support to render to 8-bit texel texture? I am primarily unsure if the output format of fragment shader is correct. Coz the framebuffer is 8 bits but the output is 24 bits. Should I modify the output format from fragment shader? If so, what format should I use?

Thanks very much for any input!

+1  A: 

To render to one/two component textures, you MUST use the GL_ARB_texture_rg extension, it will NOT work with any other format. See the extension specification for why it doesn't work:

It is also desirable to be able to render to one- and two- 
component format textures using capabilities such as framebuffer 
objects (FBO), but rendering to I/L/LA formats is under-specified
(specifically how to map R/G/B/A values to I/L/A texture channels).

So, use the GL_R8 internalFormat. To write to it, just write the full RGBA output, but only the R component will be written.

Matias Valdenegro