// ////////////////////////////////////////////////////////// // GLWindow.h // Copyright (c) 2004 Stephan Brumme. All rights reserved. // #ifndef _GLWINDOW_H_INCLUDED_ #define _GLWINDOW_H_INCLUDED_ // Windows-specific stuff #include /// Base class for an OpenGL window /** \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 **/ class GLWindow { public: /// Set up a new window GLWindow(bool fullscreen_, const char* title_, unsigned int width_, unsigned int height_, bool doublebuffer_ = true, unsigned char colorbuffer_ = 32, unsigned char depthbuffer_ = 32, unsigned char accumbuffer_ = 0); /// Destroy window ~GLWindow(); /// OVERRIDE: Initialize OpenGL virtual void init() = 0; /// Main loop int run(); /// Resize window virtual void resize(int width, int height); /// OVERRIDE: Redraw contents virtual void redraw() = 0; /// Free used stuff virtual void destroy() { } /// Toggle fullscreen/windowed void toggleFullscreen(); /// Toggle active/stopped void toggleActive(); /// Set active/stopped void setActive(bool newState); /// Paint window void paint(); /// Returns number of seconds the program was active float seconds() const; protected: /// Window's handle HWND hWnd; /// Device context HDC hDC; /// Resource context HGLRC hRC; /// Program ID HINSTANCE hInstance; /// Width of the viewport int width; /// Height of the viewport int height; /// True, if using double buffer technique bool doublebuffer; /// True, if fullscreen bool fullscreen; /// Bits of the color buffer (default: 32, RGBA) unsigned char colorbuffer; /// Bits of the depth buffer (default: 32) unsigned char depthbuffer; /// Bits of the accumulation buffer (default: 0) unsigned char accumbuffer; /// True, if window is active bool active; /// Window's caption const char* title; /// Drawn frames int frames; /// Time of initial window creation unsigned int timeStarted; /// Time spent in inactive mode unsigned int timeInactive; /// Time of last activity unsigned int inactiveSince; private: /// Ensure singleton pattern static GLWindow* singleton; /// Process message queue static LRESULT CALLBACK message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); enum { /// Hopefully unique ID FPS_TIMER_ID = 0x12345679, /// Update interval FPS_TIMER_INTERVAL = 1000 }; static unsigned int framesAtLastFPSUpdate; }; #endif // _GLWINDOW_H_INCLUDED_