sources:
Cubemania.cpp (6.2k)
GLWindow.cpp (11.0k)
GLWindow.h (3.1k)


binaries:
Release/Cubemania.exe (7.0k)
Release/CubemaniaStephan.exe (6.5k)
Release/CubemaniaUPX.exe (4.5k)


website:
more info here


screenshot:
studies/game programming/Games-Code1/GLWindow.h
download file

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