Mercurial > hg > orthanc-stone
comparison Samples/Qt/BasicScene.cpp @ 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 | 8a8cf2991538 |
children | 12b591d5d63c |
comparison
equal
deleted
inserted
replaced
860:238693c3bc51 | 863:23701fbf228e |
---|---|
28 #include "../../Framework/Scene2D/PanSceneTracker.h" | 28 #include "../../Framework/Scene2D/PanSceneTracker.h" |
29 #include "../../Framework/Scene2D/RotateSceneTracker.h" | 29 #include "../../Framework/Scene2D/RotateSceneTracker.h" |
30 #include "../../Framework/Scene2D/Scene2D.h" | 30 #include "../../Framework/Scene2D/Scene2D.h" |
31 #include "../../Framework/Scene2D/ZoomSceneTracker.h" | 31 #include "../../Framework/Scene2D/ZoomSceneTracker.h" |
32 #include "../../Framework/Scene2DViewport/ViewportController.h" | 32 #include "../../Framework/Scene2DViewport/ViewportController.h" |
33 #include "../../Framework/Scene2DViewport/UndoStack.h" | |
33 | 34 |
34 #include "../../Framework/StoneInitialization.h" | 35 #include "../../Framework/StoneInitialization.h" |
35 #include "../../Framework/Messages/MessageBroker.h" | 36 #include "../../Framework/Messages/MessageBroker.h" |
36 | 37 |
37 // From Orthanc framework | 38 // From Orthanc framework |
53 static const unsigned int FONT_SIZE = 32; | 54 static const unsigned int FONT_SIZE = 32; |
54 static const int LAYER_POSITION = 150; | 55 static const int LAYER_POSITION = 150; |
55 | 56 |
56 using namespace OrthancStone; | 57 using namespace OrthancStone; |
57 | 58 |
58 void PrepareScene(ViewportControllerPtr controller) | 59 void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller) |
59 { | 60 { |
60 Scene2D& scene(*controller->GetScene()); | 61 Scene2D& scene(*controller->GetScene()); |
61 // Texture of 2x2 size | 62 // Texture of 2x2 size |
62 { | 63 { |
63 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); | 64 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); |
113 PolylineSceneLayer::Chain chain; | 114 PolylineSceneLayer::Chain chain; |
114 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); | 115 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); |
115 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); | 116 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); |
116 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); | 117 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); |
117 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); | 118 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); |
118 layer->AddChain(chain, true); | 119 layer->AddChain(chain, true, 255, 0, 0); |
119 | 120 |
120 chain.clear(); | 121 chain.clear(); |
121 chain.push_back(ScenePoint2D(-5, -5)); | 122 chain.push_back(ScenePoint2D(-5, -5)); |
122 chain.push_back(ScenePoint2D(5, -5)); | 123 chain.push_back(ScenePoint2D(5, -5)); |
123 chain.push_back(ScenePoint2D(5, 5)); | 124 chain.push_back(ScenePoint2D(5, 5)); |
124 chain.push_back(ScenePoint2D(-5, 5)); | 125 chain.push_back(ScenePoint2D(-5, 5)); |
125 layer->AddChain(chain, true); | 126 layer->AddChain(chain, true, 0, 255, 0); |
126 | 127 |
127 double dy = 1.01; | 128 double dy = 1.01; |
128 chain.clear(); | 129 chain.clear(); |
129 chain.push_back(ScenePoint2D(-4, -4)); | 130 chain.push_back(ScenePoint2D(-4, -4)); |
130 chain.push_back(ScenePoint2D(4, -4 + dy)); | 131 chain.push_back(ScenePoint2D(4, -4 + dy)); |
131 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); | 132 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); |
132 chain.push_back(ScenePoint2D(4, 2)); | 133 chain.push_back(ScenePoint2D(4, 2)); |
133 layer->AddChain(chain, false); | 134 layer->AddChain(chain, false, 0, 0, 255); |
134 | 135 |
135 layer->SetColor(0,255, 255); | 136 // layer->SetColor(0,255, 255); |
136 scene.SetLayer(50, layer.release()); | 137 scene.SetLayer(50, layer.release()); |
137 } | 138 } |
138 | 139 |
139 // Some text | 140 // Some text |
140 { | 141 { |
358 // } | 359 // } |
359 | 360 |
360 // SDL_Delay(1); | 361 // SDL_Delay(1); |
361 // } | 362 // } |
362 //} | 363 //} |
364 | |
365 extern void InitGL(); | |
366 | |
363 #include <QApplication> | 367 #include <QApplication> |
364 #include "BasicSceneWindow.h" | 368 #include "BasicSceneWindow.h" |
365 int main(int argc, char* argv[]) | 369 int main(int argc, char* argv[]) |
366 { | 370 { |
367 { | 371 { |
368 QGuiApplication a(argc, argv); | 372 QApplication a(argc, argv); |
369 | 373 |
370 QSurfaceFormat requestedFormat; | 374 QSurfaceFormat requestedFormat; |
371 requestedFormat.setVersion( 2, 0 ); | 375 requestedFormat.setVersion( 2, 0 ); |
372 | 376 |
373 OrthancStone::Samples::BasicSceneWindow window; | 377 OrthancStone::Samples::BasicSceneWindow window; |
374 //window->setFormat(requestedFormat); | |
375 window.setSurfaceType(QWindow::OpenGLSurface); | |
376 window.show(); | 378 window.show(); |
377 | 379 |
378 // QWindow * window = new QWindow; | 380 MessageBroker broker; |
379 // window->setSurfaceType(QWindow::OpenGLSurface); | 381 boost::shared_ptr<UndoStack> undoStack(new UndoStack); |
380 // window->setFormat( requestedFormat ); | 382 boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>( |
381 | 383 undoStack, boost::ref(broker)); |
382 // window->show(); | 384 PrepareScene(controller); |
383 | 385 |
384 QOpenGLContext * context = new QOpenGLContext; | 386 QOpenGLContext * context = new QOpenGLContext; |
385 context->setFormat( requestedFormat ); | 387 context->setFormat( requestedFormat ); |
386 context->create(); | 388 context->create(); |
387 context->makeCurrent(&window); | 389 context->makeCurrent(window.GetOpenGlWidget().context()->surface()); |
388 | 390 |
389 GLenum err = glewInit(); | 391 |
390 if( GLEW_OK != err ){ | 392 boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene()); |
391 qDebug() << "[Error] GLEW failed to initialize. " << (const char*)glewGetErrorString(err); | 393 compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
392 } | 394 FONT_SIZE, Orthanc::Encoding_Latin1); |
395 | |
396 window.GetOpenGlWidget().SetCompositor(compositor); | |
393 | 397 |
394 return a.exec(); | 398 return a.exec(); |
395 } | 399 } |
396 | 400 |
397 | 401 |