Mercurial > hg > orthanc-stone
comparison Samples/Qt/BasicScene.cpp @ 885:56e4e9281076 am-dev
sharing code between Qt/SDL BasiceScene sample
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Tue, 09 Jul 2019 16:44:25 +0200 |
parents | 30268a0cafca |
children | 6073c980323a |
comparison
equal
deleted
inserted
replaced
884:aad5ccf1be10 | 885:56e4e9281076 |
---|---|
49 //#include <SDL.h> | 49 //#include <SDL.h> |
50 #include <stdio.h> | 50 #include <stdio.h> |
51 #include <QDebug> | 51 #include <QDebug> |
52 #include <QWindow> | 52 #include <QWindow> |
53 | 53 |
54 static const unsigned int FONT_SIZE = 32; | 54 #include "../Shared/SharedBasicScene.h" |
55 static const int LAYER_POSITION = 150; | 55 |
56 | 56 |
57 using namespace OrthancStone; | 57 using namespace OrthancStone; |
58 | 58 |
59 void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller) | |
60 { | |
61 Scene2D& scene(*controller->GetScene()); | |
62 // Texture of 2x2 size | |
63 { | |
64 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); | |
65 | |
66 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
67 p[0] = 255; | |
68 p[1] = 0; | |
69 p[2] = 0; | |
70 | |
71 p[3] = 0; | |
72 p[4] = 255; | |
73 p[5] = 0; | |
74 | |
75 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); | |
76 p[0] = 0; | |
77 p[1] = 0; | |
78 p[2] = 255; | |
79 | |
80 p[3] = 255; | |
81 p[4] = 0; | |
82 p[5] = 0; | |
83 | |
84 scene.SetLayer(12, new ColorTextureSceneLayer(i)); | |
85 | |
86 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
87 l->SetOrigin(-3, 2); | |
88 l->SetPixelSpacing(1.5, 1); | |
89 l->SetAngle(20.0 / 180.0 * 3.14); | |
90 scene.SetLayer(14, l.release()); | |
91 } | |
92 | |
93 // Texture of 1x1 size | |
94 { | |
95 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); | |
96 | |
97 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
98 p[0] = 255; | |
99 p[1] = 0; | |
100 p[2] = 0; | |
101 | |
102 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
103 l->SetOrigin(-2, 1); | |
104 l->SetAngle(20.0 / 180.0 * 3.14); | |
105 scene.SetLayer(13, l.release()); | |
106 } | |
107 | |
108 // Some lines | |
109 { | |
110 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); | |
111 | |
112 layer->SetThickness(1); | |
113 | |
114 PolylineSceneLayer::Chain chain; | |
115 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); | |
116 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); | |
117 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); | |
118 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); | |
119 layer->AddChain(chain, true, 255, 0, 0); | |
120 | |
121 chain.clear(); | |
122 chain.push_back(ScenePoint2D(-5, -5)); | |
123 chain.push_back(ScenePoint2D(5, -5)); | |
124 chain.push_back(ScenePoint2D(5, 5)); | |
125 chain.push_back(ScenePoint2D(-5, 5)); | |
126 layer->AddChain(chain, true, 0, 255, 0); | |
127 | |
128 double dy = 1.01; | |
129 chain.clear(); | |
130 chain.push_back(ScenePoint2D(-4, -4)); | |
131 chain.push_back(ScenePoint2D(4, -4 + dy)); | |
132 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); | |
133 chain.push_back(ScenePoint2D(4, 2)); | |
134 layer->AddChain(chain, false, 0, 0, 255); | |
135 | |
136 // layer->SetColor(0,255, 255); | |
137 scene.SetLayer(50, layer.release()); | |
138 } | |
139 | |
140 // Some text | |
141 { | |
142 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); | |
143 layer->SetText("Hello"); | |
144 scene.SetLayer(100, layer.release()); | |
145 } | |
146 } | |
147 | 59 |
148 | 60 |
149 static void GLAPIENTRY OpenGLMessageCallback(GLenum source, | 61 static void GLAPIENTRY OpenGLMessageCallback(GLenum source, |
150 GLenum type, | 62 GLenum type, |
151 GLuint id, | 63 GLuint id, |
164 | 76 |
165 extern void InitGL(); | 77 extern void InitGL(); |
166 | 78 |
167 #include <QApplication> | 79 #include <QApplication> |
168 #include "BasicSceneWindow.h" | 80 #include "BasicSceneWindow.h" |
169 #include "Scene2DInteractor.h" | |
170 | 81 |
171 int main(int argc, char* argv[]) | 82 int main(int argc, char* argv[]) |
172 { | 83 { |
173 { | 84 { |
174 QApplication a(argc, argv); | 85 QApplication a(argc, argv); |
193 context->create(); | 104 context->create(); |
194 context->makeCurrent(window.GetOpenGlWidget().context()->surface()); | 105 context->makeCurrent(window.GetOpenGlWidget().context()->surface()); |
195 | 106 |
196 boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene()); | 107 boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene()); |
197 compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | 108 compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
198 FONT_SIZE, Orthanc::Encoding_Latin1); | 109 BASIC_SCENE_FONT_SIZE, Orthanc::Encoding_Latin1); |
199 | 110 |
200 interactor->SetCompositor(compositor); | 111 interactor->SetCompositor(compositor); |
201 window.GetOpenGlWidget().SetCompositor(compositor); | 112 window.GetOpenGlWidget().SetCompositor(compositor); |
202 | 113 |
203 return a.exec(); | 114 return a.exec(); |