problem with glCopyTexSubImage2D

  1. If i want to save the background to a texture and restore it everytime instead of drawing the whole object, What should i do? Someone told me that glCopyTexSubImage2D may help but I would like to know isn’t it the width and Height for sub-image must be a (X^2) pixel when using glCopyTexSubImage2D function. The problem is my background won’t be exactly the (X^2) pixel.

can someone help me. Thanks a lot.

The texture have to be a power of two, but you don’t have to use the entire texture. Create an empty texture (I think you can pass a null pointer to glTexImage to get an empty image) with a size large enough to hold the background. That is, round up to neares power of two and use that size for the texture. Subimages can be of any size, so copy the window to the texture, and then use proper texture coordinates to get the subimage from the large texture.

If you’re willing to experiment with opengl extansions and you’re using windows, you can take a look at

http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_buffer_region.txt

This extension is ideal for what you’re trying to accomplish, and will most likely give you the best performance.

If you still want to go with the copytexsubimage solution and don’t want to be contrained by the power of 2 sizes, you can use the following extension

http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_rectangle.txt

This extension is also available under linux.

Greetz,

Nico

Originally posted by Bob:
The texture have to be a power of two, but you don’t have to use the entire texture. Create an empty texture (I think you can pass a null pointer to glTexImage to get an empty image) with a size large enough to hold the background. That is, round up to neares power of two and use that size for the texture. Subimages can be of any size, so copy the window to the texture, and then use proper texture coordinates to get the subimage from the large texture.
If the size of the window is larger than 1024 and say we use 2048(height)2048(width) texture. Will you think the texture is too big? I have try with your method and it works fine for 256256, 512512, and 10241024. But it fail if i use 2048*2048. Please help!!

Don’t use rectangle textures, use NPOT ones if your system supports it.

http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of_two.txt

Originally posted by jide:
[b] Don’t use rectangle textures, use NPOT ones if your system supports it.

http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of_two.txt [/b]
I know thats a good idea, but if the graphic card don’t support the extension what will be the altenative way?

You can then use texture rectangle. If this is not even supported, then use a viewport that suits your texture capabilities then render to it.

Originally posted by jide:
You can then use texture rectangle. If this is not even supported, then use a viewport that suits your texture capabilities then render to it.
As I have mention earlier, the texture rectangle fail at the screen size larger than 1024*1024. I hope that someone could tell me the reason. Thanks a lot.

Maybe your implementation just doesn’t support larger textures than 1024x1024. Check glGetInteger with GL_MAX_TEXTURE_SIZE.

And by the way, start a new topic with a link to the old topic, or at least mention that the original thread is nearly 2 years old. Can result in some wierd discussion if some people notice some outdated information, which was correct at the time of the post, and starts arguing without knowing the age of the information. It have happened in the past.

Originally posted by Bob:
[b] Maybe your implementation just doesn’t support larger textures than 1024x1024. Check glGetInteger with GL_MAX_TEXTURE_SIZE.

And by the way, start a new topic with a link to the old topic, or at least mention that the original thread is nearly 2 years old. Can result in some wierd discussion if some people notice some outdated information, which was correct at the time of the post, and starts arguing without knowing the age of the information. It have happened in the past. [/b]
I am sorry for that. I have
check the GL_MAX_TEXTURE_SIZE with glGetInteger and it return a 2048. Doesn’t it means that the implementation support texture with the size of 2048?