Sign in to follow this  
Hioxz

Copyteximage2d makes nice white texture

Recommended Posts

I read a little story about the glCopyTexImage2d function in my redbook (page 364), and i wanted to make a little test program to see how it works etc etc.. I wrote the following code: (in my draw procedure)
 glViewport(0,0,128,128);
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  glcolor3f(0,0,1);
  glbegin(GL_QUADS);
   glVertex3f(-1.0, -1.0,  -1.0);
   glVertex3f( 1.0, -1.0,  -1.0);
   glVertex3f( 1.0,  1.0,  -1.0);
   glVertex3f(-1.0,  1.0,  -1.0);
  glcolor3f(1,1,1);
  glEnd();

  glBindTexture(GL_TEXTURE_2D, MyTextureTex[1]);
  glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,128,128,0);
  glflush();

  glViewport(0,0,800,600);
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  gltranslatef(0,0,-15);
    glBindTexture(GL_TEXTURE_2D, MyTextureTex[1]);
    glBegin(GL_QUADS);
      glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0,  1.0);
      glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0,  1.0);
      glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0,  1.0);
      glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0,  1.0);
    glend();
 glflush();
Now the quad drawn in the last lines of this code is supposed to show up blue (or at least a blue rectangle) But it does show only white (as like there's no texture at all) (btw i enabled the texture stuff in my init) Does anyone have an idea of what i do wrong? i am looking at my code for about half a day now, and i am getting fed up with it not to work :D Tnx in advance!

Share this post


Link to post
Share on other sites
One of the common things is a wrong minification filter. Unless you enable automatic mipmap generation, you need to set the minification filter to a non-mipmap filter, or the texture is invalid as you only provide the base level and not a complete mipmap set.

And by the way, those glFlush calls are pretty much useless in the place you have them. Well, if you use single buffering, the last one could probably be there.

Share this post


Link to post
Share on other sites
I seen this off the top of my head not sure if you or the webpage did this but its wrong...


glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);



should be

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



Share this post


Link to post
Share on other sites
[quote]Original post by MARS_999
I seen this off the top of my head not sure if you or the webpage did this but its wrong...
[quote]
he never said he was using C/C++ :)

make sure you are generating a texture of dimensions
128x128 RGBA to use glCopyTexImage

Share this post


Link to post
Share on other sites
Heya all,

Tnx for all your replies :D

I am using Delphi instead of C++ atm, so i use "or" instead of |

I was wrong about the following, i thought it wasn't nescesary to set the MIN/MAG Filter... but i guess it is... :P (or isnt it?)

Anyway, i (finally) found a nice (delphi) example of using the texture copy function at sulaco.co.za , i 'borrowed' some function to properly 'initialize' a texture:


procedure CreateRenderTexture;
var pData: Pointer;
begin
GetMem(pData, 256*256*3);

glGenTextures(1, RenderedTex);
glBindTexture(GL_TEXTURE_2D, RenderedTex);

glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { only first two can be used }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); { all of the above can be used }

FreeMem(pData);
end;



This piece of code does some things i wasn't doing :D like actually allocating memory for the texture and setting the mag and min filter.

It seems that all your tips and this piece of code did the trick Since it it working now :)

Tnx a bunch again for the help :D

(ow btw, i still have to figure out how to do copytexsub instead of copytex but i guess that isn't to different from what i am doing now ^^)

[edit]
ow copytexsub isnt much different at all :D lol, ah well...

glcopytexsubimage2d(GL_TEXTURE_2D,0,0,0,0,0,256,256);

is replaced by

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);

[/edit]

[Edited by - Hioxz on September 20, 2004 6:09:43 AM]

Share this post


Link to post
Share on other sites
>>I was wrong about the following, i thought it wasn't nescesary to set the MIN/MAG Filter... but i guess it is... :P (or isnt it?)<<

yes it it cause youre creating a NEW texture, if u use glCopyTexSubImage..(...) then yore copying the image into an alreday existing tetxure, which not only is quicker but u dont have to supply the minification stuiff again etc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this