|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-27 00:41:54
|
Module: performous
Branch: opengl2
Commit: 477655db8f247c402e0967327f3c5504fbdcfeb0
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Jan 24 03:02:38 2011 +0100
Add scaling to projection matrix so that 2d translations are easier, changed all 2d translations accordingly; added FarTransform which is a RAII object for drawing backgrounds on the far plane but in fullscreen size.
---
game/dancegraph.cc | 2 +-
game/guitargraph.cc | 2 +-
game/screenmanager.cc | 4 ++--
game/video_driver.cc | 28 ++++++++++++++++++++--------
game/video_driver.hh | 13 +++++++++++--
5 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index f37ed39..eabd84c 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -416,7 +416,7 @@ void DanceGraph::draw(double time) {
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
// Some matrix magic to get the viewport right
glutil::PushMatrixMode pmm(GL_PROJECTION);
- glTranslatef((2.0 * frac) * offsetX, 0.0f, 0.0f);
+ glTranslatef(frac * offsetX, 0.0f, 0.0f);
glutil::PushMatrixMode pmb(GL_MODELVIEW);
glTranslatef((1.0 - frac) * offsetX, dimensions.y1(), 0.0f);
float temp_s = dimensions.w() / 8.0f; // Allow for 8 pads to fit on a track
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 4a6f9c5..55ba0f7 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -796,7 +796,7 @@ void GuitarGraph::draw(double time) {
{ // Translate, rotate and scale to place
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
glutil::PushMatrixMode pmm(GL_PROJECTION);
- glTranslatef(frac * 2.0 * offsetX, 0.0f, 0.0f);
+ glTranslatef(frac * offsetX, 0.0f, 0.0f);
glutil::PushMatrixMode pmb(GL_MODELVIEW);
glTranslatef((1.0 - frac) * offsetX, dimensions.y2(), 0.0f);
// Do some jumping for drums
diff --git a/game/screenmanager.cc b/game/screenmanager.cc
index c702966..e28dc19 100644
--- a/game/screenmanager.cc
+++ b/game/screenmanager.cc
@@ -46,7 +46,7 @@ void ScreenManager::drawScreen() {
{
glViewport(0, 0, 1920, 540);
glutil::PushMatrixMode pp(GL_PROJECTION);
- glTranslatef(0.04f, 0.0f, 0.0f);
+ glTranslatef(0.02f, 0.0f, 0.0f);
glutil::PushMatrixMode pmv(GL_MODELVIEW);
glTranslatef(-0.02f, 0.0f, 0.0f);
//UseFBO fbo(m_fbo);
@@ -56,7 +56,7 @@ void ScreenManager::drawScreen() {
{
glViewport(0, 540, 1920, 540);
glutil::PushMatrixMode pp(GL_PROJECTION);
- glTranslatef(-0.04f, 0.0f, 0.0f);
+ glTranslatef(-0.02f, 0.0f, 0.0f);
glutil::PushMatrixMode pmv(GL_MODELVIEW);
glTranslatef(0.02f, 0.0f, 0.0f);
//UseFBO fbo(m_fbo);
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 97da558..eb505f1 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -1,7 +1,6 @@
#include "video_driver.hh"
#include "config.hh"
-#include "glutil.hh"
#include "fs.hh"
#include "image.hh"
#include "util.hh"
@@ -31,6 +30,11 @@ namespace {
int m_value;
};
+ // stump: under MSVC, near and far are #defined to nothing for compatibility with ancient code, hence the underscores.
+ const float near_ = 0.1f; // This determines the near clipping distance (must be > 0)
+ const float far_ = 110.0f; // How far away can things be seen
+ const float z0 = 1.5f; // This determines FOV: the value is your distance from the monitor (the unit being the width of the Performous window)
+
}
unsigned int screenW() { return s_width; }
@@ -67,7 +71,7 @@ Window::Window(unsigned int width, unsigned int height, bool fs): m_windowW(widt
Window::~Window() { }
void Window::blank() {
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Window::swap() {
@@ -137,17 +141,17 @@ void Window::resize() {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
- // Set projection
+ // Setup the projection matrix for 2D translates
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float h = virtH();
- // stump: under MSVC, near and far are #defined to nothing for compatibility with ancient code, hence the underscores.
- const float near_ = 0.5f; // This determines the near clipping distance (must be > 0)
- const float far_ = 100.0f; // How far away can things be seen
- const float z0 = 1.5f; // This determines FOV: the value is your distance from the monitor (the unit being the width of the Performous window)
- // Set model-view matrix
+ // OpenGL normalized coordinates go from -1 to 1, change scale so that our 2D translates can use the Performous normalized coordinates instead
+ glScalef(2.0f, 2.0f / h, 1.0f);
+ // Note: we do the frustum on MODELVIEW so that 2D positioning can be done via projection matrix.
+ // glTranslatef on that will move the image, not the camera (i.e. far-away and nearby objects move the same amount)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+ glScalef(0.5f, 0.5f * h, 1.0f); // Invert the scaling done on projection matrix
const float f = near_ / z0;
glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, near_, far_);
glTranslatef(0.0f, 0.0f, -z0); // Move back the world so that z = 0.0f is the monitor surface
@@ -155,3 +159,11 @@ void Window::resize() {
glutil::GLErrorChecker glerror("Window::resize");
}
+FarTransform::FarTransform() {
+ float z = far_ - 0.1f; // Very near the far plane but just a bit closer to avoid accidental clipping
+ float s = z / z0; // Scale the image so that it looks the same size
+ s *= 1.04; // A bit more for stereo3d (avoid black borders)
+ glTranslatef(0.0f, 0.0f, -z + z0); // Very near the farplane
+ glScalef(s, s, s);
+}
+
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 79c24c9..131c3ef 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -1,6 +1,7 @@
#pragma once
#include "glshader.hh"
+#include "glutil.hh"
#include <boost/scoped_ptr.hpp>
unsigned int screenW();
@@ -9,9 +10,17 @@ static inline float virtH() { return float(screenH()) / screenW(); }
struct SDL_Surface;
+/// Performs a GL transform for displaying background image at far distance
+class FarTransform {
+public:
+ FarTransform();
+private:
+ glutil::PushMatrix pm;
+};
+
/// handles the window
class Window {
- public:
+public:
/// constructor
Window(unsigned int windowW, unsigned int windowH, bool fullscreen);
/// destructor
@@ -39,7 +48,7 @@ class Window {
/// take a screenshot
void screenshot();
- private:
+private:
SDL_Surface* screen;
unsigned int m_windowW, m_windowH;
unsigned int m_fsW, m_fsH;
|