http://www.stephan-brumme.com

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Cubemania Documentation

© 2004 Stephan Brumme. All Rights Reserved.


Cubemania File List

Here is a list of all files with brief descriptions:
Cubemania.cpp [code]
GLWindow.cpp [code]
GLWindow.h [code]


Cubemania.cpp File Reference

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "GLWindow.h"

Include dependency graph for Cubemania.cpp:

Include dependency graph

Go to the source code of this file.

Classes

class | Cubemania
Draw 10x10x10 = 1,000 spinning cubes. More...

Functions

int __cdecl | main (int argc, char *argv[])

Function Documentation

int __cdecl main | ( | int | argc,
 |  | char * | argv[]
 | ) |

Definition at line 176 of file Cubemania.cpp.

References Cubemania::init(), and GLWindow::run().

Here is the call graph for this function:


GLWindow.cpp File Reference

#include "GLWindow.h"
#include <gl/gl.h>
#include <cstdio>
#include <cassert>

Include dependency graph for GLWindow.cpp:

Include dependency graph

Go to the source code of this file.


GLWindow.h File Reference

#include <windows.h>

Include dependency graph for GLWindow.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

class GLWindow
Base class for an OpenGL window. More...


Cubemania Class List

Here are the classes, structs, unions and interfaces with brief descriptions:
Cubemania | Draw 10x10x10 = 1,000 spinning cubes
GLWindow | Base class for an OpenGL window


Cubemania Class Reference

Inheritance diagram for Cubemania:

[legend]
List of all members.

Detailed Description

Draw 10x10x10 = 1,000 spinning cubes.

Author:
Stephan Brumme, games@stephan-brumme.com
Version:
1.1: August 11, 2004
  • Code cleanup
  • added lots of comments

1.0: August 9, 2004

  • Initial release

Definition at line 38 of file Cubemania.cpp.

Public Member Functions

Cubemania (const char *title, bool fullscreen, int width, int height)
Set up a new window, default depth of colorbuffer and depthbuffer.

virtual void | destroy ()
Free used stuff.

virtual void | init ()
override window initialization

void | paint ()
Paint window.

virtual void | redraw ()
draw a frame

virtual void | resize (int newWidth, int newHeight)
recompute viewport

int | run ()
Main loop.

float | seconds () const
Returns number of seconds the program was active.

void | setActive (bool newState)
Set active/stopped.

void | toggleActive ()
Toggle active/stopped.

void | toggleFullscreen ()
Toggle fullscreen/windowed.

Protected Attributes

unsigned char | accumbuffer
Bits of the accumulation buffer (default: 0).

bool | active
True, if window is active.

unsigned char | colorbuffer
Bits of the color buffer (default: 32, RGBA).

unsigned char | depthbuffer
Bits of the depth buffer (default: 32).

bool | doublebuffer
True, if using double buffer technique.

int | frames
Drawn frames.

bool | fullscreen
True, if fullscreen.

HDC | hDC
Device context.

int | height
Height of the viewport.

HINSTANCE | hInstance
Program ID.

HGLRC | hRC
Resource context.

HWND | hWnd
Window's handle.

unsigned int | inactiveSince
Time of last activity.

unsigned int | timeInactive
Time spent in inactive mode.

unsigned int | timeStarted
Time of initial window creation.

const char * | title
Window's caption.

int | width
Width of the viewport.

Constructor & Destructor Documentation

Cubemania | ( | const char * | title,
 |  | bool | fullscreen,
 |  | int | width,
 |  | int | height
 | ) | [inline]

Set up a new window, default depth of colorbuffer and depthbuffer.

Definition at line 42 of file Cubemania.cpp.

Member Function Documentation

virtual void destroy ( ) [inline, virtual, inherited]

Free used stuff.

Definition at line 47 of file GLWindow.h.

void init ( ) [virtual]

override window initialization

Called by the baseclass GLWindow during window construction

Implements GLWindow.

Definition at line 58 of file Cubemania.cpp.

References resize().

Referenced by main().

Here is the call graph for this function:

void paint ( ) [inherited]

Paint window.

Definition at line 306 of file GLWindow.cpp.

References GLWindow::doublebuffer, GLWindow::frames, GLWindow::hDC, and GLWindow::redraw().

Referenced by GLWindow::message(), and GLWindow::run().

Here is the call graph for this function:

void redraw ( ) [virtual]

draw a frame

Implements GLWindow.

Definition at line 106 of file Cubemania.cpp.

References GLWindow::seconds().

Here is the call graph for this function:

void resize | ( | int | newWidth,
 |  | int | newHeight
 | ) | [virtual]

recompute viewport

Called by the baseclass GLWindow during window construction

Reimplemented from GLWindow.

Definition at line 83 of file Cubemania.cpp.

References resize().

Referenced by init(), and resize().

Here is the call graph for this function:

int run ( ) [inherited]

Main loop.

Definition at line 175 of file GLWindow.cpp.

References GLWindow::active, and GLWindow::paint().

Referenced by main().

Here is the call graph for this function:

float seconds ( ) const [inherited]

Returns number of seconds the program was active.

Definition at line 319 of file GLWindow.cpp.

References GLWindow::active, GLWindow::inactiveSince, GLWindow::timeInactive, and GLWindow::timeStarted.

Referenced by redraw().

void setActive ( bool newState ) [inherited]

Set active/stopped.

Definition at line 285 of file GLWindow.cpp.

References GLWindow::active, GLWindow::inactiveSince, GLWindow::setActive(), and GLWindow::timeInactive.

Referenced by GLWindow::setActive(), and GLWindow::toggleActive().

Here is the call graph for this function:

void toggleActive ( ) [inherited]

Toggle active/stopped.

Definition at line 278 of file GLWindow.cpp.

References GLWindow::active, and GLWindow::setActive().

Referenced by GLWindow::message().

