简体   繁体   中英

OpenGL: glTexEnvi, glBlendFunc and On Screen Text Messages

I'm developing a movie player 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. (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM