Sign in to follow this  
cyberninjaru

glBindTexture killing color of non-textured objects

Recommended Posts

Hey all, I have a quick question. What would cause glBindTexture to completely kill the color of my non-textured objects. When I comment out my SetupTextures() function which just binds some to the .bmps, the color of my non-textured objects are fine. Here is my SetupTextures() function:
void SetupTextures(void)
{
    // Generate 9 texture object ID's
    glGenTextures(9, tList);

    glBindTexture(GL_TEXTURE_2D, tList[XRAY]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\xray.bmp"))
			cout << "Failed to load xray.bmp"<<endl;
				 
    glBindTexture(GL_TEXTURE_2D, tList[LIGHTNING]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\lightning.bmp"))
			cout << "Failed to load lightning.bmp"<<endl;

    glBindTexture(GL_TEXTURE_2D, tList[FALL]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\fall.bmp"))
			cout << "Failed to load fall.bmp"<<endl;

    glBindTexture(GL_TEXTURE_2D, tList[COINS]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\coins.bmp"))
            cout <<"Failed to load coins.bmp"<<endl;

    glBindTexture(GL_TEXTURE_2D, tList[SAND]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\sand.bmp"))
			cout <<"Failed to load sand.bmp"<<endl;

    glBindTexture(GL_TEXTURE_2D, tList[STORM]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\eye.bmp"))
			cout << "Failed to load marble.bmp"<<endl;


    glBindTexture(GL_TEXTURE_2D, tList[MARBLE]);
		//Set Texture mapping parameters
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		if(!LoadBMP("Data\\marble.bmp"))
			cout << "Failed to load marble.bmp"<<endl;

    glBindTexture(GL_TEXTURE_2D, tList[GLASS]);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
	  	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	    if(!LoadBMP("Data\\glass.bmp"))
			cout <<"Failed to load glass.bmp" <<endl;

    glBindTexture(GL_TEXTURE_2D, tList[WALL]);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
	  	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	    if(!LoadBMP("Data\\Wall.bmp"))
			cout << "Failed to load wall.bmp"<<endl;

  }

tList is just an array of GLuints; I'm doing a demo for my school's open house and when I render my non-textured helicopter in with my textured objects, the helicopter's color becomes very dark. Any help with this would be much appreciated. Cyber

Share this post


Link to post
Share on other sites
I don't see any calls in there to glTexEnvi to setup the texture environment...

If you're not calling it, the default function is set to GL_REPLACE, so only the texture would appear on the polygons (ie: not blended with the vertex color). Since you want to modulate the texture with the vertex color, try using GL_MODULATE.

Share this post


Link to post
Share on other sites
Hi,

Thats possible and vice versa is also possible as color and texture is a global state. When you enable a texture and bind it it binds with every polygon until you explicitly state not to. The same goes with the color. If you want to draw textured and non textured object make sure that you call glBindTexture(GL_TEXTURE_2D, 0) so that no texture gets applied to the polygon. Similarly you want to call glColor3f(1, 1, 1) if you are drawing texture objects which should not be affected by color

Hope this helps

Share this post


Link to post
Share on other sites
Quote:
Original post by CRACK123
Thats possible and vice versa is also possible as color and texture is a global state. When you enable a texture and bind it it binds with every polygon until you explicitly state not to. The same goes with the color. If you want to draw textured and non textured object make sure that you call glBindTexture(GL_TEXTURE_2D, 0) so that no texture gets applied to the polygon. Similarly you want to call glColor3f(1, 1, 1) if you are drawing texture objects which should not be affected by color
Binding texture id 0 just binds the default texture, which could possibly be valid. The best way to make sure that a non-textured object doesn't have a texture applied to it is to disable every texture unit that you may have enabled. If a texture unit is disabled, then no texture state settings matter (including the enviroment).

Similarly, if you don't want color applied, setting the current color to white isn't really the right thing to do either. If you just want to use the texture color, set the environment to GL_REPLACE - the color will be ignored, so it won't matter what it is.

Share this post


Link to post
Share on other sites
Hey guys,

Thanks for the quick responses. The problem was a simple fix as all I needed to go was disable texturing before I rendered the object. Thanks for your suggestions though.

Cyber

Share this post


Link to post
Share on other sites
Quote:
Original post by Myopic Rhino
Binding texture id 0 just binds the default texture, which could possibly be valid. The best way to make sure that a non-textured object doesn't have a texture applied to it is to disable every texture unit that you may have enabled. If a texture unit is disabled, then no texture state settings matter (including the enviroment).


Thanks for that information. I was under the impression that 0 mean no texture.

Quote:
Original post by Myopic Rhino
Similarly, if you don't want color applied, setting the current color to white isn't really the right thing to do either. If you just want to use the texture color, set the environment to GL_REPLACE - the color will be ignored, so it won't matter what it is.


Yeah, you are right about this. It probably is a hack to set the color to white which seemed to work when I had a similar problem, but I guess in actual sense it need not.

Apparently I misunderstood some information somewhere. Thanks for correcting me.




Share this post


Link to post
Share on other sites
Quote:
Original post by bpoint
I don't see any calls in there to glTexEnvi to setup the texture environment...

If you're not calling it, the default function is set to GL_REPLACE, so only the texture would appear on the polygons (ie: not blended with the vertex color). Since you want to modulate the texture with the vertex color, try using GL_MODULATE.

Just to correct this, the default texture environment mode is GL_MODULATE, not GL_REPLACE.

Σnigma

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