Working with floating point textures

I want to load 32 bit floating point RGB textures. So do I need to create a floating point buffer using the following code?


int pixelFormat;
UINT numFloats;
int attribtes[] = {
WGL_DOUBLE_BUFFER_ARB, TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_PIXEL_TYPE_ARB, WGL_RGBA_FLOAT_ARB,
0,0
}
wglChoosePixelFormat( hdc, attributes, NULL, 1, &pixelFormat, &numFormats );
//...

( The book “More OpenGL Game Programming” suggest the readers to create a floating point buffer while using the floating point textures. However, I can’t create a floating point buffer! When I use the following line of code:
WGL_PIXEL_TYPE_ARB, WGL_RGBA_FLOAT_ARB,
I get an error–wglChoosePixelFormat() can’t create the requested pixel format.

I want to load 32 bit floating point RGB textures. So do I need to create a floating point buffer using the following code?

No. That code is for the default framebuffer. Each texture can have an arbitrary image format.

Furthermore, you can’t have a floating-point default. The default framebuffer needs to be visible, and floating-point images are not visible (since your screen can only show color values on [0, 1]).

So, why the book has suggested to use floating point frame buffers while using the floating point textures?
( If I have understood correctly, the suggestion in this book is incorrect and the texture format is independent of the frame buffer format? )
BTW, why wglChoosePixelFormat() is not able to create a floating point buffer? And what’s the benefit of a floating point buffer?

So, why the book has suggested to use floating point frame buffers while using the floating point textures?

My guess is that you misunderstood what it was saying.

BTW, why wglChoosePixelFormat() is not able to create a floating point buffer?

In what way was “The default framebuffer needs to be visible, and floating-point images are not visible (since your screen can only show color values on [0, 1]),” unclear to you?

No I didn’t misunderstood it. It describes about the “ARB_color_buffer_float” extension. Then it introduces glClampColorARB() and explains that we must use this function to disable vertex and fragment color clamping if we want to use floating point textures.

There is in fact possibility to ask for a floating point default framebuffer, however you cannot render it to a window so using such a context makes sense only if you are using e.g. pbuffers, still, instead of pbuffers you should rather go with FBO.

So actually you need to create a usual normalized fixed point framebuffer and just use floating point textures as specified by ARB_texture_float and use FBOs to render to these textures if needed.

Thanks. Now I understand it :slight_smile: