1 /*******************************************************************************
2 Copyright 2008 Ian Wadham <ianw2@optusnet.com.au>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *******************************************************************************/
24 #include <QMouseEvent>
28 #include "kbkglobal.h"
30 class Game
; // Forward declaration of Game class.
33 * Demonstrate the features of the Qt OpenGL
34 * view and OpenGL itself.
36 class GameGLView
: public QGLWidget
42 * Create a new GL view for the game
44 GameGLView (Game
* g
, QWidget
* parent
= 0);
47 * Dump all OpenGL and GLU extensions to stdout
49 void dumpExtensions ();
52 void moveGLView (float xChange
, float yChange
, float zChange
);
53 void rotateGLView (float degrees
, float x
, float y
, float z
);
56 void drawACubie (float size
, float centre
[], int axis
, int angle
);
58 void drawASticker (float size
, int color
, bool blinking
,
59 int faceNormal
[], float faceCentre
[]);
60 void setBlinkIntensity (float intensity
);
62 QPoint
getMousePosition ();
64 void setBevelAmount (int bevelPerCent
);
68 * Reimplemented to initialize the OpenGL context.
70 * This method is called automatically by Qt once.
72 virtual void initializeGL();
75 * Called by Qt when the size of the GL view changes.
77 virtual void resizeGL(int w
, int h
);
80 * This method actually renders the scene. It is called automatically by Qt
81 * when paint events occur. A manual repaint (for example for animations) can
82 * be made by calling updateGL which also calls this method.
84 * Do not call this method directly!
86 virtual void paintGL();
89 * Handle mouse events. In these implementations, game->handleMouseEvent
90 * is called with event type, button, X co-ordinate and Y co-ordinate in
91 * OpenGL convention (zero at bottom of window).
93 virtual void mousePressEvent (QMouseEvent
* e
);
94 virtual void mouseReleaseEvent (QMouseEvent
* e
);
97 * Check for an OpenGL error. Dump any error to stdout
98 * @return true, if an error occured, otherwise false
103 void turnOnLighting ();
106 float bevelAmount
; // Fraction of bevelling on a cubie (eg. 0.1).
107 QColor bgColor
; // Background color.
109 static float colors
[7] [3];
110 float blinkIntensity
;