Jump to content
  • Advertisement
Sign in to follow this  
HL706

OpenGL Problems with glColor3f() and texture rendering.

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, my problems are relatively simple, but I don't really know enough OpenGL to sort them. I'm rendering two bitmaps and a text string (taken from Nehe's bitmap font code) and trying to change the colour of the string. Here is my code for the main loop:

case IDLE:
				if( ! this->mRuntime->ProcessEvents( pClickedID ) )
					return false;

				this->mRender->PreRenderProcess( );

				glClearColor( 1, 0, 0, 0 );

				this->mRender->RenderButtons( this->mBitmapHandler, pButtonHandler->GetButtons( ), pClickedID );				

				glColor4f( 0, 1, 0, 0 );
				this->mFontHandler->PrintText( 50, 500, this->mScreenHeight, "Help Me Please!" );


				this->mRender->PostRenderProcess( this->mDC );

				break;

The code for rendering buttons is:

glDisable( GL_DEPTH_TEST );
	glEnable( GL_BLEND );
	glEnable( GL_TEXTURE_2D );

	if( pUseMask )
	{
		glBlendFunc( GL_DST_COLOR, GL_ZERO );
		glBindTexture( GL_TEXTURE_2D, pTextureMask );
		glBegin(GL_QUADS);

			glTexCoord2f( 0.0f, 1.0f );		glVertex2i( pX, pY );
			glTexCoord2f( 1.0f, 1.0f );		glVertex2i( pX + pW, pY );
			glTexCoord2f( 1.0f, 0.0f );		glVertex2i( pX + pW, pY + pH );
			glTexCoord2f( 0.0f, 0.0f );		glVertex2i( pX, pY + pH );

		glEnd( );

		glBlendFunc( GL_ONE, GL_ONE );
	}	

	glBindTexture( GL_TEXTURE_2D, pTexture );

	glBegin(GL_QUADS);

			glTexCoord2f( 0.0f, 1.0f );		glVertex2i( pX, pY );
			glTexCoord2f( 1.0f, 1.0f );		glVertex2i( pX + pW, pY );
			glTexCoord2f( 1.0f, 0.0f );		glVertex2i( pX + pW, pY + pH );
			glTexCoord2f( 0.0f, 0.0f );		glVertex2i( pX, pY + pH );
	
	glEnd( );

	glDisable( GL_BLEND );
	glEnable( GL_DEPTH_TEST );
	glDisable( GL_TEXTURE_2D );

The problem is that the bitmaps themselves are being blended with the colour i've set for the text which is obviously not what i'm looking for. The only problem is that my OpenGL is so rusty that i've forgotten pretty much everything >:( Any help anyone could give would be greatly appreciated. Finally, here are two screenshots showing the problem: Using glColor3f() -- http://drive.123-reg.co.uk/F/1980285-147313551 Not using glColor3f() -- http://drive.123-reg.co.uk/F/1980285-147314125

Share this post


Link to post
Share on other sites
Advertisement
The problem is that once set the color is used until you change it, i.e. after the first frame the buttons will also use that color.

AFAIK the default texture combine mode is G_MODULATE so the texture will be modulated with the color. You have two options:
1. call glColor3f(1.0f, 1.0f, 1.0f) before rendering the button
2. call glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)

I'd suggest using the first option since you might want to modulate some textures with the vertex color, e.g. for lighting. Then you'd have to change the texture combine mode to GL_MODULATE again.

Share this post


Link to post
Share on other sites
I took your advice and went with option one and everything works perfectly.

Thanks for your help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!