mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 18:22:55 +02:00
Make text overlays apply alpha to text as well as background
This commit is contained in:
parent
d9141b4010
commit
8ac3aba2bd
5 changed files with 12 additions and 9 deletions
|
@ -68,7 +68,8 @@ var text = Overlays.addOverlay("text", {
|
||||||
color: { red: 255, green: 0, blue: 0},
|
color: { red: 255, green: 0, blue: 0},
|
||||||
topMargin: 4,
|
topMargin: 4,
|
||||||
leftMargin: 4,
|
leftMargin: 4,
|
||||||
text: "Here is some text.\nAnd a second line."
|
text: "Here is some text.\nAnd a second line.",
|
||||||
|
alpha: 0.7
|
||||||
});
|
});
|
||||||
|
|
||||||
// This will create an image overlay, which starts out as invisible
|
// This will create an image overlay, which starts out as invisible
|
||||||
|
|
|
@ -69,14 +69,16 @@ int TextRenderer::calculateHeight(const char* str) {
|
||||||
return maxHeight;
|
return maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextRenderer::draw(int x, int y, const char* str) {
|
int TextRenderer::draw(int x, int y, const char* str, float alpha) {
|
||||||
// Grab the current color
|
// Grab the current color
|
||||||
float currentColor[4];
|
float currentColor[4];
|
||||||
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
||||||
int compactColor = ((int( currentColor[0] * 255.f) & 0xFF)) |
|
alpha = std::max(0.f, std::min(alpha, 1.f));
|
||||||
((int( currentColor[1] * 255.f) & 0xFF) << 8) |
|
currentColor[3] *= alpha;
|
||||||
((int( currentColor[2] * 255.f) & 0xFF) << 16) |
|
int compactColor = ((int(currentColor[0] * 255.f) & 0xFF)) |
|
||||||
((int( currentColor[3] * 255.f) & 0xFF) << 24);
|
((int(currentColor[1] * 255.f) & 0xFF) << 8) |
|
||||||
|
((int(currentColor[2] * 255.f) & 0xFF) << 16) |
|
||||||
|
((int(currentColor[3] * 255.f) & 0xFF) << 24);
|
||||||
|
|
||||||
// TODO: Remove that code once we test for performance improvments
|
// TODO: Remove that code once we test for performance improvments
|
||||||
//glEnable(GL_TEXTURE_2D);
|
//glEnable(GL_TEXTURE_2D);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
int calculateHeight(const char* str);
|
int calculateHeight(const char* str);
|
||||||
|
|
||||||
// also returns the height of the tallest character
|
// also returns the height of the tallest character
|
||||||
int draw(int x, int y, const char* str);
|
int draw(int x, int y, const char* str, float alpha = 1.f);
|
||||||
|
|
||||||
int computeWidth(char ch);
|
int computeWidth(char ch);
|
||||||
int computeWidth(const char* str);
|
int computeWidth(const char* str);
|
||||||
|
|
|
@ -112,7 +112,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
||||||
QStringList lines = _text.split("\n");
|
QStringList lines = _text.split("\n");
|
||||||
int lineOffset = maxHeight;
|
int lineOffset = maxHeight;
|
||||||
foreach(QString thisLine, lines) {
|
foreach(QString thisLine, lines) {
|
||||||
textRenderer->draw(0, lineOffset, qPrintable(thisLine));
|
textRenderer->draw(0, lineOffset, qPrintable(thisLine), alpha);
|
||||||
lineOffset += maxHeight;
|
lineOffset += maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ void TextOverlay::render(RenderArgs* args) {
|
||||||
if (lineOffset == 0) {
|
if (lineOffset == 0) {
|
||||||
lineOffset = textRenderer->calculateHeight(qPrintable(thisLine));
|
lineOffset = textRenderer->calculateHeight(qPrintable(thisLine));
|
||||||
}
|
}
|
||||||
lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine));
|
lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine), alpha);
|
||||||
|
|
||||||
const int lineGap = 2;
|
const int lineGap = 2;
|
||||||
lineOffset += lineGap;
|
lineOffset += lineGap;
|
||||||
|
|
Loading…
Reference in a new issue