From d585f8c7073a55915c3de4a76e89c769b18f42d7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 12:10:40 -0800 Subject: [PATCH 1/8] replace gluOrtho2D() with glOrtho() --- interface/src/devices/OculusManager.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 ++-- interface/src/ui/RearMirrorTools.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 1854c9539d..76a54eb9d8 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -582,7 +582,7 @@ void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - gluOrtho2D(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight()); + glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index ab85da125c..0350726d9c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -180,7 +180,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glCanvas->width(), glCanvas->height(), 0); + glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0f, 1.0f); renderAudioMeter(); @@ -224,7 +224,7 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0); + glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index fd3fc34adb..2287324656 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -128,7 +128,7 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glPushMatrix(); glLoadIdentity(); - gluOrtho2D(bounds.left(), bounds.right(), bounds.bottom(), bounds.top()); + glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0f, 1.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); From 046564ec470dc7587ecd680e904eaf9fc40cca0b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 12:35:47 -0800 Subject: [PATCH 2/8] oops double --- interface/src/devices/OculusManager.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 ++-- interface/src/ui/RearMirrorTools.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 76a54eb9d8..f59ce639a0 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -582,7 +582,7 @@ void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0f, 1.0f); + glOrtho(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight(), -1.0, 1.0); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 0350726d9c..b2ed9fc77d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -180,7 +180,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0f, 1.0f); + glOrtho(0, glCanvas->width(), glCanvas->height(), 0, -1.0, 1.0); renderAudioMeter(); @@ -224,7 +224,7 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0f, 1.0f); + glOrtho(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0, -1.0, 1.0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index 2287324656..37f7c6ae23 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -128,7 +128,7 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glPushMatrix(); glLoadIdentity(); - glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0f, 1.0f); + glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0, 1.0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); From 1db1914a2efb409d5c1027343e1da4d40ab5b380 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:46:33 -0800 Subject: [PATCH 3/8] replace gluProject() with just the math --- interface/src/avatar/Avatar.cpp | 138 ++++++++++++++++---------------- interface/src/avatar/Avatar.h | 1 + 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 39c528d080..4c309b2c8c 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -669,6 +669,49 @@ glm::vec3 Avatar::getDisplayNamePosition() { return namePosition; } +float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) { + + // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates + // We project a unit vector and check the difference in screen coordinates, to check which is the + // correction scale needed + // save the matrices for later scale correction factor + // The up vector must be relative to the rotation current rotation matrix: + // we set the identity + glm::vec3 testPoint0 = textPosition; + glm::vec3 testPoint1 = textPosition + (Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); + + double textWindowHeight; + + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + float windowSizeX = glCanvas->getDeviceWidth(); + float windowSizeY = glCanvas->getDeviceHeight(); + + glm::dmat4 modelViewMatrix; + glm::dmat4 projectionMatrix; + Application::getInstance()->getModelViewMatrix(&modelViewMatrix); + Application::getInstance()->getProjectionMatrix(&projectionMatrix); + + glm::dvec4 p0 = modelViewMatrix * glm::dvec4(testPoint0, 1.0); + p0 = projectionMatrix * p0; + glm::dvec2 result0 = glm::vec2(windowSizeX * (p0.x / p0.w + 1.0f) * 0.5f, windowSizeY * (p0.y / p0.w + 1.0f) * 0.5f); + + glm::dvec4 p1 = modelViewMatrix * glm::dvec4(testPoint1, 1.0); + p1 = projectionMatrix * p1; + glm::vec2 result1 = glm::vec2(windowSizeX * (p1.x / p1.w + 1.0f) * 0.5f, windowSizeY * (p1.y / p1.w + 1.0f) * 0.5f); + textWindowHeight = abs(result1.y - result0.y); + + // need to scale to compensate for the font resolution due to the device + float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * + ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); + if (inHMD) { + const float HMDMODE_NAME_SCALE = 0.65f; + scaleFactor *= HMDMODE_NAME_SCALE; + } else { + scaleFactor *= Application::getInstance()->getRenderResolutionScale(); + } + return scaleFactor; +} + void Avatar::renderDisplayName() { if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) { @@ -700,78 +743,39 @@ void Avatar::renderDisplayName() { frontAxis = glm::normalize(glm::vec3(frontAxis.z, 0.0f, -frontAxis.x)); float angle = acos(frontAxis.x) * ((frontAxis.z < 0) ? 1.0f : -1.0f); glRotatef(glm::degrees(angle), 0.0f, 1.0f, 0.0f); - - // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates - // We project a unit vector and check the difference in screen coordinates, to check which is the - // correction scale needed - // save the matrices for later scale correction factor - glm::dmat4 modelViewMatrix; - glm::dmat4 projectionMatrix; - GLint viewportMatrix[4]; - Application::getInstance()->getModelViewMatrix(&modelViewMatrix); - Application::getInstance()->getProjectionMatrix(&projectionMatrix); - glGetIntegerv(GL_VIEWPORT, viewportMatrix); - GLdouble result0[3], result1[3]; - - // The up vector must be relative to the rotation current rotation matrix: - // we set the identity - glm::dvec3 testPoint0 = glm::dvec3(textPosition); - glm::dvec3 testPoint1 = glm::dvec3(textPosition) + glm::dvec3(Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); - bool success; - success = gluProject(testPoint0.x, testPoint0.y, testPoint0.z, - (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, - &result0[0], &result0[1], &result0[2]); - success = success && - gluProject(testPoint1.x, testPoint1.y, testPoint1.z, - (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, - &result1[0], &result1[1], &result1[2]); + float scaleFactor = calculateDisplayNameScaleFactor(textPosition, inHMD); + glScalef(scaleFactor, scaleFactor, 1.0); + + glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis - if (success) { - double textWindowHeight = abs(result1[1] - result0[1]); - // need to scale to compensate for the font resolution due to the device - float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * - ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); - if (inHMD) { - const float HMDMODE_NAME_SCALE = 0.65f; - scaleFactor *= HMDMODE_NAME_SCALE; - } else { - scaleFactor *= Application::getInstance()->getRenderResolutionScale(); - } - glScalef(scaleFactor, scaleFactor, 1.0); - - glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis + int text_x = -_displayNameBoundingRect.width() / 2; + int text_y = -_displayNameBoundingRect.height() / 2; - int text_x = -_displayNameBoundingRect.width() / 2; - int text_y = -_displayNameBoundingRect.height() / 2; + // draw a gray background + int left = text_x + _displayNameBoundingRect.x(); + int right = left + _displayNameBoundingRect.width(); + int bottom = text_y + _displayNameBoundingRect.y(); + int top = bottom + _displayNameBoundingRect.height(); + const int border = 8; + bottom -= border; + left -= border; + top += border; + right += border; - // draw a gray background - int left = text_x + _displayNameBoundingRect.x(); - int right = left + _displayNameBoundingRect.width(); - int bottom = text_y + _displayNameBoundingRect.y(); - int top = bottom + _displayNameBoundingRect.height(); - const int border = 8; - bottom -= border; - left -= border; - top += border; - right += border; + // We are drawing coplanar textures with depth: need the polygon offset + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); - // We are drawing coplanar textures with depth: need the polygon offset - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 1.0f); - - glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); - renderBevelCornersRect(left, bottom, right - left, top - bottom, 3); - - glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); - QByteArray ba = _displayName.toLocal8Bit(); - const char* text = ba.data(); - - glDisable(GL_POLYGON_OFFSET_FILL); - textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); - - - } + glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); + renderBevelCornersRect(left, bottom, right - left, top - bottom, 3); + + glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); + QByteArray ba = _displayName.toLocal8Bit(); + const char* text = ba.data(); + + glDisable(GL_POLYGON_OFFSET_FILL); + textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); glPopMatrix(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 88ab3b12ca..d862e042c2 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -230,6 +230,7 @@ protected: float getPelvisFloatingHeight() const; glm::vec3 getDisplayNamePosition(); + float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD); void renderDisplayName(); virtual void renderBody(RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; From 22e2fcf746af7df99a71b2f5caea198d1d63ef1e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:46:42 -0800 Subject: [PATCH 4/8] add some vec2 debugging --- libraries/shared/src/StreamUtils.cpp | 8 ++++++++ libraries/shared/src/StreamUtils.h | 1 + 2 files changed, 9 insertions(+) diff --git a/libraries/shared/src/StreamUtils.cpp b/libraries/shared/src/StreamUtils.cpp index 85b800efbe..47bb8dd4e4 100644 --- a/libraries/shared/src/StreamUtils.cpp +++ b/libraries/shared/src/StreamUtils.cpp @@ -98,6 +98,14 @@ std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule) { #ifndef QT_NO_DEBUG_STREAM #include +QDebug& operator<<(QDebug& dbg, const glm::vec2& v) { + dbg.nospace() << "{type='glm::vec2'" + ", x=" << v.x << + ", y=" << v.y << + "}"; + return dbg; +} + QDebug& operator<<(QDebug& dbg, const glm::vec3& v) { dbg.nospace() << "{type='glm::vec3'" ", x=" << v.x << diff --git a/libraries/shared/src/StreamUtils.h b/libraries/shared/src/StreamUtils.h index 6d00c0e354..d176d68e45 100644 --- a/libraries/shared/src/StreamUtils.h +++ b/libraries/shared/src/StreamUtils.h @@ -49,6 +49,7 @@ std::ostream& operator<<(std::ostream& s, const CapsuleShape& capsule); #ifndef QT_NO_DEBUG_STREAM class QDebug; // Add support for writing these to qDebug(). +QDebug& operator<<(QDebug& s, const glm::vec2& v); QDebug& operator<<(QDebug& s, const glm::vec3& v); QDebug& operator<<(QDebug& s, const glm::quat& q); QDebug& operator<<(QDebug& s, const glm::mat4& m); From 2e3a522e73d045d5efa071e8a6ca4417db52dae6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 13:53:44 -0800 Subject: [PATCH 5/8] remove glut.h from CmakeLists.txt and fix a compiler issue with Hair.cpp --- interface/CMakeLists.txt | 6 +++--- interface/src/Hair.cpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a9688a5919..6d0b6a2f07 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -25,15 +25,15 @@ else () endif () if (APPLE) - set(GL_HEADERS "#include \n#include ") + set(GL_HEADERS "#include ") elseif (UNIX) # include the right GL headers for UNIX - set(GL_HEADERS "#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include ") elseif (WIN32) add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines - set(GL_HEADERS "#include \n#include \n#include \n#include ") + set(GL_HEADERS "#include \n#include \n#include ") endif () # set up the external glm library diff --git a/interface/src/Hair.cpp b/interface/src/Hair.cpp index cb664f39ed..6fd326a9b5 100644 --- a/interface/src/Hair.cpp +++ b/interface/src/Hair.cpp @@ -10,6 +10,8 @@ // // Creates single flexible verlet-integrated strands that can be used for hair/fur/grass +#include + #include "Hair.h" #include "Util.h" From 30e2a9c13f13c0e6cd3b13db85f4307b7b3783f4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Dec 2014 14:18:44 -0800 Subject: [PATCH 6/8] Add notifications.js to defaultScripts --- examples/defaultScripts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index d39fce0186..cdb8e76c65 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -15,3 +15,4 @@ Script.load("hydraMove.js"); Script.load("headMove.js"); Script.load("inspect.js"); Script.load("lobby.js"); +Script.load("notifications.js"); From 7e37aaabde2f7597fdff8ef28b0c66ffd931d1dd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 14:24:04 -0800 Subject: [PATCH 7/8] windows build hack --- interface/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 6d0b6a2f07..ff813343ab 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -232,7 +232,7 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib Winmm.lib) # try to find the Nsight package and add it to the build if we find it find_package(NSIGHT) From b7165abd5beaa5498024ed098bcbadcec83a12d5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 19 Dec 2014 14:33:45 -0800 Subject: [PATCH 8/8] possible glew warning fix for windows --- libraries/gpu/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 340adcc9e6..e63495867e 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -19,7 +19,7 @@ elseif (WIN32) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" opengl32.lib) + target_link_libraries(${TARGET_NAME} opengl32.lib) # need to bubble up the GLEW_INCLUDE_DIRS list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${GLEW_INCLUDE_DIRS}")