From a8c28a6d2aa9d87bfd0c6d6d441d33fb0f3d86a5 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 29 Apr 2013 18:54:12 -0700 Subject: [PATCH 01/10] First stab at text rendering by rendering glyphs (using Qt's font rendering) into textures, storing the associated metrics, and drawing strings as sequences of textured quads. --- interface/src/ui/TextRenderer.cpp | 129 ++++++++++++++++++++++++++++++ interface/src/ui/TextRenderer.h | 81 +++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 interface/src/ui/TextRenderer.cpp create mode 100644 interface/src/ui/TextRenderer.h diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp new file mode 100644 index 0000000000..8488a01ce7 --- /dev/null +++ b/interface/src/ui/TextRenderer.cpp @@ -0,0 +1,129 @@ +// +// TextRenderer.cpp +// interface +// +// Created by Andrzej Kapolka on 4/24/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. + +#include +#include +#include + +#include "InterfaceConfig.h" +#include "TextRenderer.h" + +// the width/height of the cached glyph textures +const int IMAGE_SIZE = 256; + +Glyph::Glyph(int textureID, const QPoint& location, const QRect& bounds, int width) : + _textureID(textureID), _location(location), _bounds(bounds), _width(width) { +} + +TextRenderer::TextRenderer(const char* family, int pointSize, int weight, bool italic) + : _font(family, pointSize, weight, italic), + _metrics(_font), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0) { +} + +void TextRenderer::draw(int x, int y, const char* str) { + + glEnable(GL_TEXTURE_2D); + + for (const char* ch = str; *ch != 0; ch++) { + const Glyph& glyph = getGlyph(*ch); + if (glyph.textureID() == 0) { + x += glyph.width(); + continue; + } + + glBindTexture(GL_TEXTURE_2D, glyph.textureID()); + + int left = x + glyph.bounds().x(); + int right = x + glyph.bounds().x() + glyph.bounds().width(); + int bottom = y + glyph.bounds().y(); + int top = y + glyph.bounds().y() + glyph.bounds().height(); + + float scale = 1.0 / IMAGE_SIZE; + float ls = glyph.location().x() * scale; + float rs = (glyph.location().x() + glyph.bounds().width()) * scale; + float bt = glyph.location().y() * scale; + float tt = (glyph.location().y() + glyph.bounds().height()) * scale; + + glBegin(GL_QUADS); + glTexCoord2f(ls, bt); + glVertex2f(left, bottom); + glTexCoord2f(rs, bt); + glVertex2f(right, bottom); + glTexCoord2f(rs, tt); + glVertex2f(right, top); + glTexCoord2f(ls, tt); + glVertex2f(left, top); + glEnd(); + + x += glyph.width(); + } + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); +} + +int TextRenderer::computeWidth(char ch) +{ + return getGlyph(ch).width(); +} + +int TextRenderer::computeWidth(const char* str) +{ + int width = 0; + for (const char* ch = str; *ch != 0; ch++) { + width += computeWidth(*ch); + } + return width; +} + +const Glyph& TextRenderer::getGlyph(char c) { + Glyph& glyph = _glyphs[c]; + if (glyph.isValid()) { + return glyph; + } + QRect bounds = _metrics.boundingRect(c); + if (bounds.isEmpty()) { + glyph = Glyph(0, QPoint(), QRect(), _metrics.width(c)); + return glyph; + } + + if (_x + bounds.width() > IMAGE_SIZE) { + // we can't fit it on the current row; move to next + _y += _rowHeight; + _x = _rowHeight = 0; + } + if (_y + bounds.height() > IMAGE_SIZE) { + // can't fit it on current texture; make a new one + glGenTextures(1, &_textureID); + _x = _y = _rowHeight = 0; + + glBindTexture(GL_TEXTURE_2D, _textureID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + } else { + glBindTexture(GL_TEXTURE_2D, _textureID); + } + // render the glyph into an image and copy it into the texture + QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32); + image.fill(0); + { + QPainter painter(&image); + painter.setFont(_font); + painter.setPen(QColor(255, 255, 255)); + painter.drawText(-bounds.x(), -bounds.y(), QChar(c)); + } + glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); + + glyph = Glyph(_textureID, QPoint(_x, _y), bounds, _metrics.width(c)); + _x += bounds.width(); + _rowHeight = qMax(_rowHeight, bounds.height()); + + glBindTexture(GL_TEXTURE_2D, 0); + return glyph; +} diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h new file mode 100644 index 0000000000..840e686075 --- /dev/null +++ b/interface/src/ui/TextRenderer.h @@ -0,0 +1,81 @@ +// +// TextRenderer.h +// interface +// +// Created by Andrzej Kapolka on 4/26/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__TextRenderer__ +#define __interface__TextRenderer__ + +#include +#include +#include +#include + +class Glyph; + +class TextRenderer { +public: + + TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false); + + const QFontMetrics& metrics() const { return _metrics; } + + void draw(int x, int y, const char* str); + + int computeWidth(char ch); + int computeWidth(const char* str); + +private: + + const Glyph& getGlyph (char c); + + // the font to render + QFont _font; + + // the font metrics + QFontMetrics _metrics; + + // maps characters to cached glyph info + QHash _glyphs; + + // the id of the glyph texture to which we're currently writing + GLuint _textureID; + + // the position within the current glyph texture + int _x, _y; + + // the height of the current row of characters + int _rowHeight; +}; + +class Glyph { +public: + + Glyph(int textureID = 0, const QPoint& location = QPoint(), const QRect& bounds = QRect(), int width = 0); + + GLuint textureID() const { return _textureID; } + const QPoint& location () const { return _location; } + const QRect& bounds() const { return _bounds; } + int width () const { return _width; } + + bool isValid() { return _width != 0; } + +private: + + // the id of the OpenGL texture containing the glyph + GLuint _textureID; + + // the location of the character within the texture + QPoint _location; + + // the bounds of the character + QRect _bounds; + + // the width of the character (distance to next, as opposed to bounds width) + int _width; +}; + +#endif /* defined(__interface__TextRenderer__) */ From 068d3d216e58c53151da4ddd1d641d5d35ac816c Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 29 Apr 2013 19:12:34 -0700 Subject: [PATCH 02/10] Need to commit these, too, for the font rendering change. --- interface/CMakeLists.txt | 12 ++++++-- interface/src/Avatar.cpp | 27 ++++++++++------ interface/src/ChatEntry.cpp | 4 +-- interface/src/ChatEntry.h | 4 +-- interface/src/Log.cpp | 24 ++++++--------- interface/src/MenuColumn.cpp | 9 +++++- interface/src/Util.cpp | 60 +++++++++++------------------------- interface/src/Util.h | 1 + interface/src/main.cpp | 7 +++++ 9 files changed, 75 insertions(+), 73 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index e4e8dc1614..360caea152 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -30,8 +30,12 @@ include_glm(${TARGET_NAME} ${ROOT_DIR}) # create the InterfaceConfig.h file based on GL_HEADERS above configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h) -# grab the implementation and header files from src dir +# grab the implementation and header files from src dirs file(GLOB INTERFACE_SRCS src/*.cpp src/*.h) +foreach(SUBDIR ui) + file(GLOB SUBDIR_SRCS src/${SUBDIR}/*.cpp src/${SUBDIR}/*.h) + set(INTERFACE_SRCS ${INTERFACE_SRCS} ${SUBDIR_SRCS}) +endforeach(SUBDIR) # project subdirectories add_subdirectory(src/starfield) @@ -73,10 +77,14 @@ include_directories( ${LODEPNG_INCLUDE_DIRS} ) +find_package(Qt4 REQUIRED QtCore QtGui) +include(${QT_USE_FILE}) +target_link_libraries(${TARGET_NAME} ${QT_LIBRARIES}) + if (NOT APPLE) find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) - include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) + include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${}) target_link_libraries(${TARGET_NAME} ${OPENGL_LIBRARY}) else (NOT APPLE) # link in required OS X frameworks and include the right GL headers diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 24af81dfdf..61cd83b845 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -13,6 +13,7 @@ #include #include "Avatar.h" #include "Log.h" +#include "ui/TextRenderer.h" #include #include #include @@ -39,7 +40,7 @@ bool usingBigSphereCollisionTest = true; char iris_texture_file[] = "resources/images/green_eye.png"; -float chatMessageScale = 0.00025; +float chatMessageScale = 0.001; float chatMessageHeight = 0.4; vector iris_texture; @@ -618,6 +619,11 @@ void Avatar::setDisplayingHead( bool displayingHead ) { } +static TextRenderer* textRenderer() { + static TextRenderer* renderer = new TextRenderer("Helvetica", 24); + return renderer; +} + void Avatar::render(bool lookingInMirror) { /* @@ -667,10 +673,10 @@ void Avatar::render(bool lookingInMirror) { } if (!_chatMessage.empty()) { - float width = 0; - float lastWidth; + int width = 0; + int lastWidth; for (string::iterator it = _chatMessage.begin(); it != _chatMessage.end(); it++) { - width += (lastWidth = glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*chatMessageScale); + width += (lastWidth = textRenderer()->computeWidth(*it)); } glPushMatrix(); @@ -682,11 +688,14 @@ void Avatar::render(bool lookingInMirror) { glTranslatef(_position.x, _position.y + chatMessageHeight, _position.z); glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); - glTranslatef(width * 0.5, 0, 0); + glColor3f(0, 1, 0); + glRotatef(180, 0, 0, 1); + glScalef(chatMessageScale, chatMessageScale, 1.0f); + glDisable(GL_LIGHTING); if (_keyState == NO_KEY_DOWN) { - drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + textRenderer()->draw(-width/2, 0, _chatMessage.c_str()); } else { // rather than using substr and allocating a new string, just replace the last @@ -694,11 +703,9 @@ void Avatar::render(bool lookingInMirror) { int lastIndex = _chatMessage.size() - 1; char lastChar = _chatMessage[lastIndex]; _chatMessage[lastIndex] = '\0'; - drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + textRenderer()->draw(-width/2, 0, _chatMessage.c_str()); _chatMessage[lastIndex] = lastChar; - glTranslatef(lastWidth - width, 0, 0); - drawtext(0, 0, chatMessageScale, 180, 3.0, - 0, _chatMessage.c_str() + lastIndex, 0, 1, 0); + textRenderer()->draw(width/2 - lastWidth, 0, _chatMessage.c_str() + lastIndex); } glEnable(GL_LIGHTING); diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp index aca13a79ac..2b6144e76d 100644 --- a/interface/src/ChatEntry.cpp +++ b/interface/src/ChatEntry.cpp @@ -14,7 +14,7 @@ using namespace std; const int MAX_CONTENT_LENGTH = 140; -void ChatEntry::clear () { +void ChatEntry::clear() { _contents.clear(); _cursorPos = 0; } @@ -67,7 +67,7 @@ void ChatEntry::render(int screenWidth, int screenHeight) { float width = 0; for (string::iterator it = _contents.begin(), end = it + _cursorPos; it != end; it++) { - width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.10; + width += widthChar(0.10, 0, *it); } glDisable(GL_LINE_SMOOTH); glBegin(GL_LINE_STRIP); diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h index db92822158..c2f1254c41 100644 --- a/interface/src/ChatEntry.h +++ b/interface/src/ChatEntry.h @@ -14,9 +14,9 @@ class ChatEntry { public: - const std::string& getContents () const { return _contents; } + const std::string& getContents() const { return _contents; } - void clear (); + void clear(); bool key(unsigned char k); void specialKey(unsigned char k); diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp index 454a64a0fb..be66bd3a76 100644 --- a/interface/src/Log.cpp +++ b/interface/src/Log.cpp @@ -14,6 +14,7 @@ #include #include "Util.h" +#include "ui/TextRenderer.h" namespace { // anonymous namespace - everything in here only exists within this very .cpp file @@ -194,6 +195,11 @@ void Log::setCharacterSize(unsigned width, unsigned height) { pthread_mutex_unlock(& _mtx); } +static TextRenderer* textRenderer() { + static TextRenderer* renderer = new TextRenderer("Helvetica"); + return renderer; +} + void Log::render(unsigned screenWidth, unsigned screenHeight) { // rendering might take some time, so create a local copy of the portion we need @@ -261,10 +267,8 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { } // get values for rendering - float scaleFactor = _valCharScale; - int yStart = int((screenHeight - _valCharYoffset) / _valCharAspect); - int yStep = int(_valCharHeight / _valCharAspect); - float yScale = _valCharAspect; + int yStep = textRenderer()->metrics().lineSpacing(); + int yStart = screenHeight - textRenderer()->metrics().descent(); // render text char** line = _ptrLinesEnd + showLines; @@ -273,11 +277,6 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { pthread_mutex_unlock(& _mtx); // ok, we got all we need - GLint matrixMode; - glGetIntegerv(GL_MATRIX_MODE, & matrixMode); - glPushMatrix(); - glScalef(1.0f, yScale, 1.0f); - for (int y = yStart; y > 0; y -= yStep) { // debug mode: check line pointer is valid @@ -299,14 +298,11 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { assert(! (chars < _ptrCharsEnd || chars >= _ptrCharsEnd + (_ptrCharsEnd - _arrChars))); // render the string - drawtext(x, y, scaleFactor, 0.0f, 1.0f, int(TEXT_MONOSPACED), - chars, TEXT_RED, TEXT_GREEN, TEXT_BLUE); + glColor3f(TEXT_RED, TEXT_GREEN, TEXT_BLUE); + textRenderer()->draw(x, y, chars); //fprintf(stderr, "Log::render, message = \"%s\"\n", chars); } - - glPopMatrix(); - glMatrixMode(matrixMode); } Log logger; diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index 94e8595c8b..2eea8e3235 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -16,6 +16,7 @@ #include "MenuColumn.h" #include "Menu.h" +#include "ui/TextRenderer.h" MenuColumn::MenuColumn() { } @@ -137,6 +138,11 @@ int MenuColumn::getMaxRowWidth() { return maxColumnWidth; } +static TextRenderer* textRenderer() { + static TextRenderer* renderer = new TextRenderer("Helvetica", 11); + return renderer; +} + void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { float scale = 0.09; int mono = 0; @@ -158,7 +164,8 @@ void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { char* rowName; for (unsigned int i = 0; i < rows.size(); ++i) { rowName = rows[i].getName(); - drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0); + glColor3f(0, 0, 0); + textRenderer()->draw(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, rowName); y += lineHeight; } renderMouseOver(yOffset); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 55b55b12eb..1dbe95d42d 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -15,6 +15,7 @@ #include #include "Log.h" +#include "ui/TextRenderer.h" #include "world.h" #include "Util.h" @@ -25,7 +26,6 @@ using namespace std; // see http://www.opengl.org/resources/libraries/glut/spec3/node78.html static float MONO_STROKE_WIDTH_GLUT = 104.76; - void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * right, glm::vec3 * up) { // // Converts from three euler angles to the associated orthonormal vectors @@ -152,19 +152,18 @@ double diffclock(timeval *clock1,timeval *clock2) return diffms; } +static TextRenderer* textRenderer(int mono) { + static TextRenderer* monoRenderer = new TextRenderer("Courier"); + static TextRenderer* proportionalRenderer = new TextRenderer("Helvetica"); + return mono ? monoRenderer : proportionalRenderer; +} + int widthText(float scale, int mono, char const* string) { - int width = 0; - if (!mono) { - width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string); - } else { -#ifndef WORKAROUND_BROKEN_GLUT_STROKES - width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string); -#else - // return value is unreliable, so just calculate it - width = scale * float(strlen(string)) * MONO_STROKE_WIDTH_GLUT; -#endif - } - return width; + return textRenderer(mono)->computeWidth(string) * (scale / 0.10); +} + +float widthChar(float scale, int mono, char ch) { + return textRenderer(mono)->computeWidth(ch) * (scale / 0.10); } void drawtext(int x, int y, float scale, float rotate, float thick, int mono, @@ -177,35 +176,12 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, glPushMatrix(); glTranslatef( static_cast(x), static_cast(y), 0.0f); glColor3f(r,g,b); - glRotated(180+rotate,0,0,1); - glRotated(180,0,1,0); - glLineWidth(thick); - glScalef(scale, scale, 1.0); - len = (int) strlen(string); - for (i = 0; i < len; i++) - { - if (!mono) { - glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i])); - } else { -#ifdef WORKAROUND_BROKEN_GLUT_STROKES - if (string[i] != 'm') { -#endif - glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i])); -#ifdef WORKAROUND_BROKEN_GLUT_STROKES - } else { - // some glut implementations have a broken 'm'... - unsigned char tmpStr[2]; - tmpStr[0] = string[i]; - tmpStr[1] = '\0'; - float scale = MONO_STROKE_WIDTH_GLUT / glutStrokeLength(GLUT_STROKE_ROMAN, tmpStr); - glScalef(scale, 1.0f, 1.0f); - glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i])); - // staying humble on the stack - might be in projection mode - glScalef(1.0f / scale, 1.0f, 1.0f); - } -#endif - } - } + glRotated(rotate,0,0,1); + // glLineWidth(thick); + glScalef(scale / 0.10, scale / 0.10, 1.0); + + textRenderer(mono)->draw(0, 0, string); + glPopMatrix(); } diff --git a/interface/src/Util.h b/interface/src/Util.h index b23885e6bc..70794898f6 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -28,6 +28,7 @@ float randFloat(); void render_world_box(); void render_vector(glm::vec3 * vec); int widthText(float scale, int mono, char const* string); +float widthChar(float scale, int mono, char ch); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char const* string, float r=1.0, float g=1.0, float b=1.0); void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 058d7ad2c9..ac186a2f07 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -39,6 +39,8 @@ #include #endif +#include + #include #include @@ -86,6 +88,8 @@ using namespace std; void reshape(int width, int height); // will be defined below void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below +QApplication* app; + bool enableNetworkThread = true; pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; @@ -1615,6 +1619,9 @@ int main(int argc, const char * argv[]) voxels_lib::printLog = & ::printLog; avatars_lib::printLog = & ::printLog; + // we need to create a QApplication instance in order to use Qt's font rendering + app = new QApplication(argc, const_cast(argv)); + // Quick test of the Orientation class on startup! if (cmdOptionExists(argc, argv, "--testOrientation")) { testOrientationClass(); From a24f215f09bc7f2f040abd49e3db985be8562f24 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Apr 2013 09:59:05 -0700 Subject: [PATCH 03/10] Moved menu, chat entry field to ui subdirectory. --- interface/src/main.cpp | 9 +++++---- interface/src/{ => ui}/ChatEntry.cpp | 0 interface/src/{ => ui}/ChatEntry.h | 0 interface/src/{ => ui}/Menu.cpp | 0 interface/src/{ => ui}/Menu.h | 0 interface/src/{ => ui}/MenuColumn.cpp | 0 interface/src/{ => ui}/MenuColumn.h | 0 interface/src/{ => ui}/MenuRow.cpp | 0 interface/src/{ => ui}/MenuRow.h | 0 9 files changed, 5 insertions(+), 4 deletions(-) rename interface/src/{ => ui}/ChatEntry.cpp (100%) rename interface/src/{ => ui}/ChatEntry.h (100%) rename interface/src/{ => ui}/Menu.cpp (100%) rename interface/src/{ => ui}/Menu.h (100%) rename interface/src/{ => ui}/MenuColumn.cpp (100%) rename interface/src/{ => ui}/MenuColumn.h (100%) rename interface/src/{ => ui}/MenuRow.cpp (100%) rename interface/src/{ => ui}/MenuRow.h (100%) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index ac186a2f07..1b52194d8d 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -61,11 +61,12 @@ #include "AngleUtil.h" #include "Stars.h" -#include "MenuRow.h" -#include "MenuColumn.h" -#include "Menu.h" +#include "ui/ChatEntry.h" +#include "ui/MenuRow.h" +#include "ui/MenuColumn.h" +#include "ui/Menu.h" + #include "Camera.h" -#include "ChatEntry.h" #include "Avatar.h" #include "Texture.h" #include diff --git a/interface/src/ChatEntry.cpp b/interface/src/ui/ChatEntry.cpp similarity index 100% rename from interface/src/ChatEntry.cpp rename to interface/src/ui/ChatEntry.cpp diff --git a/interface/src/ChatEntry.h b/interface/src/ui/ChatEntry.h similarity index 100% rename from interface/src/ChatEntry.h rename to interface/src/ui/ChatEntry.h diff --git a/interface/src/Menu.cpp b/interface/src/ui/Menu.cpp similarity index 100% rename from interface/src/Menu.cpp rename to interface/src/ui/Menu.cpp diff --git a/interface/src/Menu.h b/interface/src/ui/Menu.h similarity index 100% rename from interface/src/Menu.h rename to interface/src/ui/Menu.h diff --git a/interface/src/MenuColumn.cpp b/interface/src/ui/MenuColumn.cpp similarity index 100% rename from interface/src/MenuColumn.cpp rename to interface/src/ui/MenuColumn.cpp diff --git a/interface/src/MenuColumn.h b/interface/src/ui/MenuColumn.h similarity index 100% rename from interface/src/MenuColumn.h rename to interface/src/ui/MenuColumn.h diff --git a/interface/src/MenuRow.cpp b/interface/src/ui/MenuRow.cpp similarity index 100% rename from interface/src/MenuRow.cpp rename to interface/src/ui/MenuRow.cpp diff --git a/interface/src/MenuRow.h b/interface/src/ui/MenuRow.h similarity index 100% rename from interface/src/MenuRow.h rename to interface/src/ui/MenuRow.h From 34f2a281140ee526457f31db7e3af0b5b4379939 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Apr 2013 10:04:01 -0700 Subject: [PATCH 04/10] Delete our glyph textures on destruction. --- interface/src/ui/TextRenderer.cpp | 5 +++++ interface/src/ui/TextRenderer.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 8488a01ce7..33fc6f722c 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -24,6 +24,10 @@ TextRenderer::TextRenderer(const char* family, int pointSize, int weight, bool i _metrics(_font), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0) { } +TextRenderer::~TextRenderer() { + glDeleteTextures(_textureIDs.size(), _textureIDs.constData()); +} + void TextRenderer::draw(int x, int y, const char* str) { glEnable(GL_TEXTURE_2D); @@ -105,6 +109,7 @@ const Glyph& TextRenderer::getGlyph(char c) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + _textureIDs.append(_textureID); } else { glBindTexture(GL_TEXTURE_2D, _textureID); diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 840e686075..1ee7c913aa 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -13,6 +13,7 @@ #include #include #include +#include class Glyph; @@ -20,6 +21,7 @@ class TextRenderer { public: TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false); + ~TextRenderer(); const QFontMetrics& metrics() const { return _metrics; } @@ -49,6 +51,9 @@ private: // the height of the current row of characters int _rowHeight; + + // the list of all texture ids for which we're responsible + QVector _textureIDs; }; class Glyph { From 8b742e43e6eaadecd951be31ed9e51a9958b7485 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Apr 2013 10:15:48 -0700 Subject: [PATCH 05/10] =?UTF-8?q?GCC=20fails=20on=20these=20constants=20(I?= =?UTF-8?q?SO=20C++=20forbids=20initialization=20of=20member=20=E2=80=98CO?= =?UTF-8?q?LLISION=5FBALL=5FFORCE=E2=80=99),=20so=20I=20moved=20them=20int?= =?UTF-8?q?o=20the=20CPP=20(they=20don't=20seem=20to=20require=20external?= =?UTF-8?q?=20visibility=20anyway).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/src/Avatar.cpp | 21 +++++++++++++++++++++ interface/src/Avatar.h | 22 ---------------------- interface/src/AvatarTouch.cpp | 1 + interface/src/AvatarTouch.h | 2 -- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f6de7f6a77..889a158324 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -22,6 +22,27 @@ using namespace std; const bool BALLS_ON = false; +const bool AVATAR_GRAVITY = true; +const float DECAY = 0.1; +const float THRUST_MAG = 1200.0; +const float YAW_MAG = 500.0; //JJV - changed from 300.0; +const float TEST_YAW_DECAY = 5.0; +const float LIN_VEL_DECAY = 5.0; +const float MY_HAND_HOLDING_PULL = 0.2; +const float YOUR_HAND_HOLDING_PULL = 1.0; +const float BODY_SPRING_FORCE = 6.0f; +const float BODY_SPRING_DECAY = 16.0f; +//const float COLLISION_FRICTION = 0.5; +//const float COLLISION_RADIUS_SCALAR = 1.8; +//const float COLLISION_BALL_FORCE = 0.1; +//const float COLLISION_BODY_FORCE = 3.0; + +const float COLLISION_RADIUS_SCALAR = 1.8; +const float COLLISION_BALL_FORCE = 0.6; +const float COLLISION_BODY_FORCE = 6.0; +const float COLLISION_BALL_FRICTION = 200.0; +const float COLLISION_BODY_FRICTION = 0.5; + float skinColor[] = {1.0, 0.84, 0.66}; float lightBlue[] = { 0.7, 0.8, 1.0 }; float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 0f252af378..0d17b3b2a4 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -145,28 +145,6 @@ public: private: - const bool AVATAR_GRAVITY = true; - const float DECAY = 0.1; - const float THRUST_MAG = 1200.0; - const float YAW_MAG = 500.0; //JJV - changed from 300.0; - const float TEST_YAW_DECAY = 5.0; - const float LIN_VEL_DECAY = 5.0; - const float MY_HAND_HOLDING_PULL = 0.2; - const float YOUR_HAND_HOLDING_PULL = 1.0; - const float BODY_SPRING_FORCE = 6.0f; - const float BODY_SPRING_DECAY = 16.0f; - - //const float COLLISION_FRICTION = 0.5; - //const float COLLISION_RADIUS_SCALAR = 1.8; - //const float COLLISION_BALL_FORCE = 0.1; - //const float COLLISION_BODY_FORCE = 3.0; - - const float COLLISION_RADIUS_SCALAR = 1.8; - const float COLLISION_BALL_FORCE = 0.6; - const float COLLISION_BODY_FORCE = 6.0; - const float COLLISION_BALL_FRICTION = 200.0; - const float COLLISION_BODY_FRICTION = 0.5; - struct AvatarBone { AvatarBoneID parent; // which bone is this bone connected to? diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 41e040c382..b26b030b1d 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -11,6 +11,7 @@ #include "AvatarTouch.h" #include "InterfaceConfig.h" +const float THREAD_RADIUS = 0.007; AvatarTouch::AvatarTouch() { diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index 46afad6cf5..3c7a58a2b5 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -19,8 +19,6 @@ public: void setYourHandPosition( glm::vec3 position ); void simulate(float deltaTime); void render(); - - const float THREAD_RADIUS = 0.007; private: From ccdc1146a24a274cbf7892dd36adf6cf0b2a2f26 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Apr 2013 10:26:47 -0700 Subject: [PATCH 06/10] Removed cut and paste error from CMake file, made a couple variables in TextRenderer more descriptive. --- interface/CMakeLists.txt | 2 +- interface/src/ui/TextRenderer.cpp | 12 ++++++------ interface/src/ui/TextRenderer.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 360caea152..dbcb79edc7 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -84,7 +84,7 @@ target_link_libraries(${TARGET_NAME} ${QT_LIBRARIES}) if (NOT APPLE) find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) - include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${}) + include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) target_link_libraries(${TARGET_NAME} ${OPENGL_LIBRARY}) else (NOT APPLE) # link in required OS X frameworks and include the right GL headers diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 33fc6f722c..38f72aec0d 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -25,7 +25,7 @@ TextRenderer::TextRenderer(const char* family, int pointSize, int weight, bool i } TextRenderer::~TextRenderer() { - glDeleteTextures(_textureIDs.size(), _textureIDs.constData()); + glDeleteTextures(_allTextureIDs.size(), _allTextureIDs.constData()); } void TextRenderer::draw(int x, int y, const char* str) { @@ -102,17 +102,17 @@ const Glyph& TextRenderer::getGlyph(char c) { } if (_y + bounds.height() > IMAGE_SIZE) { // can't fit it on current texture; make a new one - glGenTextures(1, &_textureID); + glGenTextures(1, &_currentTextureID); _x = _y = _rowHeight = 0; - glBindTexture(GL_TEXTURE_2D, _textureID); + glBindTexture(GL_TEXTURE_2D, _currentTextureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - _textureIDs.append(_textureID); + _allTextureIDs.append(_currentTextureID); } else { - glBindTexture(GL_TEXTURE_2D, _textureID); + glBindTexture(GL_TEXTURE_2D, _currentTextureID); } // render the glyph into an image and copy it into the texture QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32); @@ -125,7 +125,7 @@ const Glyph& TextRenderer::getGlyph(char c) { } glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); - glyph = Glyph(_textureID, QPoint(_x, _y), bounds, _metrics.width(c)); + glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(c)); _x += bounds.width(); _rowHeight = qMax(_rowHeight, bounds.height()); diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 1ee7c913aa..636bcd8e73 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -44,7 +44,7 @@ private: QHash _glyphs; // the id of the glyph texture to which we're currently writing - GLuint _textureID; + GLuint _currentTextureID; // the position within the current glyph texture int _x, _y; @@ -53,7 +53,7 @@ private: int _rowHeight; // the list of all texture ids for which we're responsible - QVector _textureIDs; + QVector _allTextureIDs; }; class Glyph { From 39a70ce9e7444d842a827b11cfbe8d2fb32629ca Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Apr 2013 11:06:23 -0700 Subject: [PATCH 07/10] Rather than Xs, use a "solid block" pseudo-character to draw a bar. Tweaked the colors to indicate the pressed key again. --- interface/src/Avatar.cpp | 3 ++- interface/src/main.cpp | 3 ++- interface/src/ui/TextRenderer.cpp | 17 +++++++++++------ interface/src/ui/TextRenderer.h | 3 +++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 889a158324..6ce3276553 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -736,7 +736,7 @@ void Avatar::render(bool lookingInMirror) { glTranslatef(_position.x, _position.y + chatMessageHeight, _position.z); glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); - glColor3f(0, 1, 0); + glColor3f(0, 0.8, 0); glRotatef(180, 0, 0, 1); glScalef(chatMessageScale, chatMessageScale, 1.0f); @@ -752,6 +752,7 @@ void Avatar::render(bool lookingInMirror) { _chatMessage[lastIndex] = '\0'; textRenderer()->draw(-width/2, 0, _chatMessage.c_str()); _chatMessage[lastIndex] = lastChar; + glColor3f(0, 1, 0); textRenderer()->draw(width/2 - lastWidth, 0, _chatMessage.c_str() + lastIndex); } glEnable(GL_LIGHTING); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 1b52194d8d..634b883e08 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -65,6 +65,7 @@ #include "ui/MenuRow.h" #include "ui/MenuColumn.h" #include "ui/Menu.h" +#include "ui/TextRenderer.h" #include "Camera.h" #include "Avatar.h" @@ -1333,7 +1334,7 @@ void key(unsigned char k, int x, int y) if (chatEntry.key(k)) { myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete DELETE_KEY_DOWN : INSERT_KEY_DOWN); - myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X')); + myAvatar.setChatMessage(string(chatEntry.getContents().size(), SOLID_BLOCK_CHAR)); } else { myAvatar.setChatMessage(chatEntry.getContents()); diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 38f72aec0d..5780c59ec1 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -89,9 +89,11 @@ const Glyph& TextRenderer::getGlyph(char c) { if (glyph.isValid()) { return glyph; } - QRect bounds = _metrics.boundingRect(c); + // we use 'J' as a representative size for the solid block character + QChar ch = (c == SOLID_BLOCK_CHAR) ? QChar('J') : QChar(c); + QRect bounds = _metrics.boundingRect(ch); if (bounds.isEmpty()) { - glyph = Glyph(0, QPoint(), QRect(), _metrics.width(c)); + glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch)); return glyph; } @@ -116,16 +118,19 @@ const Glyph& TextRenderer::getGlyph(char c) { } // render the glyph into an image and copy it into the texture QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32); - image.fill(0); - { + if (c == SOLID_BLOCK_CHAR) { + image.fill(QColor(255, 255, 255)); + + } else { + image.fill(0); QPainter painter(&image); painter.setFont(_font); painter.setPen(QColor(255, 255, 255)); - painter.drawText(-bounds.x(), -bounds.y(), QChar(c)); + painter.drawText(-bounds.x(), -bounds.y(), ch); } glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); - glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(c)); + glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(ch)); _x += bounds.width(); _rowHeight = qMax(_rowHeight, bounds.height()); diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 636bcd8e73..6de0c77bad 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -15,6 +15,9 @@ #include #include +// a special "character" that renders as a solid block +const char SOLID_BLOCK_CHAR = 127; + class Glyph; class TextRenderer { From 668e25f9cd5cf9c1352764240389ae392f62fd9d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 1 May 2013 11:51:19 -0700 Subject: [PATCH 08/10] Fixed merge issue. --- interface/src/Avatar.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 74b605a137..36e9843672 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -20,28 +20,6 @@ using namespace std; -const bool AVATAR_GRAVITY = true; -const float DECAY = 0.1; -const float THRUST_MAG = 1200.0; -const float YAW_MAG = 500.0; //JJV - changed from 300.0; -const float TEST_YAW_DECAY = 5.0; -const float LIN_VEL_DECAY = 5.0; -const float MY_HAND_HOLDING_PULL = 0.2; -const float YOUR_HAND_HOLDING_PULL = 1.0; -const float BODY_SPRING_FORCE = 6.0f; -const float BODY_SPRING_DECAY = 16.0f; - -//const float COLLISION_FRICTION = 0.5; -//const float COLLISION_RADIUS_SCALAR = 1.8; -//const float COLLISION_BALL_FORCE = 0.1; -//const float COLLISION_BODY_FORCE = 3.0; - -const float COLLISION_RADIUS_SCALAR = 1.8; -const float COLLISION_BALL_FORCE = 0.6; -const float COLLISION_BODY_FORCE = 6.0; -const float COLLISION_BALL_FRICTION = 200.0; -const float COLLISION_BODY_FRICTION = 0.5; - const bool BALLS_ON = false; const bool AVATAR_GRAVITY = true; From 15e46bac82629ca03d7d856f1725fe510f225359 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 1 May 2013 11:59:21 -0700 Subject: [PATCH 09/10] Disable kerning, expand bounds to account for antialiasing. --- interface/src/ui/TextRenderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 5780c59ec1..3130463398 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -22,6 +22,7 @@ Glyph::Glyph(int textureID, const QPoint& location, const QRect& bounds, int wid TextRenderer::TextRenderer(const char* family, int pointSize, int weight, bool italic) : _font(family, pointSize, weight, italic), _metrics(_font), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0) { + _font.setKerning(false); } TextRenderer::~TextRenderer() { @@ -96,6 +97,8 @@ const Glyph& TextRenderer::getGlyph(char c) { glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch)); return glyph; } + // grow the bounds to account for antialiasing + bounds.adjust(-1, -1, 1, 1); if (_x + bounds.width() > IMAGE_SIZE) { // we can't fit it on the current row; move to next From 11a750f6a0642622fc1c3759e7d97048ef4d97cd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 1 May 2013 12:17:57 -0700 Subject: [PATCH 10/10] Changes according to Philip's feedback: spacing around operators, removed unused variables, moved font family names to #defines. --- interface/src/Avatar.cpp | 2 +- interface/src/Log.cpp | 4 +++- interface/src/Util.cpp | 4 ++-- interface/src/Util.h | 7 +++++++ interface/src/ui/MenuColumn.cpp | 6 ++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 36e9843672..b52e7484e1 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -677,7 +677,7 @@ void Avatar::setDisplayingHead( bool displayingHead ) { static TextRenderer* textRenderer() { - static TextRenderer* renderer = new TextRenderer("Helvetica", 24); + static TextRenderer* renderer = new TextRenderer(SANS_FONT_FAMILY, 24); return renderer; } diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp index be66bd3a76..5fcfb51e25 100644 --- a/interface/src/Log.cpp +++ b/interface/src/Log.cpp @@ -24,6 +24,8 @@ namespace { unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message + const char* FONT_FAMILY = SANS_FONT_FAMILY; + bool const TEXT_MONOSPACED = true; float const TEXT_RED = 0.7f; @@ -196,7 +198,7 @@ void Log::setCharacterSize(unsigned width, unsigned height) { } static TextRenderer* textRenderer() { - static TextRenderer* renderer = new TextRenderer("Helvetica"); + static TextRenderer* renderer = new TextRenderer(FONT_FAMILY); return renderer; } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 1dbe95d42d..ef51f9b72a 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -153,8 +153,8 @@ double diffclock(timeval *clock1,timeval *clock2) } static TextRenderer* textRenderer(int mono) { - static TextRenderer* monoRenderer = new TextRenderer("Courier"); - static TextRenderer* proportionalRenderer = new TextRenderer("Helvetica"); + static TextRenderer* monoRenderer = new TextRenderer(MONO_FONT_FAMILY); + static TextRenderer* proportionalRenderer = new TextRenderer(SANS_FONT_FAMILY); return mono ? monoRenderer : proportionalRenderer; } diff --git a/interface/src/Util.h b/interface/src/Util.h index 70794898f6..02b3ae8152 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -19,6 +19,13 @@ #include +// the standard sans serif font family +#define SANS_FONT_FAMILY "Helvetica" + +// the standard mono font family +#define MONO_FONT_FAMILY "Courier" + + void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * fwd, glm::vec3 * left, glm::vec3 * up); float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos); diff --git a/interface/src/ui/MenuColumn.cpp b/interface/src/ui/MenuColumn.cpp index 2eea8e3235..a70e261c52 100644 --- a/interface/src/ui/MenuColumn.cpp +++ b/interface/src/ui/MenuColumn.cpp @@ -139,13 +139,11 @@ int MenuColumn::getMaxRowWidth() { } static TextRenderer* textRenderer() { - static TextRenderer* renderer = new TextRenderer("Helvetica", 11); + static TextRenderer* renderer = new TextRenderer(SANS_FONT_FAMILY, 11); return renderer; } void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { - float scale = 0.09; - int mono = 0; int numberOfRows = rows.size(); if (numberOfRows > 0) { @@ -165,7 +163,7 @@ void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { for (unsigned int i = 0; i < rows.size(); ++i) { rowName = rows[i].getName(); glColor3f(0, 0, 0); - textRenderer()->draw(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, rowName); + textRenderer()->draw(leftPosition + SPACE_BEFORE_ROW_NAME, y + 5 + yOffset, rowName); y += lineHeight; } renderMouseOver(yOffset);