mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-17 03:30:30 +02:00
Merge pull request #3780 from ctrlaltdavid/20182
CR for Job #20182 - Add ability to set alpha on text overlays
This commit is contained in:
commit
99dd20f828
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},
|
||||
topMargin: 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
|
||||
|
|
|
@ -69,14 +69,16 @@ int TextRenderer::calculateHeight(const char* str) {
|
|||
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
|
||||
float currentColor[4];
|
||||
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
||||
int compactColor = ((int( currentColor[0] * 255.f) & 0xFF)) |
|
||||
((int( currentColor[1] * 255.f) & 0xFF) << 8) |
|
||||
((int( currentColor[2] * 255.f) & 0xFF) << 16) |
|
||||
((int( currentColor[3] * 255.f) & 0xFF) << 24);
|
||||
alpha = std::max(0.f, std::min(alpha, 1.f));
|
||||
currentColor[3] *= alpha;
|
||||
int compactColor = ((int(currentColor[0] * 255.f) & 0xFF)) |
|
||||
((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
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
int calculateHeight(const char* str);
|
||||
|
||||
// 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(const char* str);
|
||||
|
|
|
@ -112,7 +112,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
QStringList lines = _text.split("\n");
|
||||
int lineOffset = maxHeight;
|
||||
foreach(QString thisLine, lines) {
|
||||
textRenderer->draw(0, lineOffset, qPrintable(thisLine));
|
||||
textRenderer->draw(0, lineOffset, qPrintable(thisLine), alpha);
|
||||
lineOffset += maxHeight;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void TextOverlay::render(RenderArgs* args) {
|
|||
if (lineOffset == 0) {
|
||||
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;
|
||||
lineOffset += lineGap;
|
||||
|
|
Loading…
Reference in a new issue