remove glColor calls related to text rendering

This commit is contained in:
ZappoMan 2015-01-28 13:54:48 -08:00
parent 7d9de6d0eb
commit 2f4e98082b
10 changed files with 24 additions and 46 deletions

View file

@ -107,12 +107,12 @@ void drawText(int x, int y, float scale, float radians, int mono,
glPushMatrix(); glPushMatrix();
glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f); glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
// TODO: add support for color to rendering text
glColor3fv(color);
glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0); glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0);
glScalef(scale / 0.1f, scale / 0.1f, 1.0f); glScalef(scale / 0.1f, scale / 0.1f, 1.0f);
textRenderer(mono)->draw(0, 0, string);
glm::vec4 colorV4 = {color[0], color[1], color[3], 1.0f };
textRenderer(mono)->draw(0, 0, string, colorV4);
glPopMatrix(); glPopMatrix();
} }

View file

@ -57,8 +57,6 @@ void AudioIOStatsRenderer::render(const float* color, int width, int height) {
int h = statsHeight; int h = statsHeight;
DependencyManager::get<GeometryCache>()->renderQuad(x, y, w, h, backgroundColor); DependencyManager::get<GeometryCache>()->renderQuad(x, y, w, h, backgroundColor);
glColor4f(1, 1, 1, 1); // TODO: change text rendering to use collor as parameter
int horizontalOffset = x + 5; int horizontalOffset = x + 5;
int verticalOffset = y; int verticalOffset = y;

View file

@ -703,12 +703,12 @@ void Avatar::renderDisplayName() {
DependencyManager::get<GeometryCache>()->renderBevelCornersRect(left, bottom, right - left, top - bottom, 3, DependencyManager::get<GeometryCache>()->renderBevelCornersRect(left, bottom, right - left, top - bottom, 3,
glm::vec4(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA)); glm::vec4(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA));
glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); // TODO: change text rendering to use collor as parameter glm::vec4 color(0.93f, 0.93f, 0.93f, _displayNameAlpha);
QByteArray ba = _displayName.toLocal8Bit(); QByteArray ba = _displayName.toLocal8Bit();
const char* text = ba.data(); const char* text = ba.data();
glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_POLYGON_OFFSET_FILL);
textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); textRenderer(DISPLAYNAME)->draw(text_x, text_y, text, color);
glPopMatrix(); glPopMatrix();

View file

@ -86,15 +86,6 @@ void BandwidthMeter::Stream::updateValue(double amount) {
glm::clamp(dt / _msToAverage, 0.0, 1.0)); glm::clamp(dt / _msToAverage, 0.0, 1.0));
} }
void BandwidthMeter::setColorRGBA(unsigned c) {
// TODO: add support for color to rendering text, since that's why this method is used
glColor4ub(GLubyte( c >> 24),
GLubyte((c >> 16) & 0xff),
GLubyte((c >> 8) & 0xff),
GLubyte( c & 0xff));
}
glm::vec4 BandwidthMeter::getColorRGBA(unsigned c) { glm::vec4 BandwidthMeter::getColorRGBA(unsigned c) {
float r = (c >> 24) / 255.0f; float r = (c >> 24) / 255.0f;
@ -165,10 +156,10 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) {
glTranslatef((float)barX, (float)y, 0.0f); glTranslatef((float)barX, (float)y, 0.0f);
// Render captions // Render captions
setColorRGBA(COLOR_TEXT); glm::vec4 textColor = getColorRGBA(COLOR_TEXT);
_textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT); _textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT, textColor);
_textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN); _textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN, textColor);
_textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT); _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT, textColor);
// Render vertical lines for the frame // Render vertical lines for the frame
renderVerticalLine(0, 0, h, COLOR_FRAME); renderVerticalLine(0, 0, h, COLOR_FRAME);
@ -226,15 +217,14 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) {
// Render numbers // Render numbers
char fmtBuf[8]; char fmtBuf[8];
setColorRGBA(COLOR_TEXT);
sprintf(fmtBuf, "%0.1f", totalIn); sprintf(fmtBuf, "%0.1f", totalIn);
_textRenderer->draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, _textRenderer->draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
PADDING_HORIZ_VALUE), PADDING_HORIZ_VALUE),
textYupperLine, fmtBuf); textYupperLine, fmtBuf, textColor);
sprintf(fmtBuf, "%0.1f", totalOut); sprintf(fmtBuf, "%0.1f", totalOut);
_textRenderer->draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, _textRenderer->draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
PADDING_HORIZ_VALUE), PADDING_HORIZ_VALUE),
textYlowerLine, fmtBuf); textYlowerLine, fmtBuf, textColor);
glPopMatrix(); glPopMatrix();

View file

