I want to use content in frame buffer as texture.
following code do the job:
glReadBuffer( GL_BACK);
glReadPixels(0, 0, 500, 500, GL_RGB, GL_UNSIGNED_BYTE, pPixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 500,
500, 0, GL_RGB, GL_UNSIGNED_BYTE, pPixels);
however, following code does not:
glReadBuffer( GL_BACK);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 500, 500);
why? I think glCopyTexSubImage2D copy frame buffer to texture.
Before you use CopyTexSubImage, you should specify the format and dimension of your texture object.
How it can be done? By CopyTexImage or by TexImage, it doesn’t matter.
For example, you should alter code like this:
You can also call glTexImage with NULL for the pixels before the first time to eliminate the special case. This initializes the texture to undefined contents, which you can override with glCopyTexSubImage.
Depends on your overall code structure which one is better…