diff --git a/modules/v4d/src/detail/framebuffercontext.cpp b/modules/v4d/src/detail/framebuffercontext.cpp index 13256dfe7..e7499d698 100644 --- a/modules/v4d/src/detail/framebuffercontext.cpp +++ b/modules/v4d/src/detail/framebuffercontext.cpp @@ -21,14 +21,20 @@ namespace cv { namespace v4d { namespace detail { + +static bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) { + nanogui::Vector2i d = p - w->absolute_position(); + return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y(); +} + int frameBufferContextCnt = 0; -FrameBufferContext::FrameBufferContext(const string& title, const FrameBufferContext& other) : FrameBufferContext(other.frameBufferSize_, true, title, other.major_, other.minor_, other.compat_, other.samples_, other.debug_, other.glfwWindow_, &other) { +FrameBufferContext::FrameBufferContext(V4D& v4d, const string& title, const FrameBufferContext& other) : FrameBufferContext(v4d, other.frameBufferSize_, true, title, other.major_, other.minor_, other.compat_, other.samples_, other.debug_, other.glfwWindow_, &other) { } -FrameBufferContext::FrameBufferContext(const cv::Size& framebufferSize, bool offscreen, +FrameBufferContext::FrameBufferContext(V4D& v4d, const cv::Size& framebufferSize, bool offscreen, const string& title, int major, int minor, bool compat, int samples, bool debug, GLFWwindow* sharedWindow, const FrameBufferContext* parent) : - offscreen_(offscreen), title_(title), major_(major), minor_( + v4d_(&v4d), offscreen_(offscreen), title_(title), major_(major), minor_( minor), compat_(compat), samples_(samples), debug_(debug), viewport_(0, 0, framebufferSize.width, framebufferSize.height), frameBufferSize_(framebufferSize), isShared_(false), sharedWindow_(sharedWindow), parent_(parent), framebuffer_(framebufferSize, CV_8UC4) { run_sync_on_main<1>([this](){ init(); }); index_ = ++frameBufferContextCnt; @@ -181,6 +187,7 @@ void FrameBufferContext::doWebGLCopy(FrameBufferContext& dst) { GL_CHECK(glBindVertexArray(copyVao)); GL_CHECK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0)); + GL_CHECK(glDisable(GL_BLEND)); GL_CHECK(glFlush()); #else throw std::runtime_error("WebGL not supported in none WASM builds"); @@ -273,6 +280,122 @@ void FrameBufferContext::init() { #endif setup(frameBufferSize_); + glfwSetWindowUserPointer(getGLFWWindow(), &getV4D()); + + glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + cerr << "cursor" << endl; + if(v4d->hasNguiCtx()) { + auto pt = v4d->fbCtx().toWindowCoord(cv::Point2f(x, y)); + v4d->nguiCtx().screen().cursor_pos_callback_event(pt.x, pt.y); + } +#ifndef __EMSCRIPTEN__ + auto cursor = v4d->getMousePosition(); + auto diff = cursor - cv::Vec2f(x, y); + if (v4d->isMouseDrag()) { + v4d->pan(diff[0], -diff[1]); + } +#endif + v4d->setMousePosition(x, y); + } + ); + glfwSetMouseButtonCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int button, int action, int modifiers) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + if(v4d->hasNguiCtx()) + v4d->nguiCtx().screen().mouse_button_callback_event(button, action, modifiers); + if (button == GLFW_MOUSE_BUTTON_RIGHT) { + v4d->setMouseDrag(action == GLFW_PRESS); + } + } + ); + glfwSetKeyCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int key, int scancode, int action, int mods) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + if(v4d->hasNguiCtx()) + v4d->nguiCtx().screen().key_callback_event(key, scancode, action, mods); + } + ); + glfwSetCharCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, unsigned int codepoint) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + if(v4d->hasNguiCtx()) + v4d->nguiCtx().screen().char_callback_event(codepoint); + } + ); + glfwSetDropCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int count, const char** filenames) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + if(v4d->hasNguiCtx()) + v4d->nguiCtx().screen().drop_callback_event(count, filenames); + } + ); + glfwSetScrollCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, double x, double y) { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + std::vector widgets; + if(v4d->hasNguiCtx()) { + for (auto* w : v4d->nguiCtx().screen().children()) { + auto pt = v4d->fbCtx().toWindowCoord(v4d->getMousePosition()); + auto mousePos = nanogui::Vector2i(pt[0] / v4d->pixelRatioX(), pt[1] / v4d->pixelRatioY()); + if(cv::v4d::detail::contains_absolute(w, mousePos)) { + v4d->nguiCtx().screen().scroll_callback_event(x, y); + return; + } + } + } +#ifndef __EMSCRIPTEN__ + v4d->zoom(y < 0 ? 1.1 : 0.9); +#endif + } + ); + + glfwSetWindowSizeCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int width, int height) { + cerr << "glfwSetWindowSizeCallback: " << width << endl; + run_sync_on_main<23>([glfwWin, width, height]() { + V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + cv::Rect& vp = v4d->viewport(); + cv::Size fbsz = v4d->framebufferSize(); + vp.x = 0; + vp.y = 0; + vp.width = fbsz.width; + vp.height = fbsz.height; + if(v4d->hasNguiCtx()) + v4d->nguiCtx().screen().set_size({int(v4d->getWindowSize().width / v4d->pixelRatioX()), int(v4d->getWindowSize().height / v4d->pixelRatioY())}); + }); + }); + + glfwSetFramebufferSizeCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int width, int height) { + cerr << "glfwSetFramebufferSizeCallback: " << width << endl; +// run_sync_on_main<22>([glfwWin, width, height]() { +// V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); +//// v4d->makeCurrent(); +// cv::Rect& vp = v4d->viewport(); +// cv::Size fbsz = v4d->framebufferSize(); +// vp.x = 0; +// vp.y = 0; +// vp.width = fbsz.width; +// vp.height = fbsz.height; +// +// if(v4d->hasNguiCtx()) +// v4d->nguiCtx().screen().resize_callback_event(width, height); +// }); +// #ifndef __EMSCRIPTEN__ +// if(v4d->isResizable()) { +// v4d->nvgCtx().fbCtx().teardown(); +// v4d->glCtx().fbCtx().teardown(); +// v4d->fbCtx().teardown(); +// v4d->fbCtx().setup(cv::Size(width, height)); +// v4d->glCtx().fbCtx().setup(cv::Size(width, height)); +// v4d->nvgCtx().fbCtx().setup(cv::Size(width, height)); +// } +// #endif + }); +} + +V4D& FrameBufferContext::getV4D() { + return *v4d_; } int FrameBufferContext::getIndex() { diff --git a/modules/v4d/src/detail/framebuffercontext.hpp b/modules/v4d/src/detail/framebuffercontext.hpp index 1add422b7..2af242ce6 100644 --- a/modules/v4d/src/detail/framebuffercontext.hpp +++ b/modules/v4d/src/detail/framebuffercontext.hpp @@ -154,10 +154,10 @@ public: * Create a FrameBufferContext with given size. * @param frameBufferSize The frame buffer size. */ - FrameBufferContext(const cv::Size& frameBufferSize, bool offscreen, + FrameBufferContext(V4D& v4d, const cv::Size& frameBufferSize, bool offscreen, const string& title, int major, int minor, bool compat, int samples, bool debug, GLFWwindow* sharedWindow, const FrameBufferContext* parent); - FrameBufferContext(const string& title, const FrameBufferContext& other); + FrameBufferContext(V4D& v4d, const string& title, const FrameBufferContext& other); /*! * Default destructor. @@ -199,6 +199,7 @@ public: bool isClosed(); bool isShared(); protected: + V4D& getV4D(); int getIndex(); void setup(const cv::Size& sz); void teardown(); diff --git a/modules/v4d/src/detail/glcontext.cpp b/modules/v4d/src/detail/glcontext.cpp index c1744d680..8d3b37172 100644 --- a/modules/v4d/src/detail/glcontext.cpp +++ b/modules/v4d/src/detail/glcontext.cpp @@ -8,7 +8,7 @@ namespace cv { namespace v4d { namespace detail { GLContext::GLContext(FrameBufferContext& fbContext) : - mainFbContext_(fbContext), glFbContext_("OpenGL", fbContext) { + mainFbContext_(fbContext), glFbContext_(fbContext.getV4D(), "OpenGL", fbContext) { #ifdef __EMSCRIPTEN__ run_sync_on_main<19>([&,this](){ mainFbContext_.initWebGLCopy(fbCtx()); diff --git a/modules/v4d/src/detail/nanoguicontext.cpp b/modules/v4d/src/detail/nanoguicontext.cpp index 54f871702..89f322d73 100644 --- a/modules/v4d/src/detail/nanoguicontext.cpp +++ b/modules/v4d/src/detail/nanoguicontext.cpp @@ -11,7 +11,7 @@ namespace v4d { namespace detail { NanoguiContext::NanoguiContext(FrameBufferContext& fbContext) : - mainFbContext_(fbContext), nguiFbContext_("NanoGUI", fbContext), context_( + mainFbContext_(fbContext), nguiFbContext_(fbContext.getV4D(), "NanoGUI", fbContext), context_( nullptr), copyBuffer_(mainFbContext_.size(), CV_8UC4) { run_sync_on_main<25>([this]() { { @@ -44,7 +44,7 @@ void NanoguiContext::render(bool print, bool graphical) { if (!first_) { tick_.stop(); - if (tick_.getTimeMilli() > 50) { + if (tick_.getTimeMilli() > 100) { if(print) { cerr << "FPS : " << (fps_ = tick_.getFPS()); #ifndef __EMSCRIPTEN__ @@ -56,35 +56,27 @@ void NanoguiContext::render(bool print, bool graphical) { tick_.reset(); } - if (graphical) { - run_sync_on_main<4>([this](){ - string txt = "FPS: " + std::to_string(fps_); + run_sync_on_main<4>([this, graphical](){ + string txt = "FPS: " + std::to_string(fps_); #ifndef __EMSCRIPTEN__ - if(!fbCtx().isShared()) { - mainFbContext_.copyTo(copyBuffer_); - fbCtx().copyFrom(copyBuffer_); - } + if(!fbCtx().isShared()) { + mainFbContext_.copyTo(copyBuffer_); + fbCtx().copyFrom(copyBuffer_); + } #endif - { + { #ifndef __EMSCRIPTEN__ - mainFbContext_.makeCurrent(); - GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); - GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); - glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + mainFbContext_.makeCurrent(); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); + GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); + glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); #else - FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); - GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); -// GLfloat cColor[4]; -// glGetFloatv(GL_COLOR_CLEAR_VALUE, cColor); -// glClearColor(0,0,1,1); -// glClearColor(0,0,0,0); -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -// glClearColor(cColor[0], cColor[1], cColor[2], cColor[3]); - glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } - { - FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); + FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); + GL_CHECK(glClearColor(0,0,0,0)); + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); + GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); #endif + if (graphical) { float w = mainFbContext_.size().width; float h = mainFbContext_.size().height; float r = mainFbContext_.pixelRatioX(); @@ -92,39 +84,38 @@ void NanoguiContext::render(bool print, bool graphical) { nvgSave(context_); nvgBeginFrame(context_, w, h, r); cv::v4d::nvg::detail::NVG::initializeContext(context_); - using namespace cv::v4d::nvg; beginPath(); roundedRect(5, 5, 15 * txt.size() + 5, 30, 5); fillColor(cv::Scalar(255, 255, 255, 180)); fill(); } - { + } + { #ifdef __EMSCRIPTEN__ - FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); + FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); #endif - using namespace cv::v4d::nvg; - fontSize(30.0f); - fontFace("mono"); - fillColor(cv::Scalar(90, 90, 90, 255)); - textAlign(NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); - text(10, 20, txt.c_str(), nullptr); + using namespace cv::v4d::nvg; + fontSize(30.0f); + fontFace("mono"); + fillColor(cv::Scalar(90, 90, 90, 255)); + textAlign(NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); + text(10, 20, txt.c_str(), nullptr); - nvgEndFrame(context_); - nvgRestore(context_); - screen().draw_widgets(); - } + nvgEndFrame(context_); + nvgRestore(context_); + screen().draw_widgets(); + } - if(!fbCtx().isShared()) { + if(!fbCtx().isShared()) { #ifdef __EMSCRIPTEN__ - mainFbContext_.doWebGLCopy(fbCtx()); + mainFbContext_.doWebGLCopy(fbCtx()); #else - fbCtx().copyTo(copyBuffer_); - mainFbContext_.copyFrom(copyBuffer_); + fbCtx().copyTo(copyBuffer_); + mainFbContext_.copyFrom(copyBuffer_); #endif - } - }); - } + } + }); } first_ = false; tick_.start(); @@ -133,12 +124,12 @@ void NanoguiContext::render(bool print, bool graphical) { void NanoguiContext::build(std::function fn) { run_sync_on_main<5>([fn,this](){ #ifndef __EMSCRIPTEN__ - mainFbContext_.makeCurrent(); - GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); - GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); + mainFbContext_.makeCurrent(); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); + GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); #else - FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); - GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); + FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); + GL_CHECK(glViewport(0, 0, mainFbContext_.getWindowSize().width, mainFbContext_.getWindowSize().height)); #endif fn(form()); diff --git a/modules/v4d/src/detail/nanovgcontext.cpp b/modules/v4d/src/detail/nanovgcontext.cpp index 5b7a72843..7698e2528 100644 --- a/modules/v4d/src/detail/nanovgcontext.cpp +++ b/modules/v4d/src/detail/nanovgcontext.cpp @@ -11,7 +11,7 @@ namespace v4d { namespace detail { NanoVGContext::NanoVGContext(FrameBufferContext& fbContext) : - mainFbContext_(fbContext), nvgFbContext_("NanoVG", fbContext), context_( + mainFbContext_(fbContext), nvgFbContext_(fbContext.getV4D(), "NanoVG", fbContext), context_( nullptr) { UMat tmp(fbCtx().size(), CV_8UC4); diff --git a/modules/v4d/src/util.cpp b/modules/v4d/src/util.cpp index a476e9ca0..8ef99f01a 100644 --- a/modules/v4d/src/util.cpp +++ b/modules/v4d/src/util.cpp @@ -84,7 +84,7 @@ Mat read_embedded_image(const string &path) { #endif void gl_check_error(const std::filesystem::path& file, unsigned int line, const char* expression) { -#ifndef NDEBUG +//#ifndef NDEBUG int errorCode = glGetError(); // cerr << "TRACE: " << file.filename() << " (" << line << ") : " << expression << " => code: " << errorCode << endl; if (errorCode != 0) { @@ -93,7 +93,7 @@ void gl_check_error(const std::filesystem::path& file, unsigned int line, const << expression << "\nError code:\n " << errorCode; throw std::runtime_error(ss.str()); } -#endif +//#endif } unsigned int initShader(const char* vShader, const char* fShader, const char* outputAttributeName) { diff --git a/modules/v4d/src/v4d.cpp b/modules/v4d/src/v4d.cpp index b15fc32cb..21edd7384 100644 --- a/modules/v4d/src/v4d.cpp +++ b/modules/v4d/src/v4d.cpp @@ -16,11 +16,6 @@ namespace cv { namespace v4d { namespace detail { -static bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) { - nanogui::Vector2i d = p - w->absolute_position(); - return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y(); -} - void glfw_error_callback(int error, const char* description) { fprintf(stderr, "GLFW Error: (%d) %s\n", error, description); } @@ -53,133 +48,13 @@ V4D::V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool #ifdef __EMSCRIPTEN__ printf(""); //makes sure we have FS as a dependency #endif - mainFbContext_ = new detail::FrameBufferContext(fbsize.empty() ? size : fbsize, offscreen, title_, major_, + mainFbContext_ = new detail::FrameBufferContext(*this, fbsize.empty() ? size : fbsize, offscreen, title_, major_, minor_, compat_, samples_, debug_, nullptr, nullptr); - run_sync_on_main<21>([this](){ - this->makeCurrent(); - glfwSetWindowUserPointer(getGLFWWindow(), this); - - glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - if(v4d->hasNguiCtx()) { - auto pt = v4d->fbCtx().toWindowCoord(cv::Point2f(x, y)); - v4d->nguiCtx().screen().cursor_pos_callback_event(pt.x, pt.y); - } -#ifndef __EMSCRIPTEN__ - auto cursor = v4d->getMousePosition(); - auto diff = cursor - cv::Vec2f(x, y); - if (v4d->isMouseDrag()) { - v4d->pan(diff[0], -diff[1]); - } -#endif - v4d->setMousePosition(x, y); - } - ); - glfwSetMouseButtonCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, int button, int action, int modifiers) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - if(v4d->hasNguiCtx()) - v4d->nguiCtx().screen().mouse_button_callback_event(button, action, modifiers); - if (button == GLFW_MOUSE_BUTTON_RIGHT) { - v4d->setMouseDrag(action == GLFW_PRESS); - } - } - ); - glfwSetKeyCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, int key, int scancode, int action, int mods) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - if(v4d->hasNguiCtx()) - v4d->nguiCtx().screen().key_callback_event(key, scancode, action, mods); - } - ); - glfwSetCharCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, unsigned int codepoint) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - if(v4d->hasNguiCtx()) - v4d->nguiCtx().screen().char_callback_event(codepoint); - } - ); - glfwSetDropCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, int count, const char** filenames) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - if(v4d->hasNguiCtx()) - v4d->nguiCtx().screen().drop_callback_event(count, filenames); - } - ); - glfwSetScrollCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, double x, double y) { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - std::vector widgets; - if(v4d->hasNguiCtx()) { - for (auto* w : v4d->nguiCtx().screen().children()) { - auto pt = v4d->fbCtx().toWindowCoord(v4d->getMousePosition()); - auto mousePos = nanogui::Vector2i(pt[0] / v4d->pixelRatioX(), pt[1] / v4d->pixelRatioY()); - if(cv::v4d::detail::contains_absolute(w, mousePos)) { - v4d->nguiCtx().screen().scroll_callback_event(x, y); - return; - } - } - } -//#ifndef __EMSCRIPTEN__ - v4d->zoom(y < 0 ? 1.1 : 0.9); -//#endif - } - ); - - glfwSetWindowSizeCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, int width, int height) { - cerr << "glfwSetWindowSizeCallback: " << width << endl; - run_sync_on_main<23>([glfwWin, width, height]() { - V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); -// v4d->makeCurrent(); - -// GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); -// GL_CHECK(glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); - cv::Rect& vp = v4d->viewport(); - cv::Size fbsz = v4d->framebufferSize(); - vp.x = 0; - vp.y = 0; - vp.width = fbsz.width; - vp.height = fbsz.height; -// GL_CHECK(glViewport(0, 0, v4d->getWindowSize().width, v4d->getWindowSize().height)); - - if(v4d->hasNguiCtx()) - v4d->nguiCtx().screen().set_size({int(v4d->getWindowSize().width / v4d->pixelRatioX()), int(v4d->getWindowSize().height / v4d->pixelRatioY())}); - }); - }); - - glfwSetFramebufferSizeCallback(getGLFWWindow(), - [](GLFWwindow* glfwWin, int width, int height) { - cerr << "glfwSetFramebufferSizeCallback: " << width << endl; -// run_sync_on_main<22>([glfwWin, width, height]() { -// V4D* v4d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); -//// v4d->makeCurrent(); -// cv::Rect& vp = v4d->viewport(); -// cv::Size fbsz = v4d->framebufferSize(); -// vp.x = 0; -// vp.y = 0; -// vp.width = fbsz.width; -// vp.height = fbsz.height; -// -// if(v4d->hasNguiCtx()) -// v4d->nguiCtx().screen().resize_callback_event(width, height); -// }); -// #ifndef __EMSCRIPTEN__ -// if(v4d->isResizable()) { -// v4d->nvgCtx().fbCtx().teardown(); -// v4d->glCtx().fbCtx().teardown(); -// v4d->fbCtx().teardown(); -// v4d->fbCtx().setup(cv::Size(width, height)); -// v4d->glCtx().fbCtx().setup(cv::Size(width, height)); -// v4d->nvgCtx().fbCtx().setup(cv::Size(width, height)); -// } -// #endif - }); - nvgContext_ = new detail::NanoVGContext(*mainFbContext_); - nguiContext_ = new detail::NanoguiContext(*mainFbContext_); - clvaContext_ = new detail::CLVAContext(*mainFbContext_); - glContext_ = new detail::GLContext(*mainFbContext_); - }); + nvgContext_ = new detail::NanoVGContext(*mainFbContext_); + nguiContext_ = new detail::NanoguiContext(*mainFbContext_); + clvaContext_ = new detail::CLVAContext(*mainFbContext_); + glContext_ = new detail::GLContext(*mainFbContext_); } V4D::~V4D() { @@ -685,7 +560,7 @@ bool V4D::display() { #else FrameBufferContext::GLScope glScope(fbCtx(), GL_FRAMEBUFFER); #endif - GL_CHECK(glClearColor(0, 0, 0, 0)); + GL_CHECK(glClearColor(0, 0, 0, 1)); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); }