OpenGL: glTexEnvi, glBlendFunc and On Screen Text Messages
I'm developing a movie player 开发者_C百科and I'm using OpenGL to draw frames and On Screen Messages.
To draw the frame I use:
glBegin(GL_QUADS);
// Draw the quads
glTexCoord2f(0.0f, 0.0f);
glVertex2f (_movieRect.origin.x,_movieRect.origin.y + _movieRect.size.height);
glTexCoord2f(0.0f, _imageRect.size.height);
glVertex2f (_movieRect.origin.x, _movieRect.origin.y );
glTexCoord2f(_imageRect.size.width, _imageRect.size.height);
glVertex2f (_movieRect.origin.x + _movieRect.size.width,_movieRect.origin.y);
glTexCoord2f(_imageRect.size.width, 0.0f);
glVertex2f (_movieRect.origin.x + _movieRect.size.width, _movieRect.origin.y + _movieRect.size.height);
glEnd();
while to draw the On Screen Message I draw a rectangle which contains the representation of the text that I'm going to show. To handle transparency I do this before drawing text message:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
I want now to give the option to modify brightness in real-time. To achieve this I'm using:
double t = _brightnessValue;
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
if (t > 1.0f)
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glColor4f(t-1, t-1, t-1, t-1);
}
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_SUBTRACT);
glColor4f(1-t, 1-t, 1-t, 1-t);
}
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
The brightness is modified correctly but now text messages are wrong. The rectangle around the text is transparent only when brightness has its default value and even text is affected by the brightness correction. (i.e. the text is white as default and it becomes more and more gray as I reduce brightness).
Does the brightness regulation change the alpha spectrum outside 0-1? How can I solve this problem?
I'm sorry if this sounds stupid but it's the first time that I'm using OpenGL
Remember, OpenGL is a state machine. You can set your TexEnv state, draw the frame, then change the TexEnv state back to normal, and draw your OSD.
精彩评论