Here is the call graph for this function:

void toggleFullscreen ( ) [inherited]

Toggle fullscreen/windowed.

Definition at line 216 of file GLWindow.cpp.

References GLWindow::fullscreen, GLWindow::height, GLWindow::hWnd, and GLWindow::width.

Referenced by GLWindow::message().

Member Data Documentation

unsigned char accumbuffer [protected, inherited]

Bits of the accumulation buffer (default: 0).

Definition at line 85 of file GLWindow.h.

Referenced by GLWindow::GLWindow().

bool active [protected, inherited]

True, if window is active.

Definition at line 88 of file GLWindow.h.

Referenced by GLWindow::run(), GLWindow::seconds(), GLWindow::setActive(), and GLWindow::toggleActive().

unsigned char colorbuffer [protected, inherited]

Bits of the color buffer (default: 32, RGBA).

Definition at line 81 of file GLWindow.h.

Referenced by GLWindow::GLWindow().

unsigned char depthbuffer [protected, inherited]

Bits of the depth buffer (default: 32).

Definition at line 83 of file GLWindow.h.

Referenced by GLWindow::GLWindow().

bool doublebuffer [protected, inherited]

True, if using double buffer technique.

Definition at line 77 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), and GLWindow::paint().

int frames [protected, inherited]

Drawn frames.

Definition at line 93 of file GLWindow.h.

Referenced by GLWindow::message(), and GLWindow::paint().

bool fullscreen [protected, inherited]

True, if fullscreen.

Definition at line 79 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::toggleFullscreen(), and GLWindow::~GLWindow().

HDC hDC [protected, inherited]

Device context.

Definition at line 66 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::paint(), and GLWindow::~GLWindow().

int height [protected, inherited]

Height of the viewport.

Definition at line 75 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::resize(), and GLWindow::toggleFullscreen().

HINSTANCE hInstance [protected, inherited]

Program ID.

Definition at line 70 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), and GLWindow::~GLWindow().

HGLRC hRC [protected, inherited]

Resource context.

Definition at line 68 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), and GLWindow::~GLWindow().

HWND hWnd [protected, inherited]

Window's handle.

Definition at line 64 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::toggleFullscreen(), and GLWindow::~GLWindow().

unsigned int inactiveSince [protected, inherited]

Time of last activity.

Definition at line 99 of file GLWindow.h.

Referenced by GLWindow::seconds(), and GLWindow::setActive().

unsigned int timeInactive [protected, inherited]

Time spent in inactive mode.

Definition at line 97 of file GLWindow.h.

Referenced by GLWindow::seconds(), and GLWindow::setActive().

unsigned int timeStarted [protected, inherited]

Time of initial window creation.

Definition at line 95 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), and GLWindow::seconds().

const char* title [protected, inherited]

Window's caption.

Definition at line 91 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::message(), and GLWindow::~GLWindow().

int width [protected, inherited]

Width of the viewport.

Definition at line 73 of file GLWindow.h.

Referenced by GLWindow::GLWindow(), GLWindow::resize(), and GLWindow::toggleFullscreen().

The documentation for this class was generated from the following file:
  • Cubemania.cpp


GLWindow Class Reference

#include <GLWindow.h>

Inheritance diagram for GLWindow:

[legend]
List of all members.

Detailed Description

Base class for an OpenGL window.

Author:
Stephan Brumme, games@stephan-brumme.com
Version:
1.2: August 12, 2004
  • Fixed window resize bug

1.1: August 11, 2004

  • Code cleanup
  • added lots of comments

1.0: August 9, 2004

  • Initial release

Definition at line 25 of file GLWindow.h.

Public Member Functions

virtual void | destroy ()
Free used stuff.

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)
Set up a new window.

virtual void | init ()=0
OVERRIDE: Initialize OpenGL.

void | paint ()
Paint window.

virtual void | redraw ()=0
OVERRIDE: Redraw contents.

virtual void | resize (int width, int height)
Resize window.

int | run ()
Main loop.

float | seconds () const
Returns number of seconds the program was active.

void | setActive (bool newState)
Set active/stopped.

void | toggleActive ()
Toggle active/stopped.

void | toggleFullscreen ()
Toggle fullscreen/windowed.

~GLWindow ()
Destroy window.

Protected Attributes

unsigned char | accumbuffer
Bits of the accumulation buffer (default: 0).

bool | active
True, if window is active.

unsigned char | colorbuffer
Bits of the color buffer (default: 32, RGBA).

unsigned char | depthbuffer
Bits of the depth buffer (default: 32).

bool | doublebuffer
True, if using double buffer technique.

int | frames
Drawn frames.

bool | fullscreen
True, if fullscreen.

HDC | hDC
Device context.

int | height
Height of the viewport.

HINSTANCE | hInstance
Program ID.

HGLRC | hRC
Resource context.

HWND | hWnd
Window's handle.

unsigned int | inactiveSince
Time of last activity.

unsigned int | timeInactive
Time spent in inactive mode.

unsigned int | timeStarted
Time of initial window creation.

const char * | title
Window's caption.

int | width
Width of the viewport.

Private Types

enum | { FPS_TIMER_ID = 0x12345679, FPS_TIMER_INTERVAL = 1000 }

Static Private Member Functions

LRESULT CALLBACK | message (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Process message queue.

Static Private Attributes

unsigned int | framesAtLastFPSUpdate = 0
Number of frames drawn at last update.

GLWindow * | singleton = NULL
Ensure singleton pattern.

Member Enumeration Documentation

anonymous enum [private]

Enumeration values:
FPS_TIMER_ID | Hopefully unique ID.
FPS_TIMER_INTERVAL | Update interval.

Definition at line 109 of file GLWindow.h.

Constructor & Destructor Documentation

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
 | ) |

Set up a new window.

Definition at line 27 of file GLWindow.cpp.

References accumbuffer, colorbuffer, depthbuffer, doublebuffer, FPS_TIMER_ID, FPS_TIMER_INTERVAL, fullscreen, GLWindow(), hDC, height, hInstance, hRC, hWnd, message(), singleton, timeStarted, title, and width.

Referenced by GLWindow().

Here is the call graph for this function:

~GLWindow ( )

Destroy window.

Definition at line 151 of file GLWindow.cpp.

References FPS_TIMER_ID, fullscreen, hDC, hInstance, hRC, hWnd, and title.

Member Function Documentation

virtual void destroy ( ) [inline, virtual]

Free used stuff.

Definition at line 47 of file GLWindow.h.

virtual void init ( ) [pure virtual]

OVERRIDE: Initialize OpenGL.

Implemented in Cubemania.

LRESULT CALLBACK message | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) | [static, private]

Process message queue.

Definition at line 329 of file GLWindow.cpp.

References FPS_TIMER_ID, FPS_TIMER_INTERVAL, frames, framesAtLastFPSUpdate, message(), paint(), resize(), singleton, title, toggleActive(), and toggleFullscreen().

Referenced by GLWindow(), and message().

Here is the call graph for this function:

void paint ( )

Paint window.

Definition at line 306 of file GLWindow.cpp.

References doublebuffer, frames, hDC, and redraw().

Referenced by message(), and run().

Here is the call graph for this function:

virtual void redraw ( ) [pure virtual]

OVERRIDE: Redraw contents.

Implemented in Cubemania.

Referenced by paint().

void resize | ( | int | width,
 |  | int | height
 | ) | [virtual]

Resize window.

Reimplemented in Cubemania.

Definition at line 204 of file GLWindow.cpp.

References height, resize(), and width.

Referenced by message(), and resize().

Here is the call graph for this function:

int run ( )

Main loop.

Definition at line 175 of file GLWindow.cpp.

References active, and paint().

Referenced by main().

Here is the call graph for this function:

float seconds ( ) const

Returns number of seconds the program was active.

Definition at line 319 of file GLWindow.cpp.

References active, inactiveSince, timeInactive, and timeStarted.

Referenced by Cubemania::redraw().

void setActive ( bool newState )

Set active/stopped.

Definition at line 285 of file GLWindow.cpp.

References active, inactiveSince, setActive(), and timeInactive.

Referenced by setActive(), and toggleActive().

Here is the call graph for this function:

void toggleActive ( )

Toggle active/stopped.

Definition at line 278 of file GLWindow.cpp.

References active, and setActive().

Referenced by message().

Here is the call graph for this function:

void toggleFullscreen ( )

Toggle fullscreen/windowed.

Definition at line 216 of file GLWindow.cpp.

References fullscreen, height, hWnd, and width.

Referenced by message().

Member Data Documentation

unsigned char accumbuffer [protected]

Bits of the accumulation buffer (default: 0).

Definition at line 85 of file GLWindow.h.

Referenced by GLWindow().

bool active [protected]

True, if window is active.

Definition at line 88 of file GLWindow.h.

Referenced by run(), seconds(), setActive(), and toggleActive().

unsigned char colorbuffer [protected]

Bits of the color buffer (default: 32, RGBA).

Definition at line 81 of file GLWindow.h.

Referenced by GLWindow().

unsigned char depthbuffer [protected]

Bits of the depth buffer (default: 32).

Definition at line 83 of file GLWindow.h.

Referenced by GLWindow().

bool doublebuffer [protected]

True, if using double buffer technique.

Definition at line 77 of file GLWindow.h.

Referenced by GLWindow(), and paint().

int frames [protected]

Drawn frames.

Definition at line 93 of file GLWindow.h.

Referenced by message(), and paint().

unsigned int framesAtLastFPSUpdate = 0 [static, private]

Number of frames drawn at last update.

Used to compute the number of frames drawn in the last interval: it's just (frames-framesAtLastFPSUpdate) *

Definition at line 22 of file GLWindow.cpp.

Referenced by message().

bool fullscreen [protected]

True, if fullscreen.

Definition at line 79 of file GLWindow.h.

Referenced by GLWindow(), toggleFullscreen(), and ~GLWindow().

HDC hDC [protected]

Device context.

Definition at line 66 of file GLWindow.h.

Referenced by GLWindow(), paint(), and ~GLWindow().

int height [protected]

Height of the viewport.

Definition at line 75 of file GLWindow.h.

Referenced by GLWindow(), resize(), and toggleFullscreen().

HINSTANCE hInstance [protected]

Program ID.

Definition at line 70 of file GLWindow.h.

Referenced by GLWindow(), and ~GLWindow().

HGLRC hRC [protected]

Resource context.

Definition at line 68 of file GLWindow.h.

Referenced by GLWindow(), and ~GLWindow().

HWND hWnd [protected]

Window's handle.

Definition at line 64 of file GLWindow.h.

Referenced by GLWindow(), toggleFullscreen(), and ~GLWindow().

unsigned int inactiveSince [protected]

Time of last activity.

Definition at line 99 of file GLWindow.h.

Referenced by seconds(), and setActive().

GLWindow * singleton = NULL [static, private]

Ensure singleton pattern.

Definition at line 18 of file GLWindow.cpp.

Referenced by GLWindow(), and message().

unsigned int timeInactive [protected]

Time spent in inactive mode.

Definition at line 97 of file GLWindow.h.

Referenced by seconds(), and setActive().

unsigned int timeStarted [protected]

Time of initial window creation.

Definition at line 95 of file GLWindow.h.

Referenced by GLWindow(), and seconds().

const char* title [protected]

Window's caption.

Definition at line 91 of file GLWindow.h.

Referenced by GLWindow(), message(), and ~GLWindow().

int width [protected]

Width of the viewport.

Definition at line 73 of file GLWindow.h.

