|
From: Lasse Kärkkäi. <tr...@us...> - 2009-07-13 00:54:37
|
Module: performous
Branch: master
Commit: 0c92751f2722b90720ce77c701df6ce6e1ad2b3a
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Jul 13 03:52:21 2009 +0300
Added glutil.hh and used it in a few places.
---
game/glutil.hh | 16 ++++++++++++++++
game/guitargraph.cc | 6 ++----
game/notegraph.cc | 3 +--
game/screen.hh | 8 ++++----
game/screen_sing.cc | 5 ++---
game/surface.cc | 1 -
game/surface.hh | 5 ++---
game/video_driver.cc | 2 +-
8 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/game/glutil.hh b/game/glutil.hh
new file mode 100644
index 0000000..96c9541
--- /dev/null
+++ b/game/glutil.hh
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <GL/glew.h>
+
+namespace glutil {
+ struct PushMatrix {
+ PushMatrix() { glPushMatrix(); }
+ ~PushMatrix() { glPopMatrix(); }
+ };
+
+ struct Begin {
+ Begin(GLint mode) { glBegin(mode); }
+ ~Begin() { glEnd(); }
+ };
+}
+
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 45adcab..86a2273 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -4,18 +4,16 @@ GuitarGraph::GuitarGraph(Song const& song): m_song(song), m_neck("guitarneck.svg
void GuitarGraph::draw(double time) {
UseTexture tex(m_neck);
- glPushMatrix();
+ glutil::PushMatrix pmb;
glTranslatef(0.0f, 0.3f, 0.0f);
glRotatef(80.0f, 1.0f, 0.0f, 0.0f);
glScalef(0.1f, 0.1f, 0.1f);
- glBegin(GL_QUADS);
float ts = 12.0f;
float future = 3.0f;
+ glutil::Begin block(GL_QUADS);
glTexCoord2f(0.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(-2.5f, -future * ts);
glTexCoord2f(1.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(2.5f, -future * ts);
glTexCoord2f(1.0f, -(time + 0.0f)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(2.5f, 0.0f * ts);
glTexCoord2f(0.0f, -(time + 0.0f)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(-2.5f, 0.0f * ts);
- glEnd();
glColor3f(1.0f, 1.0f, 1.0f);
- glPopMatrix();
}
diff --git a/game/notegraph.cc b/game/notegraph.cc
index 7cb37a5..5cc0999 100644
--- a/game/notegraph.cc
+++ b/game/notegraph.cc
@@ -21,7 +21,7 @@ void NoteGraph::reset() {
namespace {
void drawNotebar(Texture const& texture, double x, double y, double w, double h) {
UseTexture tblock(texture);
- glBegin(GL_TRIANGLE_STRIP);
+ glutil::Begin block(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f, 0.0f); glVertex2f(x, y);
glTexCoord2f(0.0f, 1.0f); glVertex2f(x, y + h);
if (w >= 2.0 * h) {
@@ -38,7 +38,6 @@ namespace {
}
glTexCoord2f(1.0f, 0.0f); glVertex2f(x + w, y);
glTexCoord2f(1.0f, 1.0f); glVertex2f(x + w, y + h);
- glEnd();
}
}
diff --git a/game/screen.hh b/game/screen.hh
index 1ce58c5..328ddfc 100644
--- a/game/screen.hh
+++ b/game/screen.hh
@@ -1,12 +1,12 @@
#pragma once
-#include <boost/ptr_container/ptr_map.hpp>
-#include <boost/scoped_ptr.hpp>
-#include "singleton.hh"
#include "audio.hh"
+#include "glutil.hh"
#include "record.hh"
+#include "singleton.hh"
#include "songs.hh"
-#include <GL/glew.h>
+#include <boost/ptr_container/ptr_map.hpp>
+#include <boost/scoped_ptr.hpp>
#include <SDL.h>
#include <iostream>
#include <string>
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 04ea5d2..e43dd19 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -106,12 +106,11 @@ namespace {
void fillBG() {
Dimensions dim(arMin);
dim.fixedWidth(1.0);
- glBegin(GL_QUADS);
+ glutil::Begin block(GL_QUADS);
glVertex2f(dim.x1(), dim.y1());
glVertex2f(dim.x2(), dim.y1());
glVertex2f(dim.x2(), dim.y2());
glVertex2f(dim.x1(), dim.y2());
- glEnd();
}
}
@@ -253,7 +252,7 @@ ScoreWindow::ScoreWindow(Engine& e):
}
void ScoreWindow::draw() {
- struct PushMatrixBlock { PushMatrixBlock() { glPushMatrix(); } ~PushMatrixBlock() { glPopMatrix(); } } b;
+ glutil::PushMatrix block;
glTranslatef(0.0, m_pos.get(), 0.0);
m_bg.draw();
const double spacing = 0.1 + 0.1 / m_players.size();
diff --git a/game/surface.cc b/game/surface.cc
index c172301..3d59458 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -3,7 +3,6 @@
#include "fs.hh"
#include "configuration.hh"
#include "video_driver.hh"
-#include <GL/glu.h>
#include <Magick++.h>
#include <boost/bind.hpp>
#include <fstream>
diff --git a/game/surface.hh b/game/surface.hh
index 3d2d1eb..92e6b64 100644
--- a/game/surface.hh
+++ b/game/surface.hh
@@ -1,6 +1,6 @@
#pragma once
-#include <GL/glew.h>
+#include "glutil.hh"
#include <stdexcept>
#include <string>
#include <boost/noncopyable.hpp>
@@ -127,12 +127,11 @@ class UseTexture: boost::noncopyable {
template <GLenum Type> void OpenGLTexture<Type>::draw(Dimensions const& dim, TexCoords const& tex) const {
UseTexture texture(*this);
- glBegin(GL_QUADS);
+ glutil::Begin block(GL_QUADS);
glTexCoord2f(tex.x1, tex.y1); glVertex2f(dim.x1(), dim.y1());
glTexCoord2f(tex.x2, tex.y1); glVertex2f(dim.x2(), dim.y1());
glTexCoord2f(tex.x2, tex.y2); glVertex2f(dim.x2(), dim.y2());
glTexCoord2f(tex.x1, tex.y2); glVertex2f(dim.x1(), dim.y2());
- glEnd();
}
template <GLenum Type> void OpenGLTexture<Type>::drawCropped(Dimensions const& orig, TexCoords const& tex) const {
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 39dcb5e..63fcd71 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -1,10 +1,10 @@
#include "video_driver.hh"
#include "config.hh"
+#include "glutil.hh"
#include "screen.hh"
#include "util.hh"
#include "joystick.hh"
-#include <GL/glew.h>
#include <SDL.h>
unsigned s_width;
|