comparison Applications/Sdl/SdlOpenGLWindow.cpp @ 595:6e471e6cf09b

CairoPolylineRenderer, SdlOpenGLWindow
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 15:11:11 +0200
parents
children 412a2d01a189
comparison
equal deleted inserted replaced
594:9807ed3d3e03 595:6e471e6cf09b
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "SdlOpenGLWindow.h"
23
24 #if ORTHANC_ENABLE_SDL == 1
25
26 #include <Core/OrthancException.h>
27
28 namespace OrthancStone
29 {
30 SdlOpenGLWindow::SdlOpenGLWindow(const char* title,
31 unsigned int width,
32 unsigned int height) :
33 window_(title, width, height, true /* enable OpenGL */)
34 {
35 context_ = SDL_GL_CreateContext(window_.GetObject());
36
37 if (context_ == NULL)
38 {
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
40 "Cannot initialize OpenGL");
41 }
42 }
43
44
45 SdlOpenGLWindow::~SdlOpenGLWindow()
46 {
47 SDL_GL_DeleteContext(context_);
48 }
49
50
51 void SdlOpenGLWindow::MakeCurrent()
52 {
53 if (SDL_GL_MakeCurrent(window_.GetObject(), context_) != 0)
54 {
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
56 "Cannot set current OpenGL context");
57 }
58
59 // This makes our buffer swap syncronized with the monitor's vertical refresh
60 SDL_GL_SetSwapInterval(1);
61 }
62
63
64 void SdlOpenGLWindow::SwapBuffer()
65 {
66 // Swap our buffer to display the current contents of buffer on screen
67 SDL_GL_SwapWindow(window_.GetObject());
68 }
69
70
71 unsigned int SdlOpenGLWindow::GetCanvasWidth()
72 {
73 int w = 0;
74 SDL_GL_GetDrawableSize(window_.GetObject(), &w, NULL);
75 return static_cast<unsigned int>(w);
76 }
77
78
79 unsigned int SdlOpenGLWindow::GetCanvasHeight()
80 {
81 int h = 0;
82 SDL_GL_GetDrawableSize(window_.GetObject(), NULL, &h);
83 return static_cast<unsigned int>(h);
84 }
85 }
86
87 #endif