diff options
author | Benjamin Cohen <bencoh@notk.org> | 2011-11-29 21:46:22 +0100 |
---|---|---|
committer | Benjamin Cohen <bencoh@notk.org> | 2011-11-29 21:46:22 +0100 |
commit | eec305c93536dabd30a1c38cd6270c2bdc8a5e98 (patch) | |
tree | 2bca9294de36fcbeeded9a7a3d84c05837289d40 | |
parent | 70955a55db7616b77fca0f2acdc3454fb08e71a2 (diff) |
- Add drawString method
- Display "PAUSE" when pausing game
-rw-r--r-- | Game.cpp | 4 | ||||
-rw-r--r-- | Game.h | 1 | ||||
-rw-r--r-- | MainWindow.cpp | 31 | ||||
-rw-r--r-- | MainWindow.h | 16 |
4 files changed, 43 insertions, 9 deletions
@@ -96,6 +96,10 @@ void Game::toggleGame() { m_gameRunning = ! m_gameRunning;
}
+bool Game::isRunning() {
+ return m_gameRunning;
+}
+
// main function to be called within glut loop
void Game::updateGame(uint timeElapsedMs) {
if (m_gameRunning) {
@@ -20,6 +20,7 @@ public: void pauseGame();
void resumeGame();
void toggleGame();
+ bool isRunning();
/**
* This function is to be called by the MainWindow at each Main loop iteration.
**/
diff --git a/MainWindow.cpp b/MainWindow.cpp index 13d96a0..f336bc4 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1,17 +1,8 @@ #include "MainWindow.h" #include "types.h" - #include <iostream> -#ifdef APPLE_NATIVE_GLUT -#include <OpenGL/gl.h> -#include <OpenGL/glu.h> -#include <GLUT/glut.h> -#else -#include <GL/freeglut.h> -#endif - #include <string> #include <iostream> @@ -55,6 +46,26 @@ MainWindow &MainWindow::getInstance() return s_mainWindow; } +void MainWindow::drawString(GLfloat x, GLfloat y, char *text, uint color, TextAlign align) +{ + char *p; + float red, green, blue; + + hex2fColor(color, red, green, blue); + + glLineWidth(3.0); + glPushMatrix(); + glTranslatef(x, y, 0); + glScalef(0.001, 0.001, 0.00); + if (align) + glTranslatef( ((float) align / 2) * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) text), 0, 0); + glColor3f(red, green, blue); + + for (p = text; *p; p++) + glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, *p); + glPopMatrix(); +} + void MainWindow::onChangeSize(int w, int h) { if (h == 0) @@ -158,6 +169,8 @@ void MainWindow::onRenderScene() { } } } + if (! m_pGame->isRunning()) + drawString(0, -0.02, "PAUSED", 0xffffff, center); } glutSwapBuffers(); diff --git a/MainWindow.h b/MainWindow.h index d7a9577..e4e8e81 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -1,6 +1,15 @@ #ifndef _MAIN_WINDOW_H
#define _MAIN_WINDOW_H
+#ifdef APPLE_NATIVE_GLUT
+#include <OpenGL/gl.h>
+#include <OpenGL/glu.h>
+#include <GLUT/glut.h>
+#else
+#include <GL/freeglut.h>
+#endif
+
+
#include "types.h"
#include <string>
#include <vector>
@@ -10,6 +19,12 @@ #include "Game.h"
#include "KeyboardController.h"
+enum TextAlign {
+ right = -2,
+ center = -1,
+ left = 0
+};
+
// Functions defines for C callbacks
void f_onChangeSize(int w, int h);
void f_onTimer(int v=0);
@@ -56,6 +71,7 @@ public: // Callbacks private:
void onKeyPressed(KeyCode key);
void drawCell(uint Color);
+ void drawString(GLfloat x, GLfloat y, char *text, uint color, TextAlign align);
private:
static MainWindow s_mainWindow;
|