I want to generate a texture between to frames, in order to draw it on a quad, during the next frames. To generate my texture, I render the desired scene, and I store the back buffer without displaying it.
That’s OK, I can do it with the glReadPixels() function. It stores the buffer into the processor memory. Then I can create a texture object with glGenTexture2D() and use this texture object for the next frames.
But it is very slow, because the texture is send from the video memory to the processor memory (glReadPixels), and then from the processor memory to the video memory (glGenTexture2D). The texture generation has to be very fast, otherwise the frame rate of the main scene will collapse…
Is there a way to store my new texture directly into the video memory, as a texture object ? (kind of “readPixelsIntoTexture2D()” function …)
Depending on the effect you want to create, you could render your texture in a DIB (which is not hardware accelerated !) and then glTexSubImage the result !
This will avoid the slow glReadPixels process (but perhaps it is even slower !).
Well, if your texture is really complicated to generate, it is not worth a try but in case of a simple thing, why not… (I have never done that but if I’ll probably try it one day !).
I have study the glTexSubImage2D() function in the red book, and I have found a very interesting one, wich is explained in the same section : glCopyTexSubImage2D(). It seems to do exactly what I want ! What do you think about that ?
There is a new problem : I want to generate some alpha in my texture. When I used glReadPixels(), I was able to modify my texture, and to change one color into alpha.
But now, I can’t access the texture. Do you know if there is a way to generate some alpha ?