PDA

View Full Version : Is this a blending problem?



08-01-2003, 10:55 AM
I have an texture and i want to write some
text on it.But i cant set the text color.

For example:

if i have a blue texture and i try to write
red text on it.But the color seems pink.Is this a blending problem ?

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); /* X1

glColor4ub(255,0,0,255);
Font->Print(10,200,"PROBLEM");

/*****************************************/

glColor3f(1,1,1);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);/* X2 I think this is the problem

/* This is a blue texture
glBindTexture(GL_TEXTURE_2D, gl->textures[1].texID);

glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(10, 200, 1.0f);
glTexCoord2f(1, 0); glVertex3f(266,200, 1.0f);
glTexCoord2f(1, 1); glVertex3f(266,232, 1.0f);
glTexCoord2f(0, 1); glVertex3f(10,232, 1.0f);

glEnd();

İf so what is the suitable X2 function?
Thanks...

torisutan
08-01-2003, 04:29 PM
make sure GL_TEXTURE_2D is enabled
sounds silly i know, but i wasted about an hour debuging my code once after i ported existing font code over to a new program, and all it was, was the way i enabled GL_TEXTURE_2D was different in the 2 programs.

If thats not your problem, try find a tutorial on using display lists to display fonts, i use display lists, and they make things a lot simpler.

check http://nehe.gamedev.net/ or http://www.gametutorials.com/ their tutorials are very very helpful when starting out with opengl.

good luck
--Tristan

Overmind
08-03-2003, 06:55 AM
I don't know what Font->Print does, but if you are blending a blue texture and red text together, it is logical that you get pink.

If you want non-transparent red text, you have to render the backgroud first and then render the text with blend function GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (or with alpha test).

08-04-2003, 06:53 AM
When i render background first, my text disapper; but when i render text first then
background texture, my text color seems pink.
And i tried many variates of blend function
but i didnt find the correct one.

My last render code seems like this and my text invisible ;

glEnable(GL_TEXTURE_2D);

glColor3f(1,1,1);

glBlendFunc(GL_ONE,GL_ONE);

glBindTexture(GL_TEXTURE_2D, gl->textures[1].texID);

glBegin(GL_QUADS);

glTexCoord2f(0, 0); glVertex3f(10, 200, 1.0f);
glTexCoord2f(1, 0); glVertex3f(266,200, 1.0f);
glTexCoord2f(1, 1); glVertex3f(266,232, 1.0f);
glTexCoord2f(0, 1); glVertex3f(10,232, 1.0f);

glEnd();

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glColor4ub(204,204,204,255);
gl->p->Print(10,200," Problem ");


glDisable(GL_TEXTURE_2D);


So what is the solution?