]> Dogcows Code - chaz/yoink/blob - src/moof/video.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / video.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_VIDEO_HH_
11 #define _MOOF_VIDEO_HH_
12
13 #include <string>
14
15 #include <boost/shared_ptr.hpp>
16 #include <SDL/SDL.h>
17
18 #include <moof/backend.hh>
19 #include <moof/math.hh>
20 #include <moof/timer.hh>
21
22
23 /**
24 * \file video.hh
25 * Classes for managing a video context.
26 */
27
28 namespace moof {
29
30
31 // forward declarations
32 class settings;
33
34 class video;
35 typedef boost::shared_ptr<video> video_ptr;
36
37 class video
38 {
39 public:
40
41 struct attributes
42 {
43 int color_buffer[4]; // rgba
44 int frame_buffer;
45 bool is_double_buffer;
46 int depth_buffer;
47 int stencil_buffer;
48 int accumulator_buffer[4]; // rgba
49 bool is_stereo;
50 int multisamples;
51 bool is_swap_control;
52 bool is_hardware_only;
53 int mode[3]; // width, height, bpp
54 bool is_fullscreen;
55 bool is_resizable;
56 bool is_cursor_visible;
57 bool is_cursor_captured;
58
59 attributes();
60 attributes(const settings& settings);
61
62 private:
63
64 void init();
65
66 backend backend_;
67 };
68
69 static video_ptr alloc(const attributes& attribs)
70 {
71 return video_ptr(new video(attribs));
72 }
73
74 explicit video(const std::string& caption = "Moof!!");
75 explicit video(const class attributes& attribs);
76 explicit video(const std::string& caption,
77 const class attributes& attribs);
78 ~video();
79
80 class attributes attributes() const;
81
82 void mode(const int mode[3]);
83
84 void resize(int width, int height);
85 bool iconify();
86
87 void caption(const std::string& caption);
88 const std::string& caption() const;
89
90 void fullscreen(bool full);
91 bool fullscreen() const;
92 void toggle_fullscreen();
93
94 void resizable(bool is_resizable);
95 bool resizable() const;
96 void toggle_resizable();
97
98 void cursor_visible(bool is_cursor_visible);
99 bool cursor_visible() const;
100 void toggle_cursor_visible();
101
102 void cursor_captured(bool is_cursor_captured);
103 bool cursor_captured() const;
104 void toggle_cursor_captured();
105
106 /**
107 * Swap the video buffers if double-buffered.
108 */
109 void swap(scalar t = timer::ticks());
110
111 /**
112 * Make this video context the current context which will be effected
113 * by future draw commands.
114 */
115 void make_current() const;
116
117 /**
118 * Get the current video context where draw commands are sent.
119 */
120 static video& current()
121 {
122 return *current_;
123 }
124
125 /**
126 * Get whether or not a video context is in place and is ready to
127 * received drawing commands.
128 */
129 static bool ready()
130 {
131 return current_;
132 }
133
134 /**
135 * Get the width of the video display.
136 * \return The pixel width.
137 */
138 int width() const;
139
140 /**
141 * Get the height of the video display.
142 * \return The pixel height.
143 */
144 int height() const;
145
146 void show_fps(bool show)
147 {
148 show_fps_ = show;
149 fps_accumulator_ = SCALAR(0.0);
150 fps_counter_ = 0;
151 last_swap_ = SCALAR(0.0);
152 }
153
154 bool show_fps() const
155 {
156 return show_fps_;
157 }
158
159 private:
160
161 void init();
162
163 void recreate_context();
164 void set_opengl_attributes();
165
166 // TODO: this implementation is not well hidden
167
168 SDL_Surface* context_;
169 int flags_;
170 class attributes attributes_;
171 bool show_fps_;
172 std::string caption_;
173 scalar fps_accumulator_;
174 int fps_counter_;
175 scalar last_swap_;
176
177 static video* current_;
178 };
179
180
181 } // namespace moof
182
183 #endif // _MOOF_VIDEO_HH_
184
This page took 0.038094 seconds and 5 git commands to generate.