Quellcode durchsuchen

fixed font rendering problem

Former-commit-id: b18327c7d08457c76b9ea3e528e8a3bb3a99153e
Daniele Panozzo vor 10 Jahren
Ursprung
Commit
e8e53a38b1

+ 1 - 0
include/igl/n_polyvector.cpp

@@ -6,6 +6,7 @@
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 
+#include <complex>
 #include <igl/n_polyvector.h>
 #include <igl/n_polyvector.h>
 #include <igl/edge_topology.h>
 #include <igl/edge_topology.h>
 #include <igl/local_basis.h>
 #include <igl/local_basis.h>

+ 1 - 1
include/igl/slice.cpp

@@ -79,7 +79,7 @@ IGL_INLINE void igl::slice(
   // handled here (although it's not clear if there is a performance gain when
   // handled here (although it's not clear if there is a performance gain when
   // the #removals >> #remains). If this is sufficiently faster than the
   // the #removals >> #remains). If this is sufficiently faster than the
   // correct code above, one could test whether all entries in R and C are
   // correct code above, one could test whether all entries in R and C are
-  // unique and apply the permutation version if appropriate. 
+  // unique and apply the permutation version if appropriate.
   //
   //
 
 
   int xm = X.rows();
   int xm = X.rows();

+ 14 - 56
include/igl/viewer/TextRenderer.cpp

@@ -6,60 +6,45 @@
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "TextRenderer.h"
 #include "TextRenderer.h"
+#include "TextRenderer_fonts.h"
 #include <igl/project.h>
 #include <igl/project.h>
 #include <nanovg.h>
 #include <nanovg.h>
 #define NANOVG_GL3
 #define NANOVG_GL3
 #include <nanovg_gl.h>
 #include <nanovg_gl.h>
 
 
+
 using namespace std;
 using namespace std;
 
 
   IGL_INLINE igl::TextRenderer::TextRenderer() { }
   IGL_INLINE igl::TextRenderer::TextRenderer() { }
 
 
   IGL_INLINE int igl::TextRenderer::Init()
   IGL_INLINE int igl::TextRenderer::Init()
   {
   {
-    cerr << "Init TextRenderer" << endl;
     #ifdef NDEBUG
     #ifdef NDEBUG
       ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS);
       ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS);
     #else
     #else
       ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
       ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
     #endif
     #endif
 
 
-    nvgFontSize(ctx, 16);
-    nvgFontFace(ctx, "sans");
-    nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
-    NVGcolor c;
-    c.r = 0.2;
-    c.g = 0.2;
-    c.b = 255;
-    c.a = 255;
-
-    nvgFillColor(ctx, c);
-    nvgStrokeColor(ctx, c);
+    nvgCreateFontMem(ctx, "sans", igl_roboto_regular_ttf,
+                               igl_roboto_regular_ttf_size, 0);
 
 
+    return 0;
   }
   }
 
 
   IGL_INLINE int igl::TextRenderer::Shut()
   IGL_INLINE int igl::TextRenderer::Shut()
   {
   {
-    cerr << "Shut TextRenderer" << endl;
-
     nvgDeleteGL3(ctx);
     nvgDeleteGL3(ctx);
+    return 0;
   }
   }
 
 
   IGL_INLINE void igl::TextRenderer::BeginDraw(const Eigen::Matrix4f &view, const Eigen::Matrix4f &proj,
   IGL_INLINE void igl::TextRenderer::BeginDraw(const Eigen::Matrix4f &view, const Eigen::Matrix4f &proj,
     const Eigen::Vector4f &_viewport, float _object_scale)
     const Eigen::Vector4f &_viewport, float _object_scale)
   {
   {
-    cerr << "BeginDraw TextRenderer" << endl;
-
-
     viewport = _viewport;
     viewport = _viewport;
     proj_matrix = proj;
     proj_matrix = proj;
     view_matrix = view;
     view_matrix = view;
-    // CTwGraphOpenGLCore::BeginDraw(viewport[2], viewport[3]);
-    // glEnable(GL_DEPTH_TEST);
-    // glDepthMask(GL_FALSE);
     object_scale = _object_scale;
     object_scale = _object_scale;
 
 
-
     Eigen::Vector2i mFBSize;
     Eigen::Vector2i mFBSize;
     Eigen::Vector2i mSize;
     Eigen::Vector2i mSize;
 
 
@@ -68,25 +53,15 @@ using namespace std;
     glfwGetWindowSize(mGLFWWindow,&mSize[0],&mSize[1]);
     glfwGetWindowSize(mGLFWWindow,&mSize[0],&mSize[1]);
     glViewport(0,0,mFBSize[0],mFBSize[1]);
     glViewport(0,0,mFBSize[0],mFBSize[1]);
 
 
+    glClear(GL_STENCIL_BUFFER_BIT);
+
     /* Calculate pixel ratio for hi-dpi devices. */
     /* Calculate pixel ratio for hi-dpi devices. */
-    float mPixelRatio = (float)mFBSize[0] / (float)mSize[0];
+    mPixelRatio = (float)mFBSize[0] / (float)mSize[0];
     nvgBeginFrame(ctx,mSize[0],mSize[1],mPixelRatio);
     nvgBeginFrame(ctx,mSize[0],mSize[1],mPixelRatio);
-
   }
   }
 
 
   IGL_INLINE void igl::TextRenderer::EndDraw()
   IGL_INLINE void igl::TextRenderer::EndDraw()
   {
   {
-    // /* Limit the number of cached text objects */
-    // for (auto it = m_textObjects.cbegin(); it != m_textObjects.cend(); )
-    // {
-    //   if (m_textObjects.size() < 1000000)
-    //     break;
-    //   DeleteTextObj(it->second);
-    //   m_textObjects.erase(it++);
-    // }
-
-    // glDepthMask(GL_TRUE);
-    // CTwGraphOpenGLCore::EndDraw();
     nvgEndFrame(ctx);
     nvgEndFrame(ctx);
   }
   }
 
 
