annotate Samples/Sdl/BasicScene.cpp @ 702:c0a5eb9a4290 refactor-viewport-controller

Merge from default
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 19 May 2019 16:29:50 +0200
parents 059e1fd05fd6
children ef07304d4423
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 // From Stone
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../../Applications/Sdl/SdlOpenGLWindow.h"
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../../Framework/Scene2D/CairoCompositor.h"
610
0c4c0693b97c OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 607
diff changeset
25 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../Framework/Scene2D/OpenGLCompositor.h"
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../Framework/Scene2D/PanSceneTracker.h"
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Framework/Scene2D/RotateSceneTracker.h"
610
0c4c0693b97c OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 607
diff changeset
29 #include "../../Framework/Scene2D/Scene2D.h"
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
31 #include "../../Framework/Scene2DViewport/ViewportController.h"
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
32
610
0c4c0693b97c OrthancStone::StoneInitialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 607
diff changeset
33 #include "../../Framework/StoneInitialization.h"
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
34 #include "../../Framework/Messages/MessageBroker.h"
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 // From Orthanc framework
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <Core/Logging.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <Core/OrthancException.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <Core/Images/Image.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <Core/Images/ImageProcessing.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <Core/Images/PngWriter.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <SDL.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include <stdio.h>
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
46 static const unsigned int FONT_SIZE = 32;
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
47 static const int LAYER_POSITION = 150;
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
49 using namespace OrthancStone;
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
51 void PrepareScene(ViewportControllerPtr controller)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
53 Scene2D& scene(*controller->GetScene());
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 // Texture of 2x2 size
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 p[0] = 255;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 p[1] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 p[2] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 p[3] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 p[4] = 255;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 p[5] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 p[0] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 p[1] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 p[2] = 255;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 p[3] = 255;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 p[4] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 p[5] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 scene.SetLayer(12, new ColorTextureSceneLayer(i));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 l->SetOrigin(-3, 2);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 l->SetPixelSpacing(1.5, 1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 l->SetAngle(20.0 / 180.0 * M_PI);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 scene.SetLayer(14, l.release());
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 // Texture of 1x1 size
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 p[0] = 255;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 p[1] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 p[2] = 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 l->SetOrigin(-2, 1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 l->SetAngle(20.0 / 180.0 * M_PI);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 scene.SetLayer(13, l.release());
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 // Some lines
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 layer->SetThickness(1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 PolylineSceneLayer::Chain chain;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 layer->AddChain(chain, true);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 chain.clear();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 chain.push_back(ScenePoint2D(-5, -5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 chain.push_back(ScenePoint2D(5, -5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 chain.push_back(ScenePoint2D(5, 5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 chain.push_back(ScenePoint2D(-5, 5));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 layer->AddChain(chain, true);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 double dy = 1.01;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 chain.clear();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 chain.push_back(ScenePoint2D(-4, -4));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 chain.push_back(ScenePoint2D(4, -4 + dy));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 chain.push_back(ScenePoint2D(4, 2));
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 layer->AddChain(chain, false);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 layer->SetColor(0,255, 255);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 scene.SetLayer(50, layer.release());
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 // Some text
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
133 {
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
134 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
135 layer->SetText("Hello");
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
136 scene.SetLayer(100, layer.release());
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
137 }
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 void TakeScreenshot(const std::string& target,
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
142 const Scene2D& scene,
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 unsigned int canvasWidth,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 unsigned int canvasHeight)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 // Take a screenshot, then save it as PNG file
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
147 CairoCompositor compositor(scene, canvasWidth, canvasHeight);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 compositor.Refresh();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 Orthanc::ImageAccessor canvas;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 compositor.GetCanvas().GetReadOnlyAccessor(canvas);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 Orthanc::ImageProcessing::Convert(png, canvas);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 Orthanc::PngWriter writer;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 writer.WriteToFile(target, png);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
162 void HandleApplicationEvent(ViewportControllerPtr controller,
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
163 const OpenGLCompositor& compositor,
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 const SDL_Event& event,
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
165 FlexiblePointerTrackerPtr& activeTracker)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
167 Scene2D& scene(*controller->GetScene());
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
168 if (event.type == SDL_MOUSEMOTION)
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
169 {
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
170 int scancodeCount = 0;
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
171 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
172
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
173 if (activeTracker.get() == NULL &&
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
174 SDL_SCANCODE_LCTRL < scancodeCount &&
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
175 keyboardState[SDL_SCANCODE_LCTRL])
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
176 {
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
177 // The "left-ctrl" key is down, while no tracker is present
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
178
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
179 PointerEvent e;
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
180 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
181
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
182 ScenePoint2D p = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform());
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
183
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
184 char buf[64];
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
185 sprintf(buf, "(%0.02f,%0.02f)", p.GetX(), p.GetY());
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
186
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
187 if (scene.HasLayer(LAYER_POSITION))
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
188 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
189 TextSceneLayer& layer =
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
190 dynamic_cast<TextSceneLayer&>(scene.GetLayer(LAYER_POSITION));
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
191 layer.SetText(buf);
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
192 layer.SetPosition(p.GetX(), p.GetY());
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
193 }
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
194 else
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
195 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
196 std::auto_ptr<TextSceneLayer>
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
197 layer(new TextSceneLayer);
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
198 layer->SetColor(0, 255, 0);
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
199 layer->SetText(buf);
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
200 layer->SetBorder(20);
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
201 layer->SetAnchor(BitmapAnchor_BottomCenter);
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
202 layer->SetPosition(p.GetX(), p.GetY());
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
203 scene.SetLayer(LAYER_POSITION, layer.release());
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
204 }
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
205 }
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
206 else
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
207 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
208 scene.DeleteLayer(LAYER_POSITION);
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
209 }
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
210 }
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
211 else if (event.type == SDL_MOUSEBUTTONDOWN)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
213 PointerEvent e;
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
214 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 switch (event.button.button)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 case SDL_BUTTON_MIDDLE:
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
219 activeTracker.reset(new PanSceneTracker(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
220 controller, e));
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 case SDL_BUTTON_RIGHT:
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
224 activeTracker.reset(new ZoomSceneTracker(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
225 controller, e, compositor.GetCanvasHeight()));
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 case SDL_BUTTON_LEFT:
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
229 activeTracker.reset(new RotateSceneTracker(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
230 controller, e));
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 default:
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 else if (event.type == SDL_KEYDOWN &&
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 event.key.repeat == 0 /* Ignore key bounce */)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 switch (event.key.keysym.sym)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 case SDLK_s:
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
243 scene.FitContent(compositor.GetCanvasWidth(),
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
244 compositor.GetCanvasHeight());
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 case SDLK_c:
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
248 TakeScreenshot("screenshot.png", scene,
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
249 compositor.GetCanvasWidth(),
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
250 compositor.GetCanvasHeight());
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 default:
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 static void GLAPIENTRY
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 OpenGLMessageCallback(GLenum source,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 GLenum type,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 GLuint id,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 GLenum severity,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 GLsizei length,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 const GLchar* message,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 const void* userParam )
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 type, severity, message );
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
278 void Run(ViewportControllerPtr controller)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
280 SdlOpenGLWindow window("Hello", 1024, 768);
611
e3f21a265be5 Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents: 610
diff changeset
281
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
282 controller->GetScene()->FitContent(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
283 window.GetCanvasWidth(), window.GetCanvasHeight());
611
e3f21a265be5 Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents: 610
diff changeset
284
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 glEnable(GL_DEBUG_OUTPUT);
613
412a2d01a189 automatic initialization of glew
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
286 glDebugMessageCallback(OpenGLMessageCallback, 0);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
288 OpenGLCompositor compositor(window, *controller->GetScene());
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 FONT_SIZE, Orthanc::Encoding_Latin1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
292 FlexiblePointerTrackerPtr tracker;
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 bool stop = false;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 while (!stop)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 compositor.Refresh();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 SDL_Event event;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 while (!stop &&
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 SDL_PollEvent(&event))
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 if (event.type == SDL_QUIT)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 stop = true;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 else if (event.type == SDL_MOUSEMOTION)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
310 if (tracker)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
312 PointerEvent e;
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
313 e.AddPosition(compositor.GetPixelCenterCoordinates(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
314 event.button.x, event.button.y));
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
315 tracker->PointerMove(e);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 else if (event.type == SDL_MOUSEBUTTONUP)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
320 if (tracker)
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
322 PointerEvent e;
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
323 e.AddPosition(compositor.GetPixelCenterCoordinates(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
324 event.button.x, event.button.y));
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
325 tracker->PointerUp(e);
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
326 if(!tracker->IsAlive())
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
327 tracker = NULL;
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 else if (event.type == SDL_WINDOWEVENT &&
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
333 tracker = NULL;
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 compositor.UpdateSize();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 else if (event.type == SDL_KEYDOWN &&
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 event.key.repeat == 0 /* Ignore key bounce */)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 switch (event.key.keysym.sym)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 case SDLK_f:
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 window.GetWindow().ToggleMaximize();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 case SDLK_q:
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 stop = true;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 default:
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 break;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
602
03c4b998fcd0 display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
353
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
354 HandleApplicationEvent(controller, compositor, event, tracker);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 SDL_Delay(1);
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
607
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
362
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
363
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
364 /**
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
365 * IMPORTANT: The full arguments to "main()" are needed for SDL on
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
366 * Windows. Otherwise, one gets the linking error "undefined reference
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
367 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
368 **/
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 602
diff changeset
369 int main(int argc, char* argv[])
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
371 StoneInitialize();
613
412a2d01a189 automatic initialization of glew
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 611
diff changeset
372 Orthanc::Logging::EnableInfoLevel(true);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 try
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
376 MessageBroker broker;
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
377 ViewportControllerPtr controller(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
378 new ViewportController(broker));
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
379 PrepareScene(controller);
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
380 Run(controller);
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 catch (Orthanc::OrthancException& e)
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 LOG(ERROR) << "EXCEPTION: " << e.What();
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
387 StoneFinalize();
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 return 0;
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }