Mercurial > hg > orthanc-stone
comparison Samples/Sdl/TrackerSample.cpp @ 656:002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
might also be needed on macos and GNU/Linux ?) + fixed text info overlay pos
for angle measure (this requires the app to be aware of the compositor)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 14 May 2019 16:54:13 +0200 |
parents | 462a5074f914 |
children | cb3b76d16234 |
comparison
equal
deleted
inserted
replaced
655:1e26bb5f2a02 | 656:002d9562c8f5 |
---|---|
51 | 51 |
52 using namespace Orthanc; | 52 using namespace Orthanc; |
53 using namespace OrthancStone; | 53 using namespace OrthancStone; |
54 | 54 |
55 | 55 |
56 static void GLAPIENTRY | |
57 OpenGLMessageCallback(GLenum source, | |
58 GLenum type, | |
59 GLuint id, | |
60 GLenum severity, | |
61 GLsizei length, | |
62 const GLchar* message, | |
63 const void* userParam) | |
64 { | |
65 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) | |
66 { | |
67 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", | |
68 (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), | |
69 type, severity, message); | |
70 } | |
71 } | |
72 | 56 |
73 bool g_stopApplication = false; | |
74 | 57 |
75 void Run(TrackerSampleApp* app) | |
76 { | |
77 SdlOpenGLWindow window("Hello", 1024, 768); | |
78 | |
79 app->GetScene().FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); | |
80 | |
81 glEnable(GL_DEBUG_OUTPUT); | |
82 glDebugMessageCallback(OpenGLMessageCallback, 0); | |
83 | |
84 OpenGLCompositor compositor(window, app->GetScene()); | |
85 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | |
86 FONT_SIZE, Orthanc::Encoding_Latin1); | |
87 | |
88 while (!g_stopApplication) | |
89 { | |
90 compositor.Refresh(); | |
91 | |
92 SDL_Event event; | |
93 while (!g_stopApplication && SDL_PollEvent(&event)) | |
94 { | |
95 if (event.type == SDL_QUIT) | |
96 { | |
97 g_stopApplication = true; | |
98 break; | |
99 } | |
100 else if (event.type == SDL_WINDOWEVENT && | |
101 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) | |
102 { | |
103 app->DisableTracker(); // was: tracker.reset(NULL); | |
104 compositor.UpdateSize(); | |
105 } | |
106 else if (event.type == SDL_KEYDOWN && | |
107 event.key.repeat == 0 /* Ignore key bounce */) | |
108 { | |
109 switch (event.key.keysym.sym) | |
110 { | |
111 case SDLK_f: | |
112 window.GetWindow().ToggleMaximize(); | |
113 break; | |
114 | |
115 case SDLK_q: | |
116 g_stopApplication = true; | |
117 break; | |
118 default: | |
119 break; | |
120 } | |
121 } | |
122 app->HandleApplicationEvent(compositor, event); | |
123 } | |
124 SDL_Delay(1); | |
125 } | |
126 } | |
127 | 58 |
128 | 59 |
129 /** | 60 /** |
130 * IMPORTANT: The full arguments to "main()" are needed for SDL on | 61 * IMPORTANT: The full arguments to "main()" are needed for SDL on |
131 * Windows. Otherwise, one gets the linking error "undefined reference | 62 * Windows. Otherwise, one gets the linking error "undefined reference |
141 try | 72 try |
142 { | 73 { |
143 MessageBroker broker; | 74 MessageBroker broker; |
144 TrackerSampleApp app(broker); | 75 TrackerSampleApp app(broker); |
145 app.PrepareScene(); | 76 app.PrepareScene(); |
146 Run(&app); | 77 app.Run(); |
147 } | 78 } |
148 catch (Orthanc::OrthancException& e) | 79 catch (Orthanc::OrthancException& e) |
149 { | 80 { |
150 LOG(ERROR) << "EXCEPTION: " << e.What(); | 81 LOG(ERROR) << "EXCEPTION: " << e.What(); |
151 } | 82 } |