@@ -96,26 +71,9 @@ using namespace std;
     Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
     Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
         view_matrix, proj_matrix, viewport);
         view_matrix, proj_matrix, viewport);
 
 
-    // auto it = m_textObjects.find(text);
-    // void *text_obj = nullptr;
-    // if (it == m_textObjects.end())
-    // {
-    //   text_obj = NewTextObj();
-    //   BuildText(text_obj, &text, NULL, NULL, 1, g_DefaultNormalFont, 0, 0);
-    //   m_textObjects[text] = text_obj;
-    // } else {
-    //   text_obj = it->second;
-    // }
-    // m_shader.bind();
-    // glUniform1f(m_TriTexUniLocationDepth, 2*(coord(2)-0.5f));
-    //CTwGraphOpenGLCore::DrawText(text_obj, coord[0], viewport[3] - coord[1], COLOR32_BLUE, 0);
-
-    nvgText(ctx, coord[0], viewport[3] - coord[1], text.c_str(), nullptr);
-
-
-    nvgText(ctx, 10, 10, "Ciao", nullptr);
-
-    cerr << "Draw TextRenderer " << coord[0] << " " << viewport[3] - coord[1] << " " << text << endl;
-
-
+    nvgFontSize(ctx, 8);
+    nvgFontFace(ctx, "sans");
+    nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+    nvgFillColor(ctx, nvgRGBA(10,10,250,255));
+    nvgText(ctx, coord[0]/mPixelRatio, (viewport[3] - coord[1])/mPixelRatio, text.c_str(), NULL);
   }
   }

+ 1 - 5
include/igl/viewer/TextRenderer.h

@@ -13,8 +13,6 @@
 #define IGL_TEXT_RENDERER_H
 #define IGL_TEXT_RENDERER_H
 
 
 #include <igl/igl_inline.h>
 #include <igl/igl_inline.h>
-//#include <igl/viewer/OpenGL_shader.h>
-//#include <TwOpenGLCore.h>
 #include <map>
 #include <map>
 #include <nanogui/opengl.h>
 #include <nanogui/opengl.h>
 
 
@@ -37,13 +35,11 @@ public:
   IGL_INLINE void DrawText(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text);
   IGL_INLINE void DrawText(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text);
 
 
 protected:
 protected:
-//  igl::OpenGL_shader m_shader;
   std::map<std::string, void *> m_textObjects;
   std::map<std::string, void *> m_textObjects;
-  // GLuint m_shaderHandleBackup;
-  // GLuint m_TriTexUniLocationDepth;
   Eigen::Matrix4f view_matrix, proj_matrix;
   Eigen::Matrix4f view_matrix, proj_matrix;
   Eigen::Vector4f viewport;
   Eigen::Vector4f viewport;
   float object_scale;
   float object_scale;
+  float mPixelRatio;
   NVGcontext *ctx;
   NVGcontext *ctx;
 };
 };
 
 

+ 1 - 0
include/igl/viewer/TextRenderer_fonts.cpp.REMOVED.git-id

@@ -0,0 +1 @@
+36fdb5c0c44d1eebf7c30d970cf9577c01dfc509

+ 27 - 0
include/igl/viewer/TextRenderer_fonts.h

@@ -0,0 +1,27 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef IGL_TEXT_RENDERER_FONTS_H
+#define IGL_TEXT_RENDERER_FONTS_H
+
+#include <stdint.h>
+
+extern uint8_t igl_entypo_ttf[];
+extern uint32_t igl_entypo_ttf_size;
+
+extern uint8_t igl_roboto_bold_ttf[];
+extern uint32_t igl_roboto_bold_ttf_size;
+
+extern uint8_t igl_roboto_regular_ttf[];
+extern uint32_t igl_roboto_regular_ttf_size;
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "TextRenderer_fonts.cpp"
+#endif
+
+#endif