glCopyTexImage2D Problem

I am trying to use glCopyTexImage2D to copy the current contents of the OpenGL frame buffer into a texture but its not working.

I call it like this:

glBindTexture(GL_TEXTURE_2D, texture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, h_Height, 256, 256, 0);

But nothing gets copied into the texture variable. When I use it later on while drawing a quad, the quad is pure white.

Im not to sure about the internalFormat parameter in the function. This might be the problem.

I also made sure to enable GL_TEXTURE_2D and bind my texture before drawing the quad.

Anyone used this function before? Can you give me an example code snippet?

Thanks,

Jason A.

I write code.
DelphiGL ( http://delphigl.cfxweb.net )

[This message has been edited by jra101 (edited 01-20-2001).]

You have to use one of the constants that specify the bit depth, e.g. GL_RGB8. I have a demo on my site: http://www.gamedeveloper.org/delphi3d/download/rendertex.zip

It should be right up your alley - it’s written in Delphi

  • Tom

Thanks Tom, I appreciate it

I downloaded the file you pointed me to and looked at the source (I couldn’t compile cause I was missing numerous files). I tried using GL_RGB8 and GL_RGBA8 and both fail. The texture is always white

What I am trying to do is take six “snapshots” of a scene to create a cube map for use in Cubic Environment Mapping. I have it working right now by saving the frame buffer with glReadPixels then generating a cubemap texture out of the six textures using gluBuild2DMipmaps.

The only drawback of this method is of course speed, its quite slow. I tried replacing gluBuild2DMipmaps with glTexImage2D but for some odd reason it doesn’t work at all. I made sure that the texture width/height were the same (512x512) and that all 6 textures were the exact same dimensions.

Doesn’t work , both glTexImage2d and glCopyTexImage2d both fail on me (no OpenGL error is reported though), I always get a white texture.

I’m at a loss…

Here is the chunk of code in question:

for I := 0 to 5 do begin
xRot := rot[I, 0];
yRot := rot[I, 1];

glDraw();
screenBmp.SaveScreen();
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
//glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + i, 0, 3, screenBmp.Width, screenBmp.Height, 0, GL_RGB, GL_UNSIGNED_BYTE, screenBmp.Bits);
gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + I, 3, screenBmp.Width, screenBMP.Height, GL_RGB, GL_UNSIGNED_BYTE, screenBmp.Bits);
//glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + I, 0, GL_RGB8, 0, 0, 512, 512, 0);

end;

the xRot, yRot stuff just rotates the scene.

Jason A.
DelphiGL ( http://delphigl.cfxweb.net )

i am not sure but it might be necessary to set your texture-parameter, i had the same problem and it fixed it.

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);

hope it helps…
Chris

Right. Default texture object parameter usemagnification filter GL_LINEAR and minification filter GL_LINEAR_MIPMAP_NEAREST (the general OpenGL texture default). As these are stored with each texture object, you have to set it for each.
This explains why gluBuildMipmaps works.
Also gluBuildMipmaps scales the image to power of two dimensions, if I remember correctly. glTexImage rejects non power of two textures.

For glTexImage a faster way to download texture data is to build the texture object once and then update it with glTexSubImage resp. glCopyTexSubImage (run benchmarks!).
But this is for level 0 texture only. If you need mipmaps, I recommend to write your own scaling algorithm.

Watch out for the recommended clamp mode with cube maps. Haven’t done it myself, but I read GL_CLAMP_TO_EDGE somewhere.

[This message has been edited by Relic (edited 01-24-2001).]

hmm i never used cube mapped so i can’t say anything about that…but i thought GL_CLAMP_TO_EDGE just ignores the texture border when clamping.

Chris

GL_CLAMP_TO_EDGE is definitely preferred for cubemaps.

  • Matt

Thanks for all the replies, I finally figured out what was the problem.

I forgot the bind my cube map texture before setting my texture parameters, just had to move a line of code up and it worked perfect.

Jason A.
DelphiGL( http://delphigl.cfxweb.net )