@ -69,7 +69,6 @@ public:
ChannelInfo const& channelInfo(ChannelIndex i) const { return _channels[i]; } ChannelInfo const& channelInfo(ChannelIndex i) const { return _channels[i]; }
private: private:
static void setColorRGBA(unsigned c);
static glm::vec4 getColorRGBA(unsigned c); static glm::vec4 getColorRGBA(unsigned c);
static void renderBox(int x, int y, int w, int h, unsigned c); static void renderBox(int x, int y, int w, int h, unsigned c);
static void renderVerticalLine(int x, int y, int h, unsigned c); static void renderVerticalLine(int x, int y, int h, unsigned c);

View file

@ -124,13 +124,11 @@ void Text3DOverlay::render(RenderArgs* args) {
enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipDimensions.y); enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipDimensions.y);
enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);
// TODO: add support for color to rendering text glm::vec4 textColor = {_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, getAlpha() };
glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR);
float alpha = getAlpha();
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), alpha); textRenderer->draw(0, lineOffset, qPrintable(thisLine), textColor);
lineOffset += maxHeight; lineOffset += maxHeight;
} }

View file

@ -90,16 +90,15 @@ void TextOverlay::render(RenderArgs* args) {
int x = _bounds.left() + _leftMargin + leftAdjust; int x = _bounds.left() + _leftMargin + leftAdjust;
int y = _bounds.top() + _topMargin + topAdjust; int y = _bounds.top() + _topMargin + topAdjust;
// TODO: add support for color to rendering text
glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR);
float alpha = getAlpha(); float alpha = getAlpha();
glm::vec4 textColor = {_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, alpha };
QStringList lines = _text.split("\n"); QStringList lines = _text.split("\n");
int lineOffset = 0; int lineOffset = 0;
foreach(QString thisLine, lines) { foreach(QString thisLine, lines) {
if (lineOffset == 0) { if (lineOffset == 0) {
lineOffset = textRenderer->calculateHeight(qPrintable(thisLine)); lineOffset = textRenderer->calculateHeight(qPrintable(thisLine));
} }
lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine), alpha); lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine), textColor);
const int lineGap = 2; const int lineGap = 2;
lineOffset += lineGap; lineOffset += lineGap;

View file

@ -78,13 +78,11 @@ void RenderableTextEntityItem::render(RenderArgs* args) {
enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);
xColor textColor = getTextColorX(); xColor textColor = getTextColorX();
// TODO: add support for color to rendering text glm::vec4 textColorV4(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR, 1.0f);
glColor3f(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR);
QStringList lines = _text.split("\n"); QStringList lines = _text.split("\n");
int lineOffset = maxHeight; int lineOffset = maxHeight;
float textAlpha = 1.0f; // getTextAlpha()
foreach(QString thisLine, lines) { foreach(QString thisLine, lines) {
textRenderer->draw(0, lineOffset, qPrintable(thisLine), textAlpha); textRenderer->draw(0, lineOffset, qPrintable(thisLine), textColorV4);
lineOffset += maxHeight; lineOffset += maxHeight;
} }

View file

@ -70,16 +70,11 @@ int TextRenderer::calculateHeight(const char* str) {
return maxHeight; return maxHeight;
} }
int TextRenderer::draw(int x, int y, const char* str, float alpha) { int TextRenderer::draw(int x, int y, const char* str, const glm::vec4& color) {
// Grab the current color int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
float currentColor[4]; ((int(color.y * 255.0f) & 0xFF) << 8) |
glGetFloatv(GL_CURRENT_COLOR, currentColor); ((int(color.z * 255.0f) & 0xFF) << 16) |
alpha = std::max(0.0f, std::min(alpha, 1.0f)); ((int(color.w * 255.0f) & 0xFF) << 24);
currentColor[3] *= alpha;
int compactColor = ((int(currentColor[0] * 255.0f) & 0xFF)) |
((int(currentColor[1] * 255.0f) & 0xFF) << 8) |
((int(currentColor[2] * 255.0f) & 0xFF) << 16) |
((int(currentColor[3] * 255.0f) & 0xFF) << 24);
int maxHeight = 0; int maxHeight = 0;
for (const char* ch = str; *ch != 0; ch++) { for (const char* ch = str; *ch != 0; ch++) {

View file

@ -13,6 +13,7 @@
#define hifi_TextRenderer_h #define hifi_TextRenderer_h
#include <gpu/GPUConfig.h> #include <gpu/GPUConfig.h>
#include <glm/glm.hpp>
#include <QColor> #include <QColor>
#include <QFont> #include <QFont>
@ -70,7 +71,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, float alpha = 1.0f); int draw(int x, int y, const char* str, const glm::vec4& color);
int computeWidth(char ch); int computeWidth(char ch);
int computeWidth(const char* str); int computeWidth(const char* str);