Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering A Texture Onto Itself In OpenGL ES

I can comfortably render a scene to a texture and map that texture back onto a framebuffer for screen display. But what if I wanted to map the texture back onto itself in order to blur it (say, at a quarter opacity in a new location). Is that possible?

The way I've done it is simply to enable the texture:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, color_tex);

And then draw to it:

glVertexPointer(2, GL_FLOAT, 0, sv);
glTexCoordPointer(2, GL_FLOAT, 0, tcb1);
glColor4f (1.0f,1.0f,1.0f,0.25f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

(some code omitted, obviously)

Is there anything obviously wrong with that idea? Am I being an idiot?

like image 707
mtrc Avatar asked Dec 05 '25 07:12

mtrc


1 Answers

No, you can't write the texture to the same texture, that triggers undefined behaviour.

But you can use a technique called Ping-Pong rendering, so you draw the result of the operation into another texture, and if you need to do more processing, you write the result to the first texture.

like image 51
Dr. Snoopy Avatar answered Dec 07 '25 21:12

Dr. Snoopy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!