Mercurial > hg > orthanc-stone
changeset 863:23701fbf228e am-dev
first rendering of a 2DScene in Qt widget
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 24 Jun 2019 16:29:49 +0200 |
parents | 238693c3bc51 |
children | 733c6db3e5a3 |
files | Samples/Qt/BasicScene.cpp Samples/Qt/CMakeLists.txt Samples/Qt/QStoneOpenGlWidget.cpp Samples/Qt/QStoneOpenGlWidget.h |
diffstat | 4 files changed, 32 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/Samples/Qt/BasicScene.cpp Mon Jun 24 14:35:00 2019 +0200 +++ b/Samples/Qt/BasicScene.cpp Mon Jun 24 16:29:49 2019 +0200 @@ -30,6 +30,7 @@ #include "../../Framework/Scene2D/Scene2D.h" #include "../../Framework/Scene2D/ZoomSceneTracker.h" #include "../../Framework/Scene2DViewport/ViewportController.h" +#include "../../Framework/Scene2DViewport/UndoStack.h" #include "../../Framework/StoneInitialization.h" #include "../../Framework/Messages/MessageBroker.h" @@ -55,7 +56,7 @@ using namespace OrthancStone; -void PrepareScene(ViewportControllerPtr controller) +void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller) { Scene2D& scene(*controller->GetScene()); // Texture of 2x2 size @@ -115,14 +116,14 @@ chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); - layer->AddChain(chain, true); + layer->AddChain(chain, true, 255, 0, 0); chain.clear(); chain.push_back(ScenePoint2D(-5, -5)); chain.push_back(ScenePoint2D(5, -5)); chain.push_back(ScenePoint2D(5, 5)); chain.push_back(ScenePoint2D(-5, 5)); - layer->AddChain(chain, true); + layer->AddChain(chain, true, 0, 255, 0); double dy = 1.01; chain.clear(); @@ -130,9 +131,9 @@ chain.push_back(ScenePoint2D(4, -4 + dy)); chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); chain.push_back(ScenePoint2D(4, 2)); - layer->AddChain(chain, false); + layer->AddChain(chain, false, 0, 0, 255); - layer->SetColor(0,255, 255); +// layer->SetColor(0,255, 255); scene.SetLayer(50, layer.release()); } @@ -360,36 +361,39 @@ // SDL_Delay(1); // } //} + +extern void InitGL(); + #include <QApplication> #include "BasicSceneWindow.h" int main(int argc, char* argv[]) { { - QGuiApplication a(argc, argv); + QApplication a(argc, argv); QSurfaceFormat requestedFormat; requestedFormat.setVersion( 2, 0 ); OrthancStone::Samples::BasicSceneWindow window; - //window->setFormat(requestedFormat); - window.setSurfaceType(QWindow::OpenGLSurface); window.show(); -// QWindow * window = new QWindow; -// window->setSurfaceType(QWindow::OpenGLSurface); -// window->setFormat( requestedFormat ); - -// window->show(); + MessageBroker broker; + boost::shared_ptr<UndoStack> undoStack(new UndoStack); + boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>( + undoStack, boost::ref(broker)); + PrepareScene(controller); QOpenGLContext * context = new QOpenGLContext; context->setFormat( requestedFormat ); context->create(); - context->makeCurrent(&window); + context->makeCurrent(window.GetOpenGlWidget().context()->surface()); + - GLenum err = glewInit(); - if( GLEW_OK != err ){ - qDebug() << "[Error] GLEW failed to initialize. " << (const char*)glewGetErrorString(err); - } + boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene()); + compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, + FONT_SIZE, Orthanc::Encoding_Latin1); + + window.GetOpenGlWidget().SetCompositor(compositor); return a.exec(); }
--- a/Samples/Qt/CMakeLists.txt Mon Jun 24 14:35:00 2019 +0200 +++ b/Samples/Qt/CMakeLists.txt Mon Jun 24 16:29:49 2019 +0200 @@ -47,6 +47,9 @@ include(${CMAKE_SOURCE_DIR}/../../Resources/CMake/OrthancStoneConfiguration.cmake) +add_definitions( + -DORTHANC_ENABLE_LOGGING_PLUGIN=0 + ) ##################################################################### ## Build the samples #####################################################################
--- a/Samples/Qt/QStoneOpenGlWidget.cpp Mon Jun 24 14:35:00 2019 +0200 +++ b/Samples/Qt/QStoneOpenGlWidget.cpp Mon Jun 24 16:29:49 2019 +0200 @@ -3,9 +3,12 @@ void QStoneOpenGlWidget::initializeGL() { - // Set up the rendering context, load shaders and other resources, etc.: - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glewInit(); +} + +void QStoneOpenGlWidget::MakeCurrent() +{ + this->makeCurrent(); } void QStoneOpenGlWidget::resizeGL(int w, int h) @@ -15,13 +18,6 @@ void QStoneOpenGlWidget::paintGL() { - makeCurrent(); - - // // Draw the scene: - // QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - // f->glClear(GL_COLOR_BUFFER_BIT); - // f->glClearColor(1.0f, 0.3f, 0.5f, 1.0f); - if (compositor_) { compositor_->Refresh();