1 // //////////////////////////////////////////////////////////
2 // GLWindow.h
3 // Copyright (c) 2004 Stephan Brumme. All rights reserved.
4 //
5
6 #ifndef _GLWINDOW_H_INCLUDED_
7 #define _GLWINDOW_H_INCLUDED_
8
9 // Windows-specific stuff
10 #include <windows.h>
11
12
13 /// Base class for an OpenGL window
14 /**
\class GLWindow
\author Stephan Brumme, games@stephan-brumme.com
\version 1.2: August 12, 2004
- Fixed window resize bug
\version 1.1: August 11, 2004
- Code cleanup
- added lots of comments
\version 1.0: August 9, 2004
- Initial release
**/
15 class GLWindow
16 {
17 public:
18 /// Set up a new window
19 GLWindow(bool fullscreen_, const char* title_,
20 unsigned int width_, unsigned int height_,
21 bool doublebuffer_ = true,
22 unsigned char colorbuffer_ = 32, unsigned char depthbuffer_ = 32,
23 unsigned char accumbuffer_ = 0);
24 /// Destroy window
25 ~GLWindow();
26
27
28 /// OVERRIDE: Initialize OpenGL
29 virtual void init() = 0;
30 /// Main loop
31 int run();
32 /// Resize window
33 virtual void resize(int width, int height);
34 /// OVERRIDE: Redraw contents
35 virtual void redraw() = 0;
36 /// Free used stuff
37 virtual void destroy() { }
38
39 /// Toggle fullscreen/windowed
40 void toggleFullscreen();
41 /// Toggle active/stopped
42 void toggleActive();
43 /// Set active/stopped
44 void setActive(bool newState);
45 /// Paint window
46 void paint();
47
48 /// Returns number of seconds the program was active
49 float seconds() const;
50
51
52 protected:
53 /// Window's handle
54 HWND hWnd;
55 /// Device context
56 HDC hDC;
57 /// Resource context
58 HGLRC hRC;
59 /// Program ID
60 HINSTANCE hInstance;
61
62 /// Width of the viewport
63 int width;
64 /// Height of the viewport
65 int height;
66 /// True, if using double buffer technique
67 bool doublebuffer;
68 /// True, if fullscreen
69 bool fullscreen;
70 /// Bits of the color buffer (default: 32, RGBA)
71 unsigned char colorbuffer;
72 /// Bits of the depth buffer (default: 32)
73 unsigned char depthbuffer;
74 /// Bits of the accumulation buffer (default: 0)
75 unsigned char accumbuffer;
76
77 /// True, if window is active
78 bool active;
79
80 /// Window's caption
81 const char* title;
82 /// Drawn frames
83 int frames;
84 /// Time of initial window creation
85 unsigned int timeStarted;
86 /// Time spent in inactive mode
87 unsigned int timeInactive;
88 /// Time of last activity
89 unsigned int inactiveSince;
90
91
92 private:
93 /// Ensure singleton pattern
94 static GLWindow* singleton;
95
96 /// Process message queue
97 static LRESULT CALLBACK message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
98
99 enum
100 {
101 /// Hopefully unique ID
102 FPS_TIMER_ID = 0x12345679,
103 /// Update interval
104 FPS_TIMER_INTERVAL = 1000
105 };
106
107 static unsigned int framesAtLastFPSUpdate;
108 };
109
110
111 #endif // _GLWINDOW_H_INCLUDED_
112