PDA

View Full Version : textures are getting a color.... what the hell?



Structural
11-19-2002, 03:17 AM
My second problem I've encountered...

I'm making an object-oriented program now, that draws object that are specified in the init. I also included the ability to set colors and textures of planes of the object.

What I have is an object that is colorred yellow, after that another object is drawn with a texture (the texture is a BMP and has a white background).
What happens is that it draws both objects nicely, but for some odd reason it SEEMS as if it does an addition to the colors (the red in the texture becomes orange-ish, the white yellow)
Also appear the white parts of the texture as a grey-ish color WHEN there is no color defined before it is drawn.

I have the vague idea that I set some transparency property somewhere, but I can't locate it...
Any tips on what the problem could be and how I can get it out?

[This message has been edited by Structural (edited 11-19-2002).]

rIO
11-19-2002, 03:34 AM
It sounds like you have color material enabled.
Try to disable GL_COLOR_MATERIAL and everything should get nicer http://www.opengl.org/discussion_boards/ubb/smile.gif
Or just set a white color before rendering the second object.

hope this helps

Structural
11-19-2002, 03:45 AM
I'm affraid that's not the problem...
I never enabled GL_COLOR_MATERIAL, and even when I disable it the coloring remains the same http://www.opengl.org/discussion_boards/ubb/frown.gif




int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
}

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

camera.position(0, 0, 12.0f, 0, 0, 0, 0, 1.0f, 0);

obj1 = Object3D(0,0,0,0,0,0);

obj1.addpoint(1,1,1);
obj1.addpoint(-1,1,1);
obj1.addpoint(-1,-1,1);
obj1.addpoint(1,-1,1);

obj1.addpoint(1,1,-1);
obj1.addpoint(-1,1,-1);
obj1.addpoint(-1,-1,-1);
obj1.addpoint(1,-1,-1);


obj1.addquad(0,1,2,3);
obj1.setColor(255,255,255);
obj1.addquad(1,5,6,2);
obj1.setColor(255,255,0);


return TRUE; // Initialization Went OK
}


object2 is drawn and enabled in another piece of code

[This message has been edited by Structural (edited 11-19-2002).]

Deiussum
11-19-2002, 05:23 AM
Color material itself wouldn't be the problem. All that does is allow you to use glColor to set material properties.

But, you could be seeing the color modulated with the texture because the default mode for glTexEnv is GL_MODULATE. Try setting the color (or material if you have lighting enabled) to white, or use glTexEnv to set the mode to GL_REPLACE.

Structural
11-19-2002, 06:19 AM
Again, I'm affraid that is not the problem...

I made a screenshot of the situation: http://www.geocities.com/structual/bla.html?ogl1.jpg

As you see is the right plane of the centre object grey-ish. I told it to be WHITE.
Also is the yellow color not completely pure yellow... I have the idea that the background is shining through for some odd reason.

All this still doesn't explain why the outer two cubes are yellow, while the bitmap is white.

I do have to say that I took some lighting OUT OF the program this morning. In my entire code there isn't a single occurence of "light" that isn't commented, so I don't believe that the problem is in any lighting.

http://www.opengl.org/discussion_boards/ubb/frown.gif

M/\dm/\n
11-19-2002, 07:29 AM
I've experienced similar problem, I don't know the solution yet. The idea is that after enabling brick wall texture (orange is dominating) all other objects I draw inherit this orange color. Mostly because I'm using all textured objects I didn't paid attention to it, but as I remember I rendered everything in lists, and objects that are drawn after caling lists are drawn correctly. I can only say that this "problem" actualy helped me.
This might be your case?

Deiussum
11-19-2002, 08:08 AM
Have you tried adding this to your init yet?

glTexEnv(GL_TEXTURE_ENV, GL_REPLACE);

One other thought:
Do you use blending anywhere?

[This message has been edited by Deiussum (edited 11-19-2002).]

Deiussum
11-19-2002, 08:10 AM
M/\dm/\n, are you saying that when you enabled a texture, your other objects seemed to have the color of that texture? Were these only on other objects that didn't have textures? If so, you probably just forgot to enable texturing before drawing those, and if you had no texcoords, they would have essentially gotten the color from one pixel of the texture.

Structural
11-19-2002, 09:09 AM
glTexEnv shows up as an undefined identifier here on this computer.

I VERY carefully read NeHe's coloring tutorial, and found out something interresting (interresting for ME):



Now we will draw a solid blue colored square. It's important to remember that anything drawn after the color has been set will be drawn in that color. Every project you create down the road will use coloring in one way or another. Even in scenes where everything is texture mapped, glColor3f can still be used to tint the color of textures, etc. More on that later.


