Sign in to follow this  
matrix2681

texture mapping question

Recommended Posts

I've got a frustrating problem. The end result of an operation is supposed to map a texture onto a square to show what the texture looks like. It maps it fine, but the colors have all been converted to grayscale. Does anybody know what might cause this? Thanks, Michael

Share this post


Link to post
Share on other sites
Hey bud,

I dunno what API you are using, but the only thing i can think of that might cause it would be the back buffer format. Not sure how that applies to OpenGL if that is what you are using.

Dave

Share this post


Link to post
Share on other sites
Whoops, forgot to say: yeah I'm using OpenGL for this.

Whatever the problem is it looks like maybe a line or two got left out somewhere, but in all the texmapping tutorials I've looked at everything seems sound. I'll have to take a closer look.

Share this post


Link to post
Share on other sites
Ok problem solved I think:

The lines where the texture is loaded into memory that look like:

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);


have to be in that order. I had a couple switched around and now it shows up properly.

Share this post


Link to post
Share on other sites
A niggle for this is that you're using a literal 3 for the internal format parameter (arg #3) which is kind of a deprecated way of doing things. You should use the symbolic constants for formatting (GL_RGBA, GL_RGB (which should be ==3), GL_RED, etc.) throughout.

I'm not sure how rearranging those lines of code would cause you to get a monochromatic image unless you uploaded the texture data before binding. Or, if that 3 had been a 1 previously.

Share this post


Link to post
Share on other sites
Originally I got the code from one of the NeHe tutorials, so that's why the 3 shows up in there. Also I think I had the lines for filtering before the lines where the data was loaded in. I got rid of the faulty code as quickly as possible ;)

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