scg3  0.6
Viewer.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright 2014-2019 Volker Ahlers
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License");
19  * you may not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  */
30 
31 #ifndef VIEWER_H_
32 #define VIEWER_H_
33 
34 #include <vector>
35 #include "scg_glew.h"
36 #include <GLFW/glfw3.h>
37 #include "scg_internals.h"
38 
39 namespace scg {
40 
41 
45 enum class OGLProfile: int {
46  NONE = 0,
47  CORE = GLFW_OPENGL_CORE_PROFILE,
48  COMPATIBILITY = GLFW_OPENGL_COMPAT_PROFILE
49 };
50 
51 
61 struct OGLConfig {
62 
65  clearColor(glm::vec4(0.15f, 0.15f, 0.15f, 1.0f)) {
66  }
67 
68  OGLConfig(int versionMajor0, int versionMinor0, GLboolean forwardCompatible0,
69  OGLProfile profile0, glm::vec4 clearColor0)
70  : versionMajor(versionMajor0), versionMinor(versionMinor0),
71  forwardCompatible(forwardCompatible0), profile(profile0), clearColor(clearColor0) {
72  }
73 
75  GLboolean forwardCompatible; // GL_TRUE requires OpenGL 3.0 or higher
76  OGLProfile profile; // CORE or COMPATIBILITY require OpenGL 3.2 or higher
77  glm::vec4 clearColor;
78 
79 };
80 
81 
91 
93  : redbits(8), greenbits(8), bluebits(8), alphabits(8), depthbits(24), stencilbits(8) {
94  }
95 
97  int depthbits;
99 
100 };
101 
102 
108 class Viewer {
109 
110 public:
111 
115  Viewer();
116 
120  virtual ~Viewer();
121 
125  static ViewerSP create();
126 
131  Viewer* init(RendererSP renderer);
132 
141  Viewer* initSimpleRenderer(CameraSP& camera, GroupSP& scene);
142 
152  Viewer* initSimpleRenderer(CameraSP& camera, GroupSP& scene, LightSP& light);
153 
160  Viewer* setOpenGLConfig(const OGLConfig& oglConfig);
161 
166  Viewer* addController(ControllerSP controller);
167 
172  Viewer* addControllers(const std::vector<ControllerSP>& controllers);
173 
178  Viewer* addControllers(std::vector<ControllerSP>&& controllers);
179 
184  Viewer* addAnimation(AnimationSP animation);
185 
190  Viewer* addAnimations(const std::vector<AnimationSP>& animations);
191 
196  Viewer* addAnimations(std::vector<AnimationSP>&& animations);
197 
203 
207  void getWindowSize(int& width, int& height) const;
208 
213  Viewer* setWindowSize(int width, int height);
214 
219  bool isWindowResized();
220 
225  Viewer* setWindowTitle(const char* title);
226 
232  Viewer* createWindow(const char* title, int width, int height);
233 
239  Viewer* createFullscreenWindow(const char* title);
240 
244  void startMainLoop();
245 
246 protected:
247 
253  void createWindow_(const char* title, int width, int height, bool fullscreenMode);
254 
258  void processControllers_();
259 
263  void processAnimations_();
264 
268  static void errorCB_(int error, const char* description);
269 
275  static void framebufferSizeCB_(GLFWwindow* window, int width, int height);
276 
277 private:
278 
283 
284 protected:
285 
286  static bool isInstantiated_;
287  static bool isWindowResized_;
288  GLFWwindow* window_;
293  std::vector<AnimationSP> animations_;
294  std::vector<ControllerSP> controllers_;
297 
298 };
299 
300 
301 } /* namespace scg */
302 
303 #endif /* VIEWER_H_ */
Viewer * setOpenGLConfig(const OGLConfig &oglConfig)
static bool isInstantiated_
Definition: Viewer.h:286
Viewer * setWindowSize(int width, int height)
OGLProfile
Profile definitions for OGLConfig.
Definition: Viewer.h:45
Base class for all cameras (composite node, abstract).
Definition: Camera.h:51
ViewStateUP viewState_
Definition: Viewer.h:289
Viewer * startAnimations()
void processAnimations_()
OGLProfile profile
Definition: Viewer.h:76
OGLConfig oglConfig_
Definition: Viewer.h:290
int versionMinor
Definition: Viewer.h:74
SCG_DISALLOW_COPY_AND_ASSIGN(Viewer)
A light to be applied to all nodes of its sub-tree (composite node).
Definition: Light.h:54
Viewer * addAnimation(AnimationSP animation)
Central viewer managing window, controllers, animations, and main loop.
Definition: Viewer.h:108
void startMainLoop()
A group node to be used as root of a sub-tree of nodes (composite node).
Definition: Group.h:41
Viewer * addController(ControllerSP controller)
static void framebufferSizeCB_(GLFWwindow *window, int width, int height)
int versionMajor
Definition: Viewer.h:74
void createWindow_(const char *title, int width, int height, bool fullscreenMode)
OpenGL configuration, may be set by user before calling Viewer::init().
Definition: Viewer.h:61
void processControllers_()
Frame buffer size, to be set by renderer in Renderer::initViewer(), called by Viewer::init().
Definition: Viewer.h:90
Local header file for GLEW library.
Viewer * initSimpleRenderer(CameraSP &camera, GroupSP &scene)
Base class for all animations (abstract), providing general functionality.
Definition: Animation.h:34
bool isWindowResized()
OGLConfig(int versionMajor0, int versionMinor0, GLboolean forwardCompatible0, OGLProfile profile0, glm::vec4 clearColor0)
Definition: Viewer.h:68
GLbitfield frameBufferClearMask_
Definition: Viewer.h:296
RendererSP renderer_
Definition: Viewer.h:292
Viewer * createWindow(const char *title, int width, int height)
The view state of the application, managed by Viewer and accessible by Controller::checkInput() (or d...
Definition: ViewState.h:39
static ViewerSP create()
Viewer * addAnimations(const std::vector< AnimationSP > &animations)
Viewer * setWindowTitle(const char *title)
Viewer * init(RendererSP renderer)
glm::vec4 clearColor
Definition: Viewer.h:77
Viewer * createFullscreenWindow(const char *title)
static void errorCB_(int error, const char *description)
std::vector< AnimationSP > animations_
Definition: Viewer.h:293
int oglVersion_
Definition: Viewer.h:291
FrameBufferSize frameBufferSize_
Definition: Viewer.h:295
Definition: Animation.h:28
Internal definitions required by most classes.
Viewer * addControllers(const std::vector< ControllerSP > &controllers)
virtual ~Viewer()
GLboolean forwardCompatible
Definition: Viewer.h:75
static bool isWindowResized_
Definition: Viewer.h:287
void getWindowSize(int &width, int &height) const
Base class for all controllers (abstract).
Definition: Controller.h:36
std::vector< ControllerSP > controllers_
Definition: Viewer.h:294
GLFWwindow * window_
Definition: Viewer.h:288
Base class for all renderers (abstract).
Definition: Renderer.h:45