From 77ce737f61e22e72c7e1032cdaa0177224bad013 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 3 Feb 2015 22:11:24 -0800 Subject: [PATCH] Working on porting renderable text item to new code --- .../src/RenderableTextEntityItem.cpp | 53 +++++-------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index b3f4baa5ba..6a97a1c6be 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -26,6 +26,11 @@ EntityItem* RenderableTextEntityItem::factory(const EntityItemID& entityID, cons return new RenderableTextEntityItem(entityID, properties); } +glm::vec3 toGlm(const xColor & color) { + static const float MAX_COLOR = 255.0f; + return std::move(glm::vec3(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR)); +} + void RenderableTextEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableTextEntityItem::render"); assert(getType() == EntityTypes::Text); @@ -46,51 +51,21 @@ void RenderableTextEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - const float MAX_COLOR = 255.0f; - xColor backgroundColor = getBackgroundColorX(); float alpha = 1.0f; //getBackgroundAlpha(); - glm::vec4 color(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha); - - const float SLIGHTLY_BEHIND = -0.005f; + static const float SLIGHTLY_BEHIND = -0.005f; glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - DependencyManager::get()->renderQuad(topLeft, bottomRight, color); - - const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation - - // Same font properties as textSize() - TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); - float maxHeight = (float)textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO; - - float scaleFactor = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight; + DependencyManager::get()->renderQuad(topLeft, bottomRight, glm::vec4(toGlm(getBackgroundColorX()), alpha)); + + TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE / 2.0f); glTranslatef(-(halfDimensions.x - leftMargin), halfDimensions.y - topMargin, 0.0f); - - glm::vec2 clipMinimum(0.0f, 0.0f); - glm::vec2 clipDimensions((dimensions.x - (leftMargin + rightMargin)) / scaleFactor, - (dimensions.y - (topMargin + bottomMargin)) / scaleFactor); - - glScalef(scaleFactor, -scaleFactor, 1.0); - enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipDimensions.x); - enableClipPlane(GL_CLIP_PLANE1, 1.0f, 0.0f, 0.0f, -clipMinimum.x); - 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); - - xColor textColor = getTextColorX(); - glm::vec4 textColorV4(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR, 1.0f); - QStringList lines = _text.split("\n"); - int lineOffset = maxHeight; - foreach(QString thisLine, lines) { - textRenderer->draw(0, lineOffset, qPrintable(thisLine), textColorV4); - lineOffset += maxHeight; - } - - glDisable(GL_CLIP_PLANE0); - glDisable(GL_CLIP_PLANE1); - glDisable(GL_CLIP_PLANE2); - glDisable(GL_CLIP_PLANE3); - + glm::vec4 textColor(toGlm(getTextColorX()), alpha); + // this is a ratio determined through experimentation + static const float testScaleFactor = 0.01f; + glScalef(testScaleFactor, -testScaleFactor, testScaleFactor); + textRenderer->draw(0, 0, _text, textColor); } glPopMatrix(); }