PDA

View Full Version : glCopyTexSubImage2D can' t work?



Flying_sands
10-23-2005, 02:19 AM
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.

Flying_sands
10-23-2005, 02:38 AM
that is really confusing. I change glCopyTexSubImage2D into glCopyTexImage2D, it works. What happens, then?

Jackis
10-23-2005, 03:56 AM
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:

if (FirstTime) {
glCopyTexImage2D(...);
FirstTime = false;
} else {
glCopyTexSubImageImage2D(...);
}

Flying_sands
10-23-2005, 06:51 AM
Maybe this is true, for first time to use glCopyTexImage2D, the internal format is not given.

jide
10-23-2005, 08:00 AM
This is not maybe, this is simply like that ;)

Overmind
10-23-2005, 02:12 PM
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...