changeset 892:50cd372e2460

fix OpenGL context for fonts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jul 2019 09:18:55 +0200
parents 0aff28f15ea2
children 0c5201499af8 9c2f6d6b9f4a a7042ad79f08
files Framework/Scene2D/OpenGLCompositor.cpp Samples/WebAssembly/BasicScene.cpp Samples/WebAssembly/CMakeLists.txt
diffstat 3 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Scene2D/OpenGLCompositor.cpp	Wed Jul 10 18:18:42 2019 +0200
+++ b/Framework/Scene2D/OpenGLCompositor.cpp	Thu Jul 11 09:18:55 2019 +0200
@@ -149,11 +149,11 @@
   
   void OpenGLCompositor::Refresh()
   {
+    context_.MakeCurrent();
+
     canvasWidth_ = context_.GetCanvasWidth();
     canvasHeight_ = context_.GetCanvasHeight();
 
-    context_.MakeCurrent();
-
     glViewport(0, 0, canvasWidth_, canvasHeight_);
     glClearColor(0, 0, 0, 1);
     glClear(GL_COLOR_BUFFER_BIT);
@@ -167,6 +167,8 @@
   void OpenGLCompositor::SetFont(size_t index,
                                  const GlyphBitmapAlphabet& dict)
   {
+    context_.MakeCurrent();
+      
     std::auto_ptr<Font> font(new Font(dict));
       
     Fonts::iterator found = fonts_.find(index);
--- a/Samples/WebAssembly/BasicScene.cpp	Wed Jul 10 18:18:42 2019 +0200
+++ b/Samples/WebAssembly/BasicScene.cpp	Thu Jul 11 09:18:55 2019 +0200
@@ -86,6 +86,7 @@
   }
 
   // Some lines
+  if (1)
   {
     std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
 
@@ -187,11 +188,19 @@
                                         FONT_SIZE, Orthanc::Encoding_Latin1);
     viewport3_->GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, 
                                         FONT_SIZE, Orthanc::Encoding_Latin1);
-    
+
     controller1_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport1_));
     controller2_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport2_));
     controller3_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport3_));
 
+    controller1_->FitContent(viewport1_->GetCanvasWidth(), viewport1_->GetCanvasHeight());
+    controller2_->FitContent(viewport2_->GetCanvasWidth(), viewport2_->GetCanvasHeight());
+    controller3_->FitContent(viewport3_->GetCanvasWidth(), viewport3_->GetCanvasHeight());
+
+    viewport1_->Refresh();
+    viewport2_->Refresh();
+    viewport3_->Refresh();
+
     SetupEvents("mycanvas1", controller1_);
     SetupEvents("mycanvas2", controller2_);
     SetupEvents("mycanvas3", controller3_);
--- a/Samples/WebAssembly/CMakeLists.txt	Wed Jul 10 18:18:42 2019 +0200
+++ b/Samples/WebAssembly/CMakeLists.txt	Thu Jul 11 09:18:55 2019 +0200
@@ -15,6 +15,8 @@
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXIT_RUNTIME=1")
 
+#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1")
+
 
 #####################################################################
 ## Configuration of the Orthanc framework