Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
viewer.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_HW_VIEWER_H_)
21 #define __MITSUBA_HW_VIEWER_H_
22 
23 #include <mitsuba/render/util.h>
24 #include <mitsuba/hw/renderer.h>
25 #include <mitsuba/hw/font.h>
26 
28 
29 /**
30  * \brief Template for simple GLUT-style viewer applications
31  *
32  * This class makes it possible to rapidly prototype simple OpenGL
33  * applications, which can be started using the 'mtsutil' launcher.
34  *
35  * \ingroup libhw
36  */
38 public:
39  /// Construct a new viewer
40  Viewer();
41 
42  /**
43  * \brief Program entry point
44  *
45  * The viewer is initialized by this method -- to add custom
46  * initialization code, please override \ref init
47  */
48  int run(int argc, char **argv);
49 protected:
50  /// Draw a heads-up display
51  void drawHUD(const std::string &text);
52 
53  /// Request that the draw() routine be called
54  inline void redraw() { m_leaveEventLoop = true; }
55 
56  /// To be overwritten by the subclass: main drawing routine
57  virtual void draw() = 0;
58 
59  /**
60  * \brief To be overwritten (optionally): perform any necessary
61  * initializations
62  *
63  * The default implementation does nothing and returns \c true.
64  *
65  * \param argc Number of command line arguments
66  * \param argv List of command line argument strings
67  * \return \c true upon success. Otherwise, the viewer will quit.
68  */
69  virtual bool init(int argc, char **argv);
70 
71  /// To be overwritten (optionally): perform any necessary cleanups
72  virtual void shutdown();
73 
74  /// To be overwritten (optionally): handle a key press event
75  virtual void keyPressed(const DeviceEvent &event);
76 
77  /// To be overwritten (optionally): handle a key release event
78  virtual void keyReleased(const DeviceEvent &event);
79 
80  /// To be overwritten (optionally): handle a mouse button press event
81  virtual void mouseButtonPressed(const DeviceEvent &event);
82 
83  /// To be overwritten (optionally): handle a mouse button release event
84  virtual void mouseButtonReleased(const DeviceEvent &event);
85 
86  /// To be overwritten (optionally): handle a mouse motion event
87  virtual void mouseMoved(const DeviceEvent &event);
88 
89  /// To be overwritten (optionally): handle a mouse begin drag event
90  virtual void mouseBeginDrag(const DeviceEvent &event);
91 
92  /// To be overwritten (optionally): handle a mouse drag event
93  virtual void mouseDragged(const DeviceEvent &event);
94 
95  /// To be overwritten (optionally): handle a mouse end drag event
96  virtual void mouseEndDrag(const DeviceEvent &event);
97 
98  /// To be overwritten (optionally): handle a window resize event
99  virtual void windowResized(const DeviceEvent &event);
100 
101 private:
102  bool deviceEventOccurred(const DeviceEvent &event);
103 
105 protected:
106  ref<Session> m_session;
107  ref<Device> m_device;
108  ref<Renderer> m_renderer;
109  ref<Font> m_font;
110  bool m_quit, m_leaveEventLoop;
111 };
112 
114 
115 #endif /* __MITSUBA_HW_VIEWER_H_ */
virtual bool deviceEventOccurred(const DeviceEvent &event)=0
Called when a device event occurs.
The device event structure encapsulates event information such as mouse movement or key presses...
Definition: device.h:34
Utility class used to render text inside OpenGL programs using pre-rasterized TrueType fonts stored a...
Definition: font.h:34
#define MTS_EXPORT_HW
Definition: platform.h:114
Abstract utility class – can be used to implement loadable utility plugins that perform various actio...
Definition: util.h:32
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
#define MTS_DECLARE_UTILITY()
Definition: util.h:59
An abstract drawing device.
Definition: device.h:136
Abstract device event callback.
Definition: device.h:121
void redraw()
Request that the draw() routine be called.
Definition: viewer.h:54
Template for simple GLUT-style viewer applications.
Definition: viewer.h:37
Reference counting helper.
Definition: ref.h:40
Abstract renderer implementation.
Definition: renderer.h:79
Abstract windowing environment session.
Definition: session.h:32
virtual int run(int argc, char **argv)=0
#define MTS_NAMESPACE_END
Definition: platform.h:138