It states that the coloring can be used to tint a texture. That is where my colored cube came from... Still, it doesn't solve the mistery of the slightly grey-ish plane in the screenshot I showed and the un-pure yellow. On this computer (Much faster than the one I used this afternoon and a better videocard) the coloring is nice and bright. The yellow shown is PURE yellow.

Anyway, with that little problem out of the way, I have run into something new...
As I've said, I'm running my code on another computer now (a win2k platform) and it appears as if the BLUE property of the coloring doesn't work. A WHITE plane appears as YELLOW, and a BLUE plane doesn't appear at all (presumably black)
I use the glColor3f(float,float,float) function for my coloring at the moment.

I hope my openGL book arrives soon so I can work that through....

Deiussum
11-19-2002, 09:50 AM
I'm sorry, glTexEnvi or glTexEnvf. Follows the same naming standard as all OpenGL calls.

And that bit you posted sounds a lot like what I tried to state in an above post, but you claim that can't be it. Basically the default for glTexEnv is GL_MODULATE, which will cause the color (or material properties if lighting is enabled) to modulate with the texture. (Didn't I state that above? I feel like I'm re-typing stuff here.)

If you change glTexEnv's mode to GL_REPLACE, the texture will replace the color (or material properties) instead of being modulated.

Structural
11-19-2002, 10:10 AM
I'm sorry Deiussum. I've started with OpenGl a few days ago, so I'm not fully familiar with certain terms.
Nor am I English, so I might have difficulty with certain wording too.

Anyway, I've tried the glTexEnvi and glTexEnvf both with extreme values as last parameter, but no result (the error is gone tho). Could you give me a concrete example of how to use this?

I do have to say that you are fully right about the modulating bit. I shall never question you again http://www.opengl.org/discussion_boards/ubb/wink.gif
I had my filtering set to the lowest (due to my work PC I used this afternoon being crap) so I couldn't see the modulation at all.
Another question of mine is: does this modulation work in order of rendering or in any particular order? because, I have a polygon without texture rendered first, and it appears to be affected by the texture that is rendered in a later stage.

Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Structural (edited 11-19-2002).]

Deiussum
11-19-2002, 12:37 PM
What do you mean by extreme parameters? there are only a few values you should be using for the last parameter. GL_MODULATE, GL_DECAL, GL_REPLACE, and GL_BLEND.

I just noticed something when looking those up. I told you the wrong thing to use for the parameters for that in the first place. (BTW, you can use msdn.microsoft.com to look up information on all the OpenGL functions.)

You should have tried this:

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

There's no ordering associated with the modulation. OpenGL is a state machine. Once you set the state of something (like color, or texture environment mode) it stays that state until you change it again.

Example:

drawmodel(); // Model drawn with whatever the current color is

setcoloryellow();
drawmodel(); // model drawn with yellow color

drawmodel2(); // model2 drawn with yellow color

setcolorwhite();
drawmodel3(); // model3 drawn with white


Hope that helps.

Structural
11-19-2002, 10:14 PM
Thank you Deiussum, both for your help and patience http://www.opengl.org/discussion_boards/ubb/wink.gif
It seems as if your solution solved the problem half. And I'm beginning to understand the coloring system in OpenGL, altho it's still a mistery to me why MODULATING is on by default and not REPLACE.

The textures appear perfectly now, yet the quads colored with glColor3f(float,float,float) don't have their original color anymore: http://www.geocities.com/structual/bla.html?GL2-2.jpg

The most right quad is supposed to be blue, yet lost it's original color completely.

Is it common to use colored polygons and textures in the same program or is there usually made an explicit choice for either one of them?

M/\dm/\n
11-20-2002, 01:13 AM
Originally posted by Deiussum:
M/\dm/\n, are you saying that when you enabled a texture, your other objects seemed to have the color of that texture? Were these only on other objects that didn't have textures? If so, you probably just forgot to enable texturing before drawing those, and if you had no texcoords, they would have essentially gotten the color from one pixel of the texture.

If I remember correctly then I disabled texture maping before drawing texture colored rectangles. But the fact is this "bug" actualy looks nice, I know how to do it and thats all I care. It's geting bit complicated with multitexturing and lightmaps when you don't need one used all the time, but it's posible to disable texture unit or if that fails bind NULL to it. You can try that in this case. I can't assure you that this is 100% correct, because I don't have the code with me & I'm currently working with shaders. But I like the idea You mentioned & I'll check this out somday http://www.opengl.org/discussion_boards/ubb/smile.gif

Deiussum
11-20-2002, 05:48 AM
Could you be forgetting to disable textures when you draw the one without the texture?

Try something like this:

glEnable(GL_TEXTURE_2D);
DrawTexturedObject();

glDisable(GL_TEXTURE_2D);
DrawUnTexturedObject();

Structural
11-20-2002, 06:41 AM
Sir, you are my God!


***waits patiently for his OpenGL book to arive***