ViewWidget::ViewWidget(QWidget * widget, osgViewer::View * view, osg::Group * sceneRoot, bool showGrids, bool showAxes) : _widget(widget), _view(view), compassAxes(0), mpXYGridTransform(0), mpXZGridTransform(0), mpYZGridTransform(0) { if (!view) return; _sceneRoot = static_cast<osg::Group*>(_view->getSceneData()); _showGrids = showGrids; _showAxes = showAxes; if (_showGrids) { initGrids(); if (mpXYGridTransform && sceneRoot) _sceneRoot->addChild(getXYGrid()); } if (_showAxes) { initAxes(); if (compassAxes && sceneRoot) _sceneRoot->addChild(getAxes()); } xyGridToggled = showGrids; axesToggled = showAxes; }
void View3D::initializeGL() { if (glewInit() != GLEW_OK) { g_logger.error("%s", "Failed to initialize GLEW"); m_badOpenGL = true; return; } g_logger.info("OpenGL implementation:\n" " GL_VENDOR = %s\n" " GL_RENDERER = %s\n" " GL_VERSION = %s\n" " GLSL_VERSION = %s\n" " GLEW_VERSION = %s", (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER), (const char*)glGetString(GL_VERSION), (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION), (const char*)glewGetString(GLEW_VERSION)); // GL_CHECK has to be defined for this to actually do something glCheckError(); initCursor(10, 1); initAxes(); initGrid(2.0f); glCheckError(); m_boundingBoxShader.reset(new ShaderProgram()); m_boundingBoxShader->setShaderFromSourceFile("shaders:bounding_box.glsl"); m_meshFaceShader.reset(new ShaderProgram()); m_meshFaceShader->setShaderFromSourceFile("shaders:meshface.glsl"); m_meshEdgeShader.reset(new ShaderProgram()); m_meshEdgeShader->setShaderFromSourceFile("shaders:meshedge.glsl"); m_annotationShader.reset(new ShaderProgram()); m_annotationShader->setShaderFromSourceFile("shaders:annotation.glsl"); double dPR = getDevicePixelRatio(); int w = width() * dPR; int h = height() * dPR; m_incrementalFramebuffer.init(w, h); initializeGLGeometry(0, m_geometries->get().size()); // FIXME: Do something about this mess. The shader editor widget needs to // be initialized with the default shader, but View3D can only compile // shaders after it has a valid OpenGL context. PointViewerMainWindow * pv_parent = dynamic_cast<PointViewerMainWindow *>(parentWidget()); if (pv_parent) pv_parent->openShaderFile("shaders:las_points.glsl"); setFocus(); }
/*! \brief Initializes a QwtPlot instance \param title Title text */ void QwtPlot::initPlot(const QString &title) { d_layout = new QwtPlotLayout; d_curves = new QwtCurveDict; d_markers = new QwtMarkerDict; d_autoReplot = FALSE; d_lblTitle = new QLabel(title, this); d_lblTitle->setFont(QFont(fontInfo().family(), 14, QFont::Bold)); d_lblTitle->setAlignment(Qt::AlignCenter|Qt::WordBreak|Qt::ExpandTabs); d_legend = new QwtLegend(this); d_autoLegend = FALSE; d_scale[yLeft] = new QwtScale(QwtScale::Left, this, "yLeft"); d_scale[yRight] = new QwtScale(QwtScale::Right, this, "yRight"); d_scale[xTop] = new QwtScale(QwtScale::Top, this, "xTop"); d_scale[xBottom] = new QwtScale(QwtScale::Bottom, this, "xBottom"); initAxes(); d_grid = new QwtPlotGrid(this); d_grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); d_grid->enableXMin(FALSE); d_grid->enableYMin(FALSE); d_grid->setAxis(xBottom, yLeft); d_canvas = new QwtPlotCanvas(this); d_canvas->setFrameStyle(QFrame::Panel|QFrame::Sunken); d_canvas->setLineWidth(2); d_canvas->setMidLineWidth(0); #ifndef QWT_NO_COMPAT connect(d_canvas, SIGNAL(mousePressed(const QMouseEvent &)), this, SIGNAL(plotMousePressed(const QMouseEvent &))); connect(d_canvas, SIGNAL(mouseMoved(const QMouseEvent &)), this, SIGNAL(plotMouseMoved(const QMouseEvent &))); connect(d_canvas, SIGNAL(mouseReleased(const QMouseEvent &)), this, SIGNAL(plotMouseReleased(const QMouseEvent &))); #endif updateTabOrder(); QSizePolicy sp; sp.setHorData( QSizePolicy::MinimumExpanding ); sp.setVerData( QSizePolicy::MinimumExpanding ); setSizePolicy(sp); }
/*! \brief Initializes a QwtPlot instance \param title Title text */ void QwtPlot::initPlot(const QString &title) { d_margin = 0; d_spacing = 5; // space below the title d_curves = new QwtCurveDict; d_markers = new QwtMarkerDict; d_autoReplot = FALSE; d_lblTitle = new QLabel(title, this); d_lblTitle->setFont(QFont("Helvetica", 14,QFont::Bold)); d_lblTitle->setAlignment(AlignHCenter|AlignBottom|WordBreak|ExpandTabs); #ifndef QWT_NO_LEGEND d_legend = new QwtLegend(this); connect(d_legend, SIGNAL(clicked(int)), SLOT(lgdClicked(int))); #endif d_legendPos = Qwt::Bottom; d_autoLegend = FALSE; d_scale[yLeft] = new QwtScale(QwtScale::Left, this, "yLeft"); d_scale[yRight] = new QwtScale(QwtScale::Right, this, "yRight"); d_scale[xTop] = new QwtScale(QwtScale::Top, this, "xTop"); d_scale[xBottom] = new QwtScale(QwtScale::Bottom, this, "xBottom"); initAxes(); d_grid.setPen(QPen(black, 0, DotLine)); d_grid.setXDiv(d_sdiv[xBottom]); d_grid.setYDiv(d_sdiv[yLeft]); d_grid.enableXMin(FALSE); d_grid.enableYMin(FALSE); d_grid.setAxis(xBottom, yLeft); d_canvas = new QwtPlotCanvas(this); d_canvas->setFrameStyle(QFrame::Panel|QFrame::Sunken); d_canvas->setLineWidth(2); d_canvas->setMidLineWidth(0); connect(d_canvas, SIGNAL(mousePressed(const QMouseEvent &)), this, SIGNAL(plotMousePressed(const QMouseEvent &))); connect(d_canvas, SIGNAL(mouseMoved(const QMouseEvent &)), this, SIGNAL(plotMouseMoved(const QMouseEvent &))); connect(d_canvas, SIGNAL(mouseReleased(const QMouseEvent &)), this, SIGNAL(plotMouseReleased(const QMouseEvent &))); }
void View3D::initializeGL() { // GLEW has a problem with core contexts. It calls glGetString(GL_EXTENSIONS), // which causes GL_INVALID_ENUM on GL 3.2+ core context as soon as glewInit() is called. // It also doesn't fetch the function pointers. The solution is for GLEW to use glGetStringi instead. // The current version of GLEW is 1.10.0 but they still haven't corrected it. // The only fix is to use glewExperimental for now. // https://www.opengl.org/wiki/OpenGL_Loading_Library glewExperimental = true; if (glewInit() != GLEW_OK) { g_logger.error("%s", "Failed to initialize GLEW"); m_badOpenGL = true; return; } g_logger.info("OpenGL implementation:\n" "GL_VENDOR = %s\n" "GL_RENDERER = %s\n" "GL_VERSION = %s\n" "GLSL_VERSION = %s\n" "GLEW_VERSION = %s\n", (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER), (const char*)glGetString(GL_VERSION), (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION), (const char*)glewGetString(GLEW_VERSION)); // GL_CHECK has to be defined for this to actually do something glCheckError(); initCursor(10, 1); initAxes(); initGrid(2.0f); glCheckError(); m_boundingBoxShader.reset(new ShaderProgram()); m_boundingBoxShader->setShaderFromSourceFile("shaders:bounding_box.glsl"); m_meshFaceShader.reset(new ShaderProgram()); m_meshFaceShader->setShaderFromSourceFile("shaders:meshface.glsl"); m_meshEdgeShader.reset(new ShaderProgram()); m_meshEdgeShader->setShaderFromSourceFile("shaders:meshedge.glsl"); double dPR = getDevicePixelRatio(); int w = width() * dPR; int h = height() * dPR; m_incrementalFramebuffer = allocIncrementalFramebuffer(w, h); glFrameBufferStatus(m_incrementalFramebuffer); glCheckError(); const GeometryCollection::GeometryVec& geoms = m_geometries->get(); for (size_t i = 0; i < geoms.size(); ++i) { if (m_boundingBoxShader->isValid()) { // TODO: build a shader manager for this geoms[i]->setShaderId("boundingbox", m_boundingBoxShader->shaderProgram().programId()); geoms[i]->setShaderId("meshface", m_meshFaceShader->shaderProgram().programId()); geoms[i]->setShaderId("meshedge", m_meshEdgeShader->shaderProgram().programId()); geoms[i]->initializeGL(); } } // FIXME: Do something about this mess. The shader editor widget needs to // be initialized with the default shader, but View3D can only compile // shaders after it has a valid OpenGL context. PointViewerMainWindow * pv_parent = dynamic_cast<PointViewerMainWindow *>(parentWidget()); pv_parent->openShaderFile("shaders:las_points.glsl"); setFocus(); }
StereotrodePlot::StereotrodePlot(int x, int y, int w, int h): BaseUIElement(x,y,w,h,0), limitsChanged(true) { initAxes(); }
int Application::run(Application* self) { m_self = self; if (!framework::Utils::exists("data/gui")) { Logger::toLog("Error: could not find gui directory. Probably working directory has not been set correctly (especially if you are running from IDE).\n"); return EXIT_FAILURE; } init(); m_isRunning = true; glfwSetErrorCallback(&Application::errorCallback); if (!glfwInit()) { Logger::toLog("Error: glfwInit failed"); return EXIT_FAILURE; } glfwWindowHint(GLFW_VISIBLE, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_RED_BITS, 8); glfwWindowHint(GLFW_GREEN_BITS, 8); glfwWindowHint(GLFW_BLUE_BITS, 8); glfwWindowHint(GLFW_ALPHA_BITS, 0); glfwWindowHint(GLFW_DEPTH_BITS, 32); glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_info.majorVersion); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_info.minorVersion); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_SAMPLES, m_info.samples); glfwWindowHint(GLFW_STEREO, m_info.flags.stereo ? GL_TRUE : GL_FALSE); // create window m_window = glfwCreateWindow(m_info.windowWidth, m_info.windowHeight, m_info.title.c_str(), m_info.flags.fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL); if (!m_window) { glfwTerminate(); return EXIT_FAILURE; } glfwSetWindowSizeCallback(m_window, &Application::_setWindowSize); glfwSetKeyCallback(m_window, &Application::_onKey); glfwSetCharCallback(m_window, &Application::_onChar); glfwSetMouseButtonCallback(m_window, &Application::_onMouse); glfwSetCursorPosCallback(m_window, &Application::_onCursor); glfwSetScrollCallback(m_window, &Application::_onScroll); glfwSetInputMode(m_window, GLFW_CURSOR, m_info.flags.cursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); // center position GLFWmonitor* primary = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(primary); int posx = (mode->width - m_info.windowWidth) >> 1; int posy = (mode->height - m_info.windowHeight) >> 1; glfwSetWindowPos(m_window, posx, posy); // set vsync glfwMakeContextCurrent(m_window); glfwSwapInterval((int)m_info.flags.vsync); // init GL3w gl3wInit(); std::vector<int> multisamplingLevels; if (!checkOpenGLVersion() || !checkDeviceCapabilities(multisamplingLevels)) { glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_FAILURE; } #ifdef _DEBUG Logger::toLogWithFormat("Video adapter: %s - %s, OpenGL: %s\n", (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER), (const char*)glGetString(GL_VERSION)); #endif if (m_info.flags.debug) { if (gl3wIsSupported(4, 3)) { glDebugMessageCallback(debugCallback, this); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); } else if (IsExtensionSupported("GL_ARB_debug_output")) { glDebugMessageCallbackARB(debugCallback, this); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); } } initGui(); if (!StandardGpuPrograms::init()) { glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_FAILURE; } initAxes(); startup(m_rootWindow); do { glfwMakeContextCurrent(m_window); Texture::beginFrame(); if (fabs(m_lastTime) < 1e-7) { render(0); Texture::endFrame(); renderGui(0); m_lastTime = glfwGetTime(); } else { double curTime = glfwGetTime(); double delta = curTime - m_lastTime; // fps counter measureFps(delta); // rendering render(delta); Texture::endFrame(); renderGui(delta); m_lastTime = curTime; } glfwSwapBuffers(m_window); glfwPollEvents(); if (glfwWindowShouldClose(m_window)) { m_isRunning = GL_FALSE; } m_isRunning &= (glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_RELEASE); } while(m_isRunning); shutdown(); destroyAllDestroyable(); destroyGui(); glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_SUCCESS; }