Referenced by GLWindow(), resize(), and toggleFullscreen().

The documentation for this class was generated from the following files:
  • GLWindow.h
  • GLWindow.cpp


Cubemania Class Hierarchy

Go to the graphical class hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically:

  • GLWindow
    • Cubemania


Here is a list of all class members with links to the classes they belong to:

- a -

  • accumbuffer : GLWindow
  • active : GLWindow

- c -

  • colorbuffer : GLWindow
  • Cubemania() : Cubemania

- d -

  • depthbuffer : GLWindow
  • destroy() : GLWindow
  • doublebuffer : GLWindow

- f -

  • FPS_TIMER_ID : GLWindow
  • FPS_TIMER_INTERVAL : GLWindow
  • frames : GLWindow
  • framesAtLastFPSUpdate : GLWindow
  • fullscreen : GLWindow

- g -

  • GLWindow() : GLWindow

- h -

  • hDC : GLWindow
  • height : GLWindow
  • hInstance : GLWindow
  • hRC : GLWindow
  • hWnd : GLWindow

- i -

  • inactiveSince : GLWindow
  • init() : GLWindow, Cubemania

- m -

  • message() : GLWindow

- p -

  • paint() : GLWindow

- r -

  • redraw() : GLWindow, Cubemania
  • resize() : GLWindow, Cubemania
  • run() : GLWindow

- s -

  • seconds() : GLWindow
  • setActive() : GLWindow
  • singleton : GLWindow

- t -

  • timeInactive : GLWindow
  • timeStarted : GLWindow
  • title : GLWindow
  • toggleActive() : GLWindow
  • toggleFullscreen() : GLWindow

- w -

  • width : GLWindow

- ~ -

  • ~GLWindow() : GLWindow


Here is a list of all file members with links to the files they belong to:

  • main() : Cubemania.cpp


Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Cubemania Graphical Class Hierarchy

Go to the textual class hierarchy


Cubemania Member List

This is the complete list of members for Cubemania, including all inherited members.

accumbuffer | GLWindow | [protected]
active | GLWindow | [protected]
colorbuffer | GLWindow | [protected]
Cubemania(const char *title, bool fullscreen, int width, int height) | Cubemania | [inline]
depthbuffer | GLWindow | [protected]
destroy() | GLWindow | [inline, virtual]
doublebuffer | GLWindow | [protected]
frames | GLWindow | [protected]
fullscreen | GLWindow | [protected]
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) | GLWindow
hDC | GLWindow | [protected]
height | GLWindow | [protected]
hInstance | GLWindow | [protected]
hRC | GLWindow | [protected]
hWnd | GLWindow | [protected]
inactiveSince | GLWindow | [protected]
init() | Cubemania | [virtual]
paint() GLWindow
redraw() | Cubemania | [virtual]
resize(int newWidth, int newHeight) | Cubemania | [virtual]
run() GLWindow
seconds() const | GLWindow
setActive(bool newState) | GLWindow
timeInactive | GLWindow | [protected]
timeStarted | GLWindow | [protected]
title | GLWindow | [protected]
toggleActive() GLWindow
toggleFullscreen() GLWindow
width | GLWindow | [protected]


Cubemania Class Index

C | G

C
Cubemania
G
GLWindow


GLWindow Member List

This is the complete list of members for GLWindow, including all inherited members.

accumbuffer | GLWindow | [protected]
active | GLWindow | [protected]
colorbuffer | GLWindow | [protected]
depthbuffer | GLWindow | [protected]
destroy() | GLWindow | [inline, virtual]
doublebuffer | GLWindow | [protected]
FPS_TIMER_ID enum value | GLWindow | [private]
FPS_TIMER_INTERVAL enum value | GLWindow | [private]
frames | GLWindow | [protected]
framesAtLastFPSUpdate | GLWindow | [private, static]
fullscreen | GLWindow | [protected]
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) | GLWindow
hDC | GLWindow | [protected]
height | GLWindow | [protected]
hInstance | GLWindow | [protected]
hRC | GLWindow | [protected]
hWnd | GLWindow | [protected]
inactiveSince | GLWindow | [protected]
init()=0 | GLWindow | [pure virtual]
message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | GLWindow | [private, static]
paint() GLWindow
redraw()=0 | GLWindow | [pure virtual]
resize(int width, int height) | GLWindow | [virtual]
run() GLWindow
seconds() const | GLWindow
setActive(bool newState) | GLWindow
singleton | GLWindow | [private, static]
timeInactive | GLWindow | [protected]
timeStarted | GLWindow | [protected]
title | GLWindow | [protected]
toggleActive() GLWindow
toggleFullscreen() GLWindow
width | GLWindow | [protected]


