I have a framebuffer bound to 32-bit FP texture:

glGenTextures(1, &texColor);
glBindTexture(GL_TEXTURE_2D, texColor);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, w, h, 0, GL_RGBA, GL_FLOAT, (GLvoid*)NULL);
glBindTexture(GL_TEXTURE_2D, 0);

glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texColor, 0);

What's the best way to initialize framebuffer to a value 1000.0?

The problem is that

glClearColor(1000.0f, 0.0f, 0.0f, 0.0f);

clamps values to [0,1] interval, and clearing the texture texColor would require memory allocation of w * h * sizeof(float) bytes of memory and manual filling of that buffer with value 1000.0 which is slow (I would inject it using glTexImage2D).

I'm using OpenGL 3.2 Core profile.

Thanks, Josip


1 Answer 1


You can render a quad onto the framebuffer with a shader that will just set the color value to 1000.0.

Since you don't even need to set a texture really let alone compute lighting, this should not really take any noteworthy time to accomplish.

It's pretty easy to do but here is a tutorial that talks about rendering to a texture. Though really you don't even need to do all of those steps.


  • \$\begingroup\$ That's the way I had to do it. It seems that rendering quad on near plane with fragment shader that sets result to 1000.0 is the fastest way. Too bad that OpenGL doesn't have some more elegant way to do this. \$\endgroup\$
    – Lisur
    Jul 22, 2016 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .