PDA

View Full Version : A question about glCopyTexImage()



ChinaShrimp
09-06-2004, 07:37 PM
Hi,
I happened to a question about using glCopyTexImage().
First, I draw a texture into the framebuffer, and read the data from the framebuffer into memory using glReadPixels(). It's all ok.
But now I want to copy the content in the framebuffer to a texture using glCopyTexImage(). To my surprise, I found all the values in the texture equal to 0. I don't know why? The following is some codes in my project:


glBindTexture(GL_TEXTURE_2D, textureMatrix[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 1, g_nProjectionSize, g_nProjectionSize, 0, GL_LUMINANCE, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, textureMatrix[i]);
glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_LUMINANCE, nLeftBorder, nRightBorder, g_nProjectionSize, g_nProjectionSize, 0);I'll appreciated any suggestios:)
Thank you!

ChinaShrimp
09-07-2004, 05:39 AM
No one has happend to such kind of questions? I used the following codes to decide whether the texture is binded:

int prevTexBind;
glGetIntegerv(GL_TEXTURE_BINDING_2D,&prevTexBind); The value of preTexBind is just equal to textureMatrix[i]. So I really don't know what's the matter :confused:

dorbie
09-07-2004, 10:31 AM
You don't show your readpixels call, for example you probably read a single component from the framebuffer.

I'm not sure where the GL_LUMINANCE in your copy expects to take data from (red channel I think?) If it's someplace like alpha then it may explain your problem. It's probably in the spec somewhere but I'm not familiar enough with the details. There are luminance framebuffer formats and there may be some issue here with what's being expected as input, either with implementation or specification. Have you tried an RGB image as a test for the copy, make sure you change the teximage call and the copy, at least then you'd narrow the problem and eliminate some factors. You could try being explicit about the luminance precision, I noticed that the luminance table isn't specific with GL_LUMINANCE, so maybe go with a GL_LUMINANCE8 on both tokens (or more depending on what you're trying) just to be on the safe side. Test with RGB though, you'll get that working easily.

ChinaShrimp
09-07-2004, 06:42 PM
Thanks for your advices!
The following is my readpixel call:

glReadPixels(nLeftBorder, nRightBorder, g_nProjectionSize, g_nProjectionSize, GL_LUMINANCE, GL_FLOAT, pImage);I saved the data read from the framebuffer into pImage and displayed it using imdebug (http://www.cs.unc.edu/~baxter/projects/imdebug/) . All are right! And I want to get the data in a GL_FLOAT format so that I'll not lose the precisions.
The question has confused me for a long time :confused:

ChinaShrimp
09-08-2004, 12:30 AM
I've tested other format, such as GL_RGB, GL_RGBA. They all passed the tests :confused:

-NiCo-
09-08-2004, 01:05 AM
Using float to read out the textures won't give you more precision, it just convertes the 8 bit unsigned byte values to floating point values in the range [0,1].

You're not casting them back to unsigned byte or something like that, are you?

Nico