PDA

View Full Version : glTexImage2D/glCopyTexImage2D not working!



inept
10-02-2002, 02:43 AM
Hello,
I've got initialisation code like this:-



GLuint id;
const int width=128;
const int height=128;

GLubyte* buffer = new GLubyte[width*height*4];
glGenTextures(1, &id);


Now, I want to grab a rectangle of colourful pixels from the frame buffer, but without mipmapping.
The code below works (but of course produces mipmaps):-



glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, id);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);


But astouningly, neither of these standard functions work (they produce a 100% white texture, not the colourful pixels I expect (and indeed get using the glu function)):-




glBindTexture(GL_TEXTURE_2D, id);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0);





glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);


That's it. Neither of the standard GL functions create a texture. I've done this kind of thing before, but suddenly I can't get it to work.
Is there something obvious I'm missing?
I've checked glGetError - which doesn't report anything is wrong.
I've just installed the latest (7thAugust) NVidia drivers on a geforce3 - I hope it's not a bug....

davepermen
10-02-2002, 03:04 AM
have you set the texture parameters?
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

by default gl tries to mipmap me thinks.. at least, my textures are white till i set that as well..

inept
10-02-2002, 03:09 AM
Davepermen, you are a very observant life saver! Thank you very much, it works fantastically now!

(why the hell does gl assume we want to mipmap by default? - damn strange)