Cubemania.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////
00002 // Cubemania.cpp
00003 // Copyright (c) 2004 Stephan Brumme. All rights reserved.
00004 //
00005
00006 // just can't live without Windows ...
00007 #include <windows.h>
00008 // ... and OpenGL !
00009 #include <gl/gl.h>
00010 #include <gl/glu.h>
00011
00012 // my OpenGL window wrapper
00013 #include "GLWindow.h"
00014
00015
00016 /* of course the following 4 settings can be done in the project settings
00017    but I like to use #pragmas since I always keep on forgetting to set them
00018    in the Visual Studio project settings. I am getting older. */
00019 // target Windows
00020 #pragma comment (linker, "/SUBSYSTEM:WINDOWS")
00021 #pragma comment (linker, "/ENTRY:mainCRTStartup")
00022 // link required libraries
00023 #pragma comment(lib, "opengl32.lib")
00024 #pragma comment(lib, "glu32.lib")
00025
00026
00027
00029
00038 class Cubemania : public GLWindow
00039 {
00040 public:
00042     Cubemania(const char* title, bool fullscreen, int width, int height)
00043         : GLWindow(fullscreen, title, width, height) {}
00044
00046     virtual void init();
00048     virtual void redraw();
00050     virtual void resize(int newWidth, int newHeight);
00051 };
00052
00053
00054
00056
00058 void Cubemania::init()
00059 {
00060     // Gouraud shading
00061     glShadeModel(GL_SMOOTH);
00062     // black background
00063     glClearColor(0,0,0, 1);
00064
00065     // z-buffer
00066     glEnable(GL_DEPTH_TEST);
00067     glDepthFunc(GL_LEQUAL);
00068
00069     // recommended by NeHe but I can't tell a difference ...
00070     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00071
00072     // backface culling, it's a bit faster
00073     glEnable(GL_CULL_FACE);
00074
00075     // initial window size
00076     resize(width, height);
00077 }
00078
00079
00081
00083 void Cubemania::resize(int newWidth, int newHeight)
00084 {
00085     // prepare resize
00086     GLWindow::resize(newWidth, newHeight);
00087
00088     // perspective view
00089     glMatrixMode(GL_PROJECTION);
00090     glLoadIdentity();
00091     gluPerspective(60,  // field-of-view
00092                    newWidth/(float)newHeight, // aspect-ratio
00093                    1,   // front-z-plane
00094                    -1); // back-z-plane
00095
00096     // set camera
00097     glMatrixMode(GL_MODELVIEW);
00098     glLoadIdentity();
00099     gluLookAt(0, 0, 2,  // from (0,0,2)
00100               0, 0, 0,  // to (0,0,0)
00101               0, 1, 0); // up
00102 }
00103
00104
00106 void Cubemania::redraw()
00107 {
00108     // clear color and depth buffer
00109     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00110
00111     // safe current model-view matrix
00112     glPushMatrix();
00113
00114     // slow rotation depending on timestamp
00115     glRotatef(seconds() * 30, 0, 1, 1);
00116
00117     // all 8 vertices of a cube organised as [x1,y1,z1], [x2,y2,yz], ...
00118     static GLfloat vertices[] = { 0,0,0,
00119                                   0,0,1,
00120                                   0,1,0,
00121                                   0,1,1,
00122                                   1,0,0,
00123                                   1,0,1,
00124                                   1,1,0,
00125                                   1,1,1 };
00126
00127     // 6 sides refering to the vertices defined above
00128     static GLubyte indices[] = { 0,2,3,1,
00129                                  4,5,7,6,
00130                                  0,1,5,4,
00131                                  2,6,7,3,
00132                                  0,4,6,2,
00133                                  1,3,7,5 };
00134
00135     // initiate vertex array
00136     glEnableClientState(GL_VERTEX_ARRAY);
00137     // 3 dimensions (x,y,z), data type float, densely packed
00138     glVertexPointer(3, GL_FLOAT, 0, vertices);
00139
00140     // translate cubes from [0,1]^3 to [-.5,+.5]^3
00141     glTranslatef(-0.5f, -0.5f, -0.5f);
00142
00143     // number and size of cubes ... just modify to get even more cubes !
00144     const int   cubes    = 10;
00145     const float gridsize = 1.0f / cubes;
00146     const float length   = 0.3f * gridsize;
00147
00148     // generate all these funky cubes ...
00149     for (float x = 0; x < 1; x += gridsize)
00150         for (float y = 0; y < 1; y += gridsize)
00151             for (float z = 0; z < 1; z += gridsize)
00152             {
00153                 // save current model-view matrix
00154                 glPushMatrix();
00155
00156                 // color is derived from position
00157                 glColor3f(x,y,z);
00158                 // place cube
00159                 glTranslatef(x,y,z);
00160                 glScalef(length,length,length);
00161                 // and draw it
00162                 glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices);
00163
00164                 // restore model-view matrix
00165                 glPopMatrix();
00166             }
00167
00168     // finished drawing
00169     glDisableClientState(GL_VERTEX_ARRAY);
00170     glPopMatrix();
00171 }
00172
00173
00174
00175 // here we go ;-)
00176 int __cdecl main(int argc, char *argv[])
00177 {
00178     // windowed mode, 512x512 pixels
00179     Cubemania opengl("Stephan's Cubemania", false, 512, 512);
00180     opengl.init();
00181     return opengl.run();
00182 }
00183
00184
00185 #ifdef _VERY_SMALL_EXE_
00186 /* JUST DELETE THE FIRST 2 #PRAGMAS SINCE THEY ARE ONLY USEFUL TO PRODUCE
00187    A VERY SMALL EXECUTABLE (6K WITH VS.NET 2003) AND ARE CONSIDERED
00188    VERRRRRY DIRRRRRTY CODING STYLE !!!
00189    Linking against a VC6 lib in VS.NET 2003 (first #pragma) may lead to
00190    INSECURE, INSTABLE and CRASHING programs. But they are smaller ;-)
00191
00192    Btw, if you compile on VS.NET 2003 and use the default system libraries
00193    (=> you removed the #pragmas) make sure to find MSVCR71.DLL on the
00194    target system. For VS7 this DLL is called somehow similar.
00195    These DLLs come usually with the Windows Service Packs but are not guaranteed
00196    to be installed on every system since they were not part of the original
00197    plain-vanilla Windows 98/XP+. On the other hand, VC6's MSVCRT.DLL always exists
00198    on any Windows 98/XP+ based computer.
00199    */
00200 #pragma comment(lib, "msvcrt_vc6.lib")
00201 #pragma comment(linker, "/NODEFAULTLIB:libc.lib")
00202 #pragma comment(exestr, "(C) http://www.stephan-brumme.com, " __DATE__ " @" __TIME__)
#endif


  • FPS_TIMER_ID : GLWindow
  • FPS_TIMER_INTERVAL : GLWindow


  • Cubemania() : Cubemania
  • destroy() : GLWindow
  • GLWindow() : GLWindow
  • init() : GLWindow, Cubemania
  • message() : GLWindow
  • paint() : GLWindow
  • redraw() : GLWindow, Cubemania
  • resize() : GLWindow, Cubemania
  • run() : GLWindow
  • seconds() : GLWindow
  • setActive() : GLWindow
  • toggleActive() : GLWindow
  • toggleFullscreen() : GLWindow
  • ~GLWindow() : GLWindow


  • accumbuffer : GLWindow
  • active : GLWindow
  • colorbuffer : GLWindow
  • depthbuffer : GLWindow
  • doublebuffer : GLWindow
  • frames : GLWindow
  • framesAtLastFPSUpdate : GLWindow
  • fullscreen : GLWindow
  • hDC : GLWindow
  • height : GLWindow
  • hInstance : GLWindow
  • hRC : GLWindow
  • hWnd : GLWindow
  • inactiveSince : GLWindow
  • singleton : GLWindow
  • timeInactive : GLWindow
  • timeStarted : GLWindow
  • title : GLWindow
  • width : GLWindow


  • main() : Cubemania.cpp


GLWindow.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////
00002 // GLWindow.cpp
00003 // Copyright (c) 2004 Stephan Brumme. All rights reserved.
00004 //
00005
00006 #include "GLWindow.h"
00007
00008 // ... and OpenGL itself !
00009 #include <gl/gl.h>
00010 // basic string processing
00011 #include <cstdio>
00012 // debugging
00013 #include <cassert>
00014
00015
00016 //  Static variables
00018 GLWindow* GLWindow::singleton = NULL;
00020
00022 unsigned int GLWindow::framesAtLastFPSUpdate = 0;
00023
00024
00025
00027 GLWindow::GLWindow(bool fullscreen_, const char* title_,
00028                    unsigned int width_, unsigned int height_,
00029                    bool doublebuffer_,
00030                    unsigned char colorbuffer_, unsigned char depthbuffer_,
00031                    unsigned char accumbuffer_)
00032     : fullscreen(fullscreen_),
00033       title(title_),
00034       width(width_), height(height_),
00035
00036       doublebuffer(doublebuffer_),
00037       accumbuffer(accumbuffer_),
00038       colorbuffer(colorbuffer_),
00039       depthbuffer(depthbuffer_),
00040
00041       active(true), timeInactive(0),
00042       frames(0)
00043 {
00044     // singleton pattern
00045     assert(singleton == NULL);
00046     singleton = this;
00047
00048     // create window
00049     hInstance = GetModuleHandle(NULL);
00050
00051     // register window class
00052     WNDCLASSEX window;
00053     window.cbSize        = sizeof(WNDCLASSEX);
00054     window.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
00055     window.lpfnWndProc   = message;
00056     window.cbClsExtra    = 0;
00057     window.cbWndExtra    = 0;
00058     window.hInstance     = hInstance;
00059     window.hIcon         =
00060     window.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
00061     window.hCursor       = LoadCursor(NULL, IDC_ARROW);
00062     window.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
00063     window.lpszMenuName  = NULL;
00064     window.lpszClassName = title;
00065
00066     // register my window
00067     bool registerClass = RegisterClassEx(&window) != 0;
00068     assert(registerClass);
00069
00070     // window style depends whether window is in fullscreen of windowed
00071     DWORD dwStyle   = WS_OVERLAPPEDWINDOW;
00072     DWORD dwExStyle = WS_EX_APPWINDOW;
00073     if (fullscreen)
00074     {
00075         dwStyle   = WS_POPUP | WS_MAXIMIZE;
00076         dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
00077     }
00078
00079     // ensure window size
00080     RECT size;
00081     size.left   = 0;
00082     size.top    = 0;
00083     size.right  = width;
00084     size.bottom = height;
00085     AdjustWindowRectEx(&size, dwStyle, FALSE, dwExStyle);
00086
00087     // create main window
00088     hWnd = CreateWindowEx(dwExStyle,
00089                           title, title,
00090                           dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00091                           256,128,
00092                           size.right-size.left,
00093                           size.bottom-size.top,
00094                           NULL, NULL, hInstance, NULL);
00095     assert(hWnd);
00096
00097
00098     // get the device context
00099     hDC = GetDC(hWnd);
00100     assert(hDC);
00101
00102     // set pixel format
00103     PIXELFORMATDESCRIPTOR pfd;
00104     ZeroMemory(&pfd, sizeof(pfd));
00105     pfd.nSize      = sizeof(pfd);
00106     pfd.nVersion   = 1;
00107     pfd.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | (doublebuffer ? PFD_DOUBLEBUFFER : 0);
00108     pfd.iPixelType = PFD_TYPE_RGBA;
00109     pfd.cColorBits = colorbuffer;
00110     pfd.cDepthBits = depthbuffer;
00111     pfd.cAccumBits = accumbuffer;
00112     pfd.iLayerType = PFD_MAIN_PLANE;
00113
00114     // set buffers' depths
00115     int format = ChoosePixelFormat(hDC, &pfd);
00116     assert(format > 0);
00117     bool setPixelFormat = SetPixelFormat(hDC, format, &pfd) != 0;
00118     assert(setPixelFormat);
00119
00120     // create and enable the render context
00121     hRC = wglCreateContext(hDC);
00122     assert(hRC);
00123     wglMakeCurrent(hDC, hRC);
00124
00125     // start timer
00126     SetTimer(hWnd, FPS_TIMER_ID, FPS_TIMER_INTERVAL, 0);
00127
00128     // disable mouse cursor in fullscreen mode
00129     if (fullscreen)
00130         ShowCursor(FALSE);
00131
00132     // show window
00133     AnimateWindow(hWnd, 200, AW_BLEND | AW_ACTIVATE);
00134     SetForegroundWindow(hWnd);
00135     SetFocus(hWnd);
00136
00137     // switch off vsync if possible
00138     typedef GLboolean (__stdcall * SwapProc) (GLint interval);
00139     SwapProc wglSwapIntervalEXT =
00140         (SwapProc) wglGetProcAddress("wglSwapIntervalEXT");
00141     if (wglSwapIntervalEXT)
00142         wglSwapIntervalEXT(0);
00143
00144
00145     // ensure proper timing
00146     timeStarted = GetTickCount();
00147 }
00148
00149
00151 GLWindow::~GLWindow()
00152 {
00153     // yeah, it's time to say good-bye ...
00154
00155     // delete timer
00156     KillTimer(hWnd, FPS_TIMER_ID);
00157
00158     // free device context
00159     wglMakeCurrent(NULL, NULL);
00160     wglDeleteContext(hRC);
00161     ReleaseDC(hWnd, hDC);
00162
00163     // show cursor
00164     if (fullscreen)
00165         ShowCursor(TRUE);
00166
00167     // properly remove window from screen
00168     AnimateWindow(hWnd, 500, AW_BLEND | AW_HIDE);
00169     DestroyWindow(hWnd);
00170     UnregisterClass(title, hInstance);
00171 }
00172
00173
00175 int GLWindow::run()
00176 {
00177     // run forever :-)
00178     while (true)
00179     {
00180         MSG msg;
00181         // quit ?
00182         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
00183         {
00184             // window closed, the only way of escaping the "run" method
00185             if (msg.message == WM_QUIT)
00186                 return (int)msg.wParam;
00187
00188             // keep message pipeline alive
00189             TranslateMessage(&msg);
00190             DispatchMessage(&msg);
00191         }
00192
00193         // redraw window
00194         if (active)
00195             paint();
00196         else
00197             // idle, so don't waste CPU time
00198             WaitMessage();
00199     }
00200 }
00201
00202
00204 void GLWindow::resize(int newWidth, int newHeight)
00205 {
00206     // store new window size
00207     width  = newWidth;
00208     height = newHeight;
00209
00210     // adjust OpenGL view
00211     glViewport(0, 0, width, height);
00212 }
00213
00214
00216 void GLWindow::toggleFullscreen()
00217 {
00218     // default windowed size if programs starts in fullscreen mode
00219     static int windowedWidth  = 512;
00220     static int windowedHeight = 512;
00221
00222
00223     if (fullscreen)
00224     {
00225         // switch from fullscreen to windowed mode
00226
00227         // set new window styles
00228         SetWindowLong(hWnd, GWL_STYLE,   WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
00229         SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW);
00230
00231         // from maximized to normal mode
00232         ShowWindow(hWnd, SW_RESTORE);
00233         UpdateWindow(hWnd);
00234
00235         // ensure window size
00236         width  = windowedWidth;
00237         height = windowedHeight;
00238
00239         RECT size;
00240         size.left   = 0;
00241         size.top    = 0;
00242         size.right  = width;
00243         size.bottom = height;
00244         AdjustWindowRectEx(&size, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, FALSE, WS_EX_APPWINDOW);
00245
00246         // restore old window size
00247         SetWindowPos(hWnd, HWND_TOP, 256,128,
00248                      size.right-size.left,
00249                      size.bottom-size.top,
00250                      SWP_SHOWWINDOW);
00251
00252         // show mouse cursor
00253         ShowCursor(TRUE);
00254     }
00255     else
00256     {
00257         // switch from windowed mode to fullscreen
00258         windowedWidth  = width;
00259         windowedHeight = height;
00260
00261         // set new window styles
00262         SetWindowLong(hWnd, GWL_STYLE,   WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
00263         SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
00264
00265         // show window maximized
00266         ShowWindow(hWnd, SW_SHOWMAXIMIZED);
00267         UpdateWindow(hWnd);
00268
00269         // hide mouse cursor
00270         ShowCursor(FALSE);
00271     }
00272
00273     fullscreen = !fullscreen;
00274 }
00275
00276
00278 void GLWindow::toggleActive()
00279 {
00280     setActive(!active);
00281 }
00282
00283
00285 void GLWindow::setActive(bool newState)
00286 {
00287     // same state ?
00288     if (active == newState)
00289         // do nothing ...
00290         return;
00291
00292
00293     // well, the state changed indeed
00294     active = newState;
00295
00296     if (!active)
00297         // entering inactive mode
00298         inactiveSince = GetTickCount();
00299     else
00300         // going back to active mode, compute time spent being inactive
00301         timeInactive += GetTickCount() - inactiveSince;
00302 }
00303
00304
00306 void GLWindow::paint()
00307 {
00308     // redraw window contents
00309     redraw();
00310     // frame counter
00311     frames++;
00312     // double-buffering: switch front and back buffer
00313     if (doublebuffer)
00314         SwapBuffers(hDC);
00315 }
00316
00317
00319 float GLWindow::seconds() const
00320 {
00321     if (active)
00322         return (GetTickCount() - (timeStarted + timeInactive)) / 1000.0f;
00323     else
00324         return (inactiveSince - (timeStarted + timeInactive)) / 1000.0f;
00325 }
00326
00327
00329 LRESULT CALLBACK GLWindow::message(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
00330 {
00331     switch (uMsg)
00332     {
00333         case WM_SYSCOMMAND:
00334         {
00335             switch (wParam)
00336             {
00337                 // disable screensavers or monitor standby
00338                 // idea taken from http://nehe.gamedev.net
00339                 case SC_SCREENSAVE:
00340                 case SC_MONITORPOWER:
00341                 return 0;
00342             }
00343             break;
00344         }
00345
00346         // restart/pause execution
00347         //case WM_ACTIVATE:
00348         //{
00349         //    singleton->setActive(!HIWORD(wParam));
00350         //    return 0;
00351         //}
00352
00353         case WM_KEYDOWN:
00354         {
00355             switch (wParam)
00356             {
00357             // quit
00358             case VK_ESCAPE:
00359                 PostMessage(hWnd, WM_CLOSE, 0, 0);
00360                 return 0;
00361
00362             // toggle fullscreen/windowed
00363             case VK_F5:
00364                 singleton->toggleFullscreen();
00365                 return 0;
00366
00367             // pause execution
00368             case VK_PAUSE:
00369             case VK_SPACE:
00370                 singleton->toggleActive();
00371                 return 0;
00372             }
00373
00374             break;
00375         }
00376
00377         // quit
00378         case WM_CLOSE:
00379         {
00380             PostQuitMessage(0);
00381             return 0;
00382         }
00383
00384         // redraw window
00385         case WM_PAINT:
00386         {
00387             singleton->paint();
00388
00389             // required to avoid artefacts
00390             static PAINTSTRUCT ps;
00391             BeginPaint(hWnd, &ps);
00392             EndPaint(hWnd, &ps);
00393             break;
00394         }
00395
00396         // resize
00397         case WM_SIZE:
00398         {
00399             singleton->resize(LOWORD(lParam), HIWORD(lParam));
00400             PostMessage(hWnd, WM_PAINT, 0, 0);
00401             return 0;
00402         }
00403
00404         // timer
00405         case WM_TIMER:
00406             // framerate timer
00407             if(wParam == FPS_TIMER_ID)
00408             {
00409                 // compute current framerate
00410                 float fps = (singleton->frames - framesAtLastFPSUpdate)
00411                             * (1000.0f / FPS_TIMER_INTERVAL);
00412                 framesAtLastFPSUpdate = singleton->frames;
00413
00414                 // update caption bar
00415                 static char newCaption[257];
00416                 sprintf(newCaption, "%s (%.0f fps)", singleton->title, fps);
00417                 SetWindowText(hWnd, newCaption);
00418
00419                 return 0;
00420             }
00421             break;
00422     }
00423
00424     // default handler
00425     return DefWindowProc(hWnd, uMsg, wParam, lParam);
00426 }


GLWindow.h

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////
00002 // GLWindow.h
00003 // Copyright (c) 2004 Stephan Brumme. All rights reserved.
00004 //
00005
00006 #ifndef _GLWINDOW_H_INCLUDED_
00007 #define _GLWINDOW_H_INCLUDED_
00008
00009 // Windows-specific stuff
00010 #include <windows.h>
00011
00012
00014
00025 class GLWindow
00026 {
00027 public:
00029     GLWindow(bool fullscreen_, const char* title_,
00030              unsigned int width_, unsigned int height_,
00031              bool doublebuffer_ = true,
00032              unsigned char colorbuffer_ = 32, unsigned char depthbuffer_ = 32,
00033              unsigned char accumbuffer_ = 0);
00035     ~GLWindow();
00036
00037
00039     virtual void init() = 0;
00041     int run();
00043     virtual void resize(int width, int height);
00045     virtual void redraw() = 0;
00047     virtual void destroy() { }
00048
00050     void toggleFullscreen();
00052     void toggleActive();
00054     void setActive(bool newState);
00056     void paint();
00057
00059     float seconds() const;
00060
00061
00062 protected:
00064     HWND  hWnd;
00066     HDC   hDC;
00068     HGLRC hRC;
00070     HINSTANCE hInstance;
00071
00073     int width;
00075     int height;
00077     bool doublebuffer;
00079     bool fullscreen;
00081     unsigned char colorbuffer;
00083     unsigned char depthbuffer;
00085     unsigned char accumbuffer;
00086
00088     bool active;
00089
00091     const char* title;
00093     int frames;
00095     unsigned int timeStarted;
00097     unsigned int timeInactive;
00099     unsigned int inactiveSince;
00100
00101
00102 private:
00104     static GLWindow* singleton;
00105
00107     static LRESULT CALLBACK message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00108
00109     enum
00110     {
00112         FPS_TIMER_ID       = 0x12345679,
00114         FPS_TIMER_INTERVAL = 1000
00115     };
00116
00117     static unsigned int framesAtLastFPSUpdate;
00118 };
00119
00120
00121 #endif // _GLWINDOW_H_INCLUDED_


Graph Legend

This page explains how to interpret the graphs that are generated by doxygen.

Consider the following example:

/*! Invisible class because of truncation */
class Invisible { };

/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };

/* Class not documented with doxygen comments */
class Undocumented { };

/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };

/*! A template class */
template<class T> class Templ { };

/*! Class that is inherited using protected inheritance */
class ProtectedBase { };

/*! Class that is inherited using private inheritance */
class PrivateBase { };

/*! Class that is used by the Inherited class */
class Used { };

/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
                  protected ProtectedBase,
                  private PrivateBase,
                  public Undocumented
                  public Templ<int>
{
  private:
    Used *m_usedClass;
};
If the MAX_DOT_GRAPH_HEIGHT tag in the configuration file is set to 240 this will result in the following graph:<p>

The boxes in the above graph have the following meaning:

  • A filled black box represents the struct or class for which the graph is generated.
  • A box with a black border denotes a documented struct or class.
  • A box with a grey border denotes an undocumented struct or class.
  • A box with a red border denotes a documented struct or class forwhich not all inheritance/containment relations are shown. A graph is truncated if it does not fit within the specified boundaries.
The arrows have the following meaning:
  • A dark blue arrow is used to visualize a public inheritance relation between two classes.
  • A dark green arrow is used for protected inheritance.
  • A dark red arrow is used for private inheritance.
  • A purple dashed arrow is used if a class is contained or used by another class. The arrow is labeled with the variable(s) through which the pointed class or struct is accessible.
  • A yellow dashed arrow denotes a relation between a template instance and the template class it was instantiated from. The arrow is labeled with the template parameters of the instance.