You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(25) |
Jul
(288) |
Aug
(119) |
Sep
(31) |
Oct
(59) |
Nov
(458) |
Dec
(359) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(268) |
Feb
(26) |
Mar
(36) |
Apr
(48) |
May
(119) |
Jun
(37) |
Jul
(173) |
Aug
(429) |
Sep
(137) |
Oct
(156) |
Nov
(59) |
Dec
(45) |
| 2011 |
Jan
(398) |
Feb
(257) |
Mar
(49) |
Apr
(5) |
May
(34) |
Jun
(11) |
Jul
(38) |
Aug
(12) |
Sep
(1) |
Oct
(49) |
Nov
(5) |
Dec
(10) |
| 2012 |
Jan
(21) |
Feb
(32) |
Mar
(20) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(173) |
Aug
|
Sep
(25) |
Oct
(6) |
Nov
(44) |
Dec
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:51:24
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sat Mar 12 23:00:27 2011 +0100 Fixed glutil::Color + cleanup --- game/dancegraph.cc | 2 +- game/glshader.cc | 10 ++-------- game/glshader.hh | 8 ++------ game/glutil.hh | 31 ------------------------------- game/guitargraph.cc | 16 ++++++++-------- game/notegraph.cc | 2 +- game/screen_songs.cc | 12 ++++++------ game/video_driver.cc | 17 ++++++++++++----- game/video_driver.hh | 14 ++++++++++++++ 9 files changed, 46 insertions(+), 66 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:51:14
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sat Mar 12 22:20:27 2011 +0100 Use local perspective for popups, joinmenus, etc. --- game/dancegraph.cc | 15 +++++++-------- game/dancegraph.hh | 2 +- game/guitargraph.cc | 22 ++++++++++------------ game/guitargraph.hh | 2 +- game/instrumentgraph.cc | 18 +++++++++--------- game/instrumentgraph.hh | 39 +++++++++++++++++++-------------------- 6 files changed, 47 insertions(+), 51 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:51:05
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 21:39:29 2011 +0100
Fix view/projection transforms (instrument perspective)
---
game/guitargraph.cc | 7 +------
game/video_driver.cc | 32 +++++++++++++++++++++++++-------
game/video_driver.hh | 10 ++++++++++
3 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 62518f4..7395222 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -796,12 +796,7 @@ void GuitarGraph::draw(double time) {
{ // Translate, rotate and scale to place
using namespace glmath;
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
- /*
- glutil::PushMatrixMode pmm(GL_PROJECTION);
- glTranslatef(frac * offsetX, 0.0f, 0.0f);
- glutil::PushMatrixMode pmb(GL_MODELVIEW);
- glTranslatef((1.0 - frac) * offsetX, 0.0f, 0.0f);
- */
+ ViewTrans view(offsetX, 0.0, frac);
mat4 m = translate(vec3(0.0f, dimensions.y2(), 0.0f)) * rotate(g_angle, vec3(1.0f, 0.0f, 0.0f)) * scale(dimensions.w() / 5.0f);
// Do some jumping for drums
if (m_drums) {
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 5d96406..eeddf08 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -148,13 +148,7 @@ void Window::updateStereo(float sepFactor) {
}
void Window::updateTransforms() {
- // Setup the projection matrix for 2D translates
using namespace glmath;
- {
- float h = virtH();
- const float f = near_ / z0;
- g_projection = frustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, near_, far_);
- }
mat4 position = g_projection * g_modelview;
mat3 normal(g_modelview);
for (ShaderMap::iterator it = m_shaders.begin(); it != m_shaders.end(); ++it) {
@@ -169,7 +163,7 @@ void Window::updateTransforms() {
void Window::render(boost::function<void (void)> drawFunc) {
glutil::GLErrorChecker glerror("Window::render");
- updateTransforms();
+ ViewTrans trans; // Default frustum
if (s_width < screen->w || s_height < screen->h) glClear(GL_COLOR_BUFFER_BIT); // Black bars
bool stereo = config["graphic/stereo3d"].b();
int type = config["graphic/stereo3dtype"].i();
@@ -318,6 +312,30 @@ void Window::resize() {
if (s_height > 0.8f * s_width) s_height = round(0.8f * s_width);
}
+ViewTrans::ViewTrans(double offsetX, double offsetY, double frac): m_old(g_projection) {
+ // Setup the projection matrix for 2D translates
+ using namespace glmath;
+ double h = virtH();
+ const double f = near_ / z0; // z0 to nearplane conversion factor
+ // Corners of the screen at z0
+ double x1 = -0.5, x2 = 0.5;
+ double y1 = 0.5 * h, y2 = -0.5 * h;
+ // Move the perspective point by frac of offset (i.e. move the image)
+ double persX = frac * offsetX, persY = frac * offsetY;
+ x1 -= persX; x2 -= persX;
+ y1 -= persY; y2 -= persY;
+ // Perspective projection + the rest of the offset in eye (world) space
+ g_projection = frustum(f * x1, f * x2, f * y1, f * y2, near_, far_)
+ * translate(vec3(offsetX - persX, offsetY - persY, 0.0));
+ ScreenManager::getSingletonPtr()->window().updateTransforms();
+}
+
+ViewTrans::~ViewTrans() {
+ g_projection = m_old;
+ ScreenManager::getSingletonPtr()->window().updateTransforms();
+}
+
+
Transform::Transform(glmath::mat4 const& m): m_old(g_modelview) {
g_modelview = g_modelview * m;
ScreenManager::getSingletonPtr()->window().updateTransforms();
diff --git a/game/video_driver.hh b/game/video_driver.hh
index c493035..eafd93d 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -12,6 +12,7 @@ static inline float virtH() { return float(screenH()) / screenW(); }
struct SDL_Surface;
+/// Apply a transform to current modelview stack
class Transform {
public:
Transform(glmath::mat4 const& m);
@@ -20,6 +21,15 @@ private:
glmath::mat4 m_old;
};
+/// Apply a subviewport with different perspective projection
+class ViewTrans {
+public:
+ ViewTrans(double offsetX = 0.0, double offsetY = 0.0, double frac = 1.0);
+ ~ViewTrans();
+private:
+ glmath::mat4 m_old;
+};
+
/// Performs a GL transform for displaying background image at far distance
glmath::mat4 farTransform();
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:56
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 20:25:06 2011 +0100
All FixedFunc transform stuff removed (gl2cleanup)
---
game/3dobject.hh | 5 ++---
game/dialog.hh | 8 ++++----
game/glutil.hh | 14 --------------
game/guitargraph.cc | 18 ++++++++++--------
game/instrumentgraph.cc | 3 +--
game/instrumentgraph.hh | 4 ++--
game/notegraph.cc | 5 ++---
game/screen_sing.cc | 4 ++--
8 files changed, 23 insertions(+), 38 deletions(-)
diff --git a/game/3dobject.hh b/game/3dobject.hh
index 1479c3b..5ce33f5 100644
--- a/game/3dobject.hh
+++ b/game/3dobject.hh
@@ -33,9 +33,8 @@ class Object3d: boost::noncopyable {
void drawVBO();
/// draws the object
void draw(float x = 0, float y = 0, float z = 0, float s = 1.0) {
- glutil::PushMatrix pm;
- glTranslatef(x, y, z); // Move to position
- if (s != 1.0) glScalef(s,s,s); // Scale if needed
+ using namespace glmath;
+ Transform trans(translate(vec3(x, y, z)) * scale(s)); // Move to position and scale
if (m_texture) {
UseTexture tex(*m_texture);
drawVBO();
diff --git a/game/dialog.hh b/game/dialog.hh
index b3e63a8..b33c1b3 100644
--- a/game/dialog.hh
+++ b/game/dialog.hh
@@ -1,9 +1,9 @@
#pragma once
-#include "opengl_text.hh"
+#include "configuration.hh"
#include "fs.hh"
+#include "opengl_text.hh"
#include "surface.hh"
-#include "configuration.hh"
/// class for printing dialogues
class Dialog {
@@ -18,8 +18,8 @@ class Dialog {
}
/// draws dialogue
void draw() {
- glutil::PushMatrix pm;
- glTranslatef(0.0f, 0.0f, 0.1f); // Raise a bit in 3D
+ using namespace glmath;
+ Transform(translate(vec3(0.0f, 0.0f, 0.1f))); // Raise a bit in 3D
m_dialog.draw();
m_svgText.draw(m_text);
}
diff --git a/game/glutil.hh b/game/glutil.hh
index f36cf91..9b737ff 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -13,20 +13,6 @@ glmath::mat4& getColorMatrix(); ///< A temporary hack for global access to the
namespace glutil {
/// wrapper struct for RAII
- struct PushMatrix {
- PushMatrix() { glPushMatrix(); }
- ~PushMatrix() { glPopMatrix(); }
- };
-
- /// wrapper struct for RAII
- struct PushMatrixMode {
- PushMatrixMode(GLenum mode) { glGetIntegerv(GL_MATRIX_MODE, &m_old); glMatrixMode(mode); glPushMatrix(); }
- ~PushMatrixMode() { glPopMatrix(); glMatrixMode(m_old); }
- private:
- GLint m_old;
- };
-
- /// wrapper struct for RAII
struct UseDepthTest {
/// enable depth test (for 3d objects)
UseDepthTest() {
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 38ada22..62518f4 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -23,7 +23,7 @@ namespace {
const size_t diffsz = sizeof(diffv) / sizeof(*diffv);
const int death_delay = 20; // Delay in notes after which the player is hidden
const float join_delay = 3.0f; // Time after join menu before playing when joining mid-game
- const float g_angle = 80.0f; // How much to rotate the fretboards
+ const float g_angle = 1.4f; // How many radians to rotate the fretboards
const float past = -0.2f; // Relative time from cursor that is considered past (out of screen)
const float future = 1.5f; // Relative time from cursor that is considered future (out of screen)
const float timescale = 25.0f; // Multiplier to get graphics units from time
@@ -794,20 +794,22 @@ void GuitarGraph::draw(double time) {
float ng_r = 0, ng_g = 0, ng_b = 0; // neck glow color components
int ng_ccnt = 0; // neck glow color count
{ // Translate, rotate and scale to place
+ using namespace glmath;
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
+ /*
glutil::PushMatrixMode pmm(GL_PROJECTION);
glTranslatef(frac * offsetX, 0.0f, 0.0f);
glutil::PushMatrixMode pmb(GL_MODELVIEW);
- glTranslatef((1.0 - frac) * offsetX, dimensions.y2(), 0.0f);
+ glTranslatef((1.0 - frac) * offsetX, 0.0f, 0.0f);
+ */
+ mat4 m = translate(vec3(0.0f, dimensions.y2(), 0.0f)) * rotate(g_angle, vec3(1.0f, 0.0f, 0.0f)) * scale(dimensions.w() / 5.0f);
// Do some jumping for drums
if (m_drums) {
float jumpanim = m_drumJump.get();
if (jumpanim == 1.0) m_drumJump.setTarget(0.0);
- if (jumpanim > 0) glTranslatef(0.0f, -m_drumJump.get() * 0.01, 0.0f);
+ if (jumpanim > 0) m = translate(vec3(0.0f, -m_drumJump.get() * 0.01, 0.0f)) * m;
}
- glRotatef(g_angle, 1.0f, 0.0f, 0.0f);
- float temp_s = dimensions.w() / 5.0f;
- glScalef(temp_s, temp_s, temp_s);
+ Transform trans(m);
// Draw the neck
{
@@ -1156,8 +1158,8 @@ void GuitarGraph::drawDrumfill(float tBeg, float tEnd) {
void GuitarGraph::drawInfo(double time, double offsetX, Dimensions dimensions) {
// Draw info
if (!menuOpen()) {
- glutil::PushMatrix mat;
- glTranslatef(0.0f, 0.0f, -0.5f);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0f, 0.0f, -0.5f)));
float xcor = 0.35 * dimensions.w();
float h = 0.075 * 2.0 * dimensions.w();
// Hack to show the scores better when there is more space (1 instrument)
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index 95de035..5a7aca9 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -75,10 +75,9 @@ void InstrumentGraph::drawMenu() {
// Some helper vars
ThemeInstrumentMenu& th = *m_menuTheme;
MenuOptions::const_iterator cur = static_cast<MenuOptions::const_iterator>(&m_menu.current());
- glutil::PushMatrix pm; // Save scaling state
double w = m_menu.dimensions.w();
const float s = std::min(m_width.get(), 0.5) / w;
- glScalef(s, s, 1.0f);
+ Transform trans(glmath::scale(s)); // Fit better menu on screen
// We need to multiply offset by inverse scale factor to keep it always constant
// All these vars are ultimately affected by the scaling matrix
const double offsetX = 0.5f * (dimensions.x1() + dimensions.x2()) / s;
diff --git a/game/instrumentgraph.hh b/game/instrumentgraph.hh
index 85d3585..fe6d0d4 100644
--- a/game/instrumentgraph.hh
+++ b/game/instrumentgraph.hh
@@ -34,8 +34,8 @@ class Popup {
glutil::Color color(m_color);
m_popupText->render(m_msg);
{
- glutil::PushMatrix mat;
- glTranslatef(0.0f, 0.0f, 0.5f * anim);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0f, 0.0f, 0.5f * anim)));
m_popupText->dimensions().center(0.1 - 0.03 * anim).middle(offsetX).stretch(0.2f, 0.2f);
m_popupText->draw();
}
diff --git a/game/notegraph.cc b/game/notegraph.cc
index f012ea8..f3c36e1 100644
--- a/game/notegraph.cc
+++ b/game/notegraph.cc
@@ -122,9 +122,8 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
float centerx = x + w - (player_star_offset + 1.2) * hh; // Star is 1.2 units from end
float rot = fmod(time * 360, 360); // They rotate!
float zoom = (std::abs((rot-180) / 360.0f) * 0.8f + 0.6f) * (position == NoteGraph::TOP ? 2.3 : 2.0) * hh;
- glutil::PushMatrix pm;
- glTranslatef(centerx, centery, 0.0f);
- glRotatef(rot, 0.0f, 0.0f, 1.0f);
+ using namespace glmath;
+ Transform trans(translate(vec3(centerx, centery, 0.0f)) * rotate(rot, vec3(0.0f, 0.0f, 1.0f)));
{
glutil::Color c(Color(it_col->r, it_col->g, it_col->b, it_col->a));
m_star_hl.draw(Dimensions().stretch(zoom*1.2, zoom*1.2).center().middle(), TexCoords());
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index f4c0d0a..fb3bc43 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -646,8 +646,8 @@ ScoreWindow::ScoreWindow(Instruments& instruments, Database& database, Dancers&
}
void ScoreWindow::draw() {
- glutil::PushMatrix block;
- glTranslatef(0.0, m_pos.get(), 0.0);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0, m_pos.get(), 0.0)));
m_bg.draw();
const double spacing = 0.1 + 0.1 / m_database.scores.size();
unsigned i = 0;
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:48
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 19:43:37 2011 +0100
Fix FarTransform
---
game/screen_sing.cc | 2 +-
game/screen_songs.cc | 2 +-
game/video_driver.cc | 6 +++---
game/video_driver.hh | 7 +------
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 335fead..f4c0d0a 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -426,7 +426,7 @@ void ScreenSing::draw() {
// Rendering starts
{
- FarTransform ft;
+ Transform ft(farTransform());
double ar = arMax;
// Background image
if (m_background) {
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index 2bbc520..da69c36 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -148,7 +148,7 @@ void ScreenSongs::drawJukebox() {
void ScreenSongs::drawMultimedia() {
{
- FarTransform ft; // 3D effect
+ Transform ft(farTransform()); // 3D effect
double length = m_audio.getLength();
double time = clamp(m_audio.getPosition() - config["audio/video_delay"].f(), 0.0, length);
m_songbg_default->draw(); // Default bg
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 356deaf..5d96406 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -328,11 +328,11 @@ Transform::~Transform() {
ScreenManager::getSingletonPtr()->window().updateTransforms();
}
-FarTransform::FarTransform() {
+glmath::mat4 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.0 + 2.0 * getSeparation(); // A bit more for stereo3d (avoid black borders)
- glTranslatef(0.0f, 0.0f, -z + z0); // Very near the farplane
- glScalef(s, s, s);
+ using namespace glmath;
+ return translate(vec3(0.0f, 0.0f, -z + z0)) * scale(s); // Very near the farplane
}
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 8bb7eef..c493035 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -21,12 +21,7 @@ private:
};
/// Performs a GL transform for displaying background image at far distance
-class FarTransform {
-public:
- FarTransform();
-private:
- glutil::PushMatrix pm;
-};
+glmath::mat4 farTransform();
/// handles the window
class Window {
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:41
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 19:19:50 2011 +0100
Fix dancegraph transformations (gl2cleanup)
---
game/dancegraph.cc | 8 ++------
1 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index 7625a2e..3352d94 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -413,14 +413,10 @@ void DanceGraph::draw(double time) {
double offsetX = 0.5 * (dimensions.x1() + dimensions.x2());
{
- double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
+ using namespace glmath;
// Some matrix magic to get the viewport right
- glutil::PushMatrixMode pmm(GL_PROJECTION);
- 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
- glScalef(temp_s, temp_s, temp_s);
+ Transform trans(translate(vec3(offsetX, dimensions.y1(), 0.0)) * scale(temp_s));
// Draw the "neck" graph (beat lines)
drawBeats(time);
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:35
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 17:30:18 2011 +0100
Remove useless include
---
game/glmath.hh | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/game/glmath.hh b/game/glmath.hh
index 96bc1c3..2f1da54 100644
--- a/game/glmath.hh
+++ b/game/glmath.hh
@@ -5,7 +5,6 @@
#include <cmath>
#include <iomanip>
#include <iostream>
-#include <stdexcept>
#include <sstream>
namespace glmath {
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:28
|
Author: Lasse Karkkainen <tro...@tr...> Date: Mon Mar 7 02:11:01 2011 +0100 Transforms via a new helper class and video_driver, cover browser updated to use that. Uniforms separated from Shader class (new helper class) and code updated to use that. colorMatrix broken (old hack removed). --- game/dancegraph.cc | 22 ++++++++++-------- game/glshader.cc | 9 ++++--- game/glshader.hh | 50 +++++++++++++---------------------------- game/screen_songs.cc | 17 ++++++------- game/video_driver.cc | 59 ++++++++++++++++++++++++++++++------------------- game/video_driver.hh | 10 +++++++- 6 files changed, 86 insertions(+), 81 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:22
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Mar 7 00:03:41 2011 +0100
Normals need to be normalized in both vertex and fragment shaders for proper weighting and interpolation.
---
data/shaders/core.vert | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/data/shaders/core.vert b/data/shaders/core.vert
index d3b5f4f..ee16a3d 100644
--- a/data/shaders/core.vert
+++ b/data/shaders/core.vert
@@ -20,7 +20,7 @@ varying vec4 vColor;
void main() {
gl_Position = positionMatrix * vertPos;
vTexCoord = texCoord = vertTexCoord;
- vNormal = normal = normalMatrix * vertNormal;
+ vNormal = normal = normalize(normalMatrix * vertNormal);
vColor = color = vertColor;
}
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:15
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sun Mar 6 23:15:10 2011 +0100 Re-enable bogus (the old problem remains) and improve the shader defines system. --- data/shaders/core.frag | 8 ++++++++ data/shaders/stereo3d.geom | 2 ++ game/glshader.hh | 2 +- game/video_driver.cc | 19 ++++++++++++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/data/shaders/core.frag b/data/shaders/core.frag index 78a3c87..f7c7e28 100644 --- a/data/shaders/core.frag +++ b/data/shaders/core.frag @@ -5,6 +5,10 @@ uniform mat4 colorMatrix; +#ifdef ENABLE_BOGUS +in float bogus; // Workaround for http://www.nvnews.net/vbulletin/showthread.php?p=2401097 +#endif + in vec3 normal; in vec4 color; @@ -28,6 +32,10 @@ uniform sampler2D tex; void main() { vec4 frag = TEXFUNC; +#ifdef ENABLE_BOGUS + frag.a += 1e-14 * bogus; // Convince the compiler not to optimize away the bogus variable +#endif + #ifdef ENABLE_VERTEX_COLOR frag *= color; #endif diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom index 4fa2f7a..c6522c1 100644 --- a/data/shaders/stereo3d.geom +++ b/data/shaders/stereo3d.geom @@ -11,6 +11,7 @@ in vec4 vTexCoord[]; in vec3 vNormal[]; in vec4 vColor[]; +out float bogus; // Workaround for http://www.nvnews.net/vbulletin/showthread.php?p=2401097 out vec4 texCoord; out vec3 normal; out vec4 color; @@ -28,6 +29,7 @@ void passthru() { #define PROCESS(code) i = 0; do { passthru(); code; EmitVertex(); } while (++i < gl_in.length()); EndPrimitive(); void main() { + bogus = 0.0; if (sepFactor == 0.0) { gl_ViewportIndex = 0; PROCESS(); // No stereo } else { diff --git a/game/glshader.hh b/game/glshader.hh index 4a08121..22f12ff 100644 --- a/game/glshader.hh +++ b/game/glshader.hh @@ -16,7 +16,7 @@ struct Shader: public boost::noncopyable { Shader(std::string const& name); ~Shader(); /// Set a string that will replace "//DEFINES" in anything loaded by compileFile - Shader& setDefines(std::string const& defines) { defs = defines; return *this; } + Shader& addDefines(std::string const& defines) { defs += defines; return *this; } /// Load shader from file Shader& compileFile(std::string const& filename); /** Compiles a shader of a given type. */ diff --git a/game/video_driver.cc b/game/video_driver.cc index 01c712d..47b9116 100644 --- a/game/video_driver.cc +++ b/game/video_driver.cc @@ -81,38 +81,47 @@ Window::Window(unsigned int width, unsigned int height, bool fs): m_windowW(widt shader("texture").compileFile(getThemePath("shaders/stereo3d.geom")); shader("3dobject").compileFile(getThemePath("shaders/stereo3d.geom")); shader("dancenote").compileFile(getThemePath("shaders/stereo3d.geom")); + if (!GLEW_VERSION_4_1) { + // Enable bugfix for some older Nvidia cards + for (ShaderMap::iterator it = m_shaders.begin(); it != m_shaders.end(); ++it) { + Shader& sh = *it->second; + sh.addDefines("#define ENABLE_BOGUS\n"); + } + } } shader("color") - .setDefines("#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("surface") - .setDefines("#define ENABLE_TEXTURING 1\n") + .addDefines("#define ENABLE_TEXTURING 1\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("texture") - .setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_TEXTURING 2\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("3dobject") - .setDefines("#define ENABLE_LIGHTING\n") + .addDefines("#define ENABLE_LIGHTING\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("dancenote") - .setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_TEXTURING 2\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/dancenote.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:08
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 28 01:43:32 2011 +0100
Correct order for vertex color vs. lighting.
---
data/shaders/core.frag | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/data/shaders/core.frag b/data/shaders/core.frag
index 7a3f7a1..78a3c87 100644
--- a/data/shaders/core.frag
+++ b/data/shaders/core.frag
@@ -28,6 +28,10 @@ uniform sampler2D tex;
void main() {
vec4 frag = TEXFUNC;
+#ifdef ENABLE_VERTEX_COLOR
+ frag *= color;
+#endif
+
#ifdef ENABLE_LIGHTING
vec3 lightDir = normalize(vec3(-50.0, 5.0, -15.0));
const vec3 ambient = vec3(0.1, 0.1, 0.1);
@@ -35,9 +39,7 @@ void main() {
float NdotL = max(dot(normalize(normal), lightDir), 0.0);
frag = vec4(ambient + frag.rgb * NdotL, frag.a);
#endif
-#ifdef ENABLE_VERTEX_COLOR
- frag *= color;
-#endif
+
gl_FragColor = colorMatrix * frag;
}
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:56
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 28 01:26:21 2011 +0100
Stereo3d shader cleanup and changed stereo viewport numbering.
---
data/shaders/stereo3d.geom | 42 +++++++++++-------------------------------
game/video_driver.cc | 8 ++++----
2 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom
index b19f19b..4fa2f7a 100644
--- a/data/shaders/stereo3d.geom
+++ b/data/shaders/stereo3d.geom
@@ -1,6 +1,9 @@
#version 330
#extension GL_ARB_viewport_array : require
+uniform float sepFactor;
+uniform float z0;
+
layout(triangles) in;
layout(triangle_strip, max_vertices = 6) out;
@@ -12,47 +15,24 @@ out vec4 texCoord;
out vec3 normal;
out vec4 color;
-uniform float sepFactor;
-uniform float z0;
+int i;
-void passthru(in int i) {
+void passthru() {
gl_Position = gl_in[i].gl_Position;
texCoord = vTexCoord[i];
normal = vNormal[i];
color = vColor[i];
}
+// Process all the vertices, applying code to them before emitting (do-while to convince Nvidia of the code getting executed)
+#define PROCESS(code) i = 0; do { passthru(); code; EmitVertex(); } while (++i < gl_in.length()); EndPrimitive();
+
void main() {
- // Fix Nvidia compile warnings ("might be used uninitialized")
- gl_Position = vec4(0);
- texCoord = vec4(0);
- normal = vec3(0);
- color = vec4(0);
if (sepFactor == 0.0) {
- // No stereo
- gl_ViewportIndex = 0;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- EmitVertex();
- }
- EndPrimitive();
+ gl_ViewportIndex = 0; PROCESS(); // No stereo
} else {
- // Render the left eye
- gl_ViewportIndex = 0;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- gl_Position.x -= sepFactor * (gl_Position.z - z0);
- EmitVertex();
- }
- EndPrimitive();
- // Render the right eye
- gl_ViewportIndex = 1;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- gl_Position.x += sepFactor * (gl_Position.z - z0);
- EmitVertex();
- }
- EndPrimitive();
+ gl_ViewportIndex = 1; PROCESS(gl_Position.x -= sepFactor * (gl_Position.z - z0)); // Left eye
+ gl_ViewportIndex = 2; PROCESS(gl_Position.x += sepFactor * (gl_Position.z - z0)); // Right eye
}
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 5a4e9ce..01c712d 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -178,8 +178,8 @@ void Window::render(boost::function<void (void)> drawFunc) {
{
UseFBO user(fbo);
view(0);
- glViewportIndexedf(0, 0, h / 2, w, h / 2);
- glViewportIndexedf(1, 0, 0, w, h / 2);
+ glViewportIndexedf(1, 0, h / 2, w, h / 2);
+ glViewportIndexedf(2, 0, 0, w, h / 2);
drawFunc();
}
glerror.check("Render to FBO");
@@ -240,8 +240,8 @@ void Window::view(unsigned num) {
if (num == 0) {
glViewport(vx, vy, vw, vh); // Drawable area of the window (excluding black bars)
} else {
- glViewportIndexedf(0, 0, vh / 2, vw, vh / 2); // Top half of the drawable area
- glViewportIndexedf(1, 0, 0, vw, vh / 2); // Bottom half of the drawable area
+ glViewportIndexedf(1, 0, vh / 2, vw, vh / 2); // Top half of the drawable area
+ glViewportIndexedf(2, 0, 0, vw, vh / 2); // Bottom half of the drawable area
}
}
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:49
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 28 01:22:47 2011 +0100
The longest journey towards legacy-free OpenGL
* Fixes/extensions to glmath.
* Separate uniform functions for Mat3/Mat4.
* Hardcoded position (modelviewprojection) matrix - glTranslatef & friends do nothing now => major b0rkage.
* Normal matrix uses the position matrix directly for now (should be inverse transpose).
---
game/glmath.hh | 8 ++++++++
game/glshader.cc | 4 ++--
game/glshader.hh | 5 ++++-
game/video_driver.cc | 43 +++++++++++++++++++++++--------------------
game/video_driver.hh | 1 +
5 files changed, 38 insertions(+), 23 deletions(-)
diff --git a/game/glmath.hh b/game/glmath.hh
index a013fe5..96bc1c3 100644
--- a/game/glmath.hh
+++ b/game/glmath.hh
@@ -10,9 +10,15 @@
namespace glmath {
+ struct vec4;
+
struct vec3 {
GLfloat x, y, z;
+ explicit vec3(GLfloat const* arr) { std::copy(arr, arr + 3, &x); }
explicit vec3(float x = 0.0, float y = 0.0, float z = 0.0): x(x), y(y), z(z) {}
+ explicit vec3(vec4 const& v);
+ GLfloat& operator[](unsigned j) { return (&x)[j]; }
+ GLfloat const& operator[](unsigned j) const { return (&x)[j]; }
};
struct vec4 {
@@ -24,6 +30,8 @@ namespace glmath {
GLfloat const& operator[](unsigned j) const { return (&x)[j]; }
};
+ inline vec3::vec3(vec4 const& v): x(v.x), y(v.y), z(v.z) {}
+
static inline vec3 operator*(float k, vec3 const& v) { return vec3(k * v.x, k * v.y, k * v.z); }
static inline float dot(vec3 const& a, vec3 const& b) {
diff --git a/game/glshader.cc b/game/glshader.cc
index 6b9242a..e3710f7 100644
--- a/game/glshader.cc
+++ b/game/glshader.cc
@@ -123,7 +123,7 @@ Shader& Shader::link() {
Shader& Shader::bind() {
glutil::GLErrorChecker ec("Shader::bind");
glUseProgram(program);
- setUniformMatrix("colorMatrix", getColorMatrix());
+ setUniformMat4("colorMatrix", getColorMatrix());
return *this;
}
@@ -158,7 +158,7 @@ void VertexArray::Draw(GLint mode) {
}
if (vertNormal != -1) {
glEnableVertexAttribArray(vertNormal);
- glVertexAttribPointer(vertNormal, 4, GL_FLOAT, GL_FALSE, stride, ptr + 2);
+ glVertexAttribPointer(vertNormal, 3, GL_FLOAT, GL_FALSE, stride, ptr + 2);
}
if (vertColor != -1) {
glEnableVertexAttribArray(vertColor);
diff --git a/game/glshader.hh b/game/glshader.hh
index d3355a8..4a08121 100644
--- a/game/glshader.hh
+++ b/game/glshader.hh
@@ -53,7 +53,10 @@ struct Shader: public boost::noncopyable {
Shader& setUniform(const std::string& uniform, float x, float y, float z, float w) {
glUniform4f((*this)[uniform], x, y, z, w); return *this;
}
- Shader& setUniformMatrix(const std::string& uniform, GLfloat const* m) {
+ Shader& setUniformMat3(const std::string& uniform, GLfloat const* m) {
+ glUniformMatrix3fv((*this)[uniform], 1, GL_FALSE, m); return *this;
+ }
+ Shader& setUniformMat4(const std::string& uniform, GLfloat const* m) {
glUniformMatrix4fv((*this)[uniform], 1, GL_FALSE, m); return *this;
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 2ea6d62..5a4e9ce 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -89,35 +89,35 @@ Window::Window(unsigned int width, unsigned int height, bool fs): m_windowW(widt
.compileFile(getThemePath("shaders/core.frag"))
.link()
.bind()
- .setUniformMatrix("colorMatrix", glmath::mat4::identity());
+ .setUniformMat4("colorMatrix", glmath::mat4::identity());
shader("surface")
.setDefines("#define ENABLE_TEXTURING 1\n")
.compileFile(getThemePath("shaders/core.vert"))
.compileFile(getThemePath("shaders/core.frag"))
.link()
.bind()
- .setUniformMatrix("colorMatrix", glmath::mat4::identity());
+ .setUniformMat4("colorMatrix", glmath::mat4::identity());
shader("texture")
.setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n")
.compileFile(getThemePath("shaders/core.vert"))
.compileFile(getThemePath("shaders/core.frag"))
.link()
.bind()
- .setUniformMatrix("colorMatrix", glmath::mat4::identity());
+ .setUniformMat4("colorMatrix", glmath::mat4::identity());
shader("3dobject")
.setDefines("#define ENABLE_LIGHTING\n")
.compileFile(getThemePath("shaders/core.vert"))
.compileFile(getThemePath("shaders/core.frag"))
.link()
.bind()
- .setUniformMatrix("colorMatrix", glmath::mat4::identity());
+ .setUniformMat4("colorMatrix", glmath::mat4::identity());
shader("dancenote")
.setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n")
.compileFile(getThemePath("shaders/dancenote.vert"))
.compileFile(getThemePath("shaders/core.frag"))
.link()
.bind()
- .setUniformMatrix("colorMatrix", glmath::mat4::identity());
+ .setUniformMat4("colorMatrix", glmath::mat4::identity());
view(0); // For loading screens
}
@@ -138,8 +138,26 @@ void Window::updateStereo(float sepFactor) {
}
}
+void Window::updateTransforms() {
+ // Setup the projection matrix for 2D translates
+ using namespace glmath;
+ float h = virtH();
+ const float f = near_ / z0;
+ mat4 position = frustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, near_, far_) * translate(vec3(0.0, 0.0, -z0));
+ mat3 normal(position);
+ for (ShaderMap::iterator it = m_shaders.begin(); it != m_shaders.end(); ++it) {
+ Shader& sh = *it->second;
+ sh.bind();
+ sh.setUniformMat4("positionMatrix", position);
+ try {
+ sh.setUniformMat3("normalMatrix", normal);
+ } catch(...) {} // Not fatal if normalMatrix is missing (only 3d objects use it)
+ }
+}
+
void Window::render(boost::function<void (void)> drawFunc) {
glutil::GLErrorChecker glerror("Window::render");
+ updateTransforms();
if (s_width < screen->w || s_height < screen->h) glClear(GL_COLOR_BUFFER_BIT); // Black bars
bool stereo = config["graphic/stereo3d"].b();
int type = config["graphic/stereo3dtype"].i();
@@ -215,21 +233,6 @@ void Window::view(unsigned num) {
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
shader("color").bind();
- // Setup the projection matrix for 2D translates
- using namespace glmath;
- glMatrixMode(GL_PROJECTION);
- float h = virtH();
- // OpenGL normalized coordinates go from -1 to 1, change scale so that our 2D translates can use the Performous normalized coordinates instead
- //upload(scale(vec3(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);
- const float f = near_ / z0;
- /*upload(
- scale(vec3(0.5, 0.5 * h, 1.0))
- * frustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, near_, far_)
- * translate(vec3(0.0, 0.0, -z0))
- );*/
// Setup views
double vx = 0.5f * (screen->w - s_width);
double vy = 0.5f * (screen->h - s_height);
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 7a11fa6..7ae29dc 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -63,6 +63,7 @@ private:
/// @param num 0 = no stereo, 1 = left eye, 2 = right eye
void view(unsigned num);
void updateStereo(float separation);
+ void updateTransforms();
SDL_Surface* screen;
unsigned int m_windowW, m_windowH;
unsigned int m_fsW, m_fsH;
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:40
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sun Feb 27 00:58:39 2011 +0100 Reworked glmath * The types are now called vec3, vec4, mat3 and mat4 (mat3 is a new one) * A more generic approach to avoid code duplication * Default matrix constructor made private (and it now initializes with zero) * Named constructors zero/identity/diagonal provided instead * Fixed func upload/get removed * All code changed to use the new style * Code that was using upload disabled in video_driver.cc --- game/3dobject.cc | 8 ++-- game/glmath.hh | 105 +++++++++++++++++++++++-------------------------- game/glshader.cc | 6 +- game/glshader.hh | 22 +++++----- game/glutil.hh | 8 ++-- game/screen_intro.cc | 2 +- game/video_driver.cc | 23 ++++++----- 7 files changed, 84 insertions(+), 90 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:31
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 27 00:41:55 2011 +0100
Remove disabled VBO code that doesn't work in GL2
---
game/glshader.cc | 27 ---------------------------
1 files changed, 0 insertions(+), 27 deletions(-)
diff --git a/game/glshader.cc b/game/glshader.cc
index e11dad7..0a656bd 100644
--- a/game/glshader.cc
+++ b/game/glshader.cc
@@ -142,7 +142,6 @@ void VertexArray::Draw(GLint mode) {
if (empty()) return;
unsigned stride = sizeof(VertexInfo);
glmath::Vec4 const* ptr = &m_vertices[0].position;
-#if 1
GLint program;
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
GLint vertPos = glGetAttribLocation(program, "vertPos");
@@ -171,31 +170,5 @@ void VertexArray::Draw(GLint mode) {
if (vertTexCoord != -1) glDisableVertexAttribArray(vertTexCoord);
if (vertNormal != -1) glDisableVertexAttribArray(vertNormal);
if (vertColor != -1) glDisableVertexAttribArray(vertColor);
-#else
- // VBO
- glmath::Vec4 const* ptr_ = NULL;
- GLuint bufferName;
- glGenBuffers(1, &bufferName);
- glBindBuffer(GL_ARRAY_BUFFER, bufferName);
- glBufferData(GL_ARRAY_BUFFER, size(), ptr, GL_STREAM_DRAW);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glVertexPointer(4, GL_FLOAT, stride, ptr_);
- glTexCoordPointer(4, GL_FLOAT, stride, ptr_ + 1);
- glNormalPointer(GL_FLOAT, stride, ptr_ + 2);
- glColorPointer(4, GL_FLOAT, stride, ptr_ + 3);
- glDrawArrays(mode, 0, size());
-
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glBindBuffer(GL_ARRAY_BUFFER, bufferName);
-#endif
}
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:24
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 27 00:39:30 2011 +0100
Build fix
---
game/CMakeLists.txt | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 3a34f6b..0482c8e 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -123,8 +123,9 @@ if(APPLE)
endif(APPLE)
if(UNIX)
- list(APPEND CMAKE_CXX_FLAGS -pthread)
- list(APPEND CMAKE_EXE_LINKER_FLAGS -pthread)
+ # Note: cannot use list APPEND here because it inserts semicolons instead of spaces
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif(UNIX)
if(MSVC)
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:17
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 27 00:36:54 2011 +0100
Shader cleanup
* Do not use fixed func transformation matrices
* Removed the "bogus" hack (the bug was caused by fixedfunc matrices being used)
* ColorMatrix no longer passed thru vertex/geometry shaders (uniform in fragment shader instead)
* Quite possibly other minor changes
---
data/shaders/core.frag | 9 +++------
data/shaders/core.vert | 19 +++++++------------
data/shaders/dancenote.vert | 27 ++++++++++-----------------
data/shaders/stereo3d.geom | 3 ---
4 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/data/shaders/core.frag b/data/shaders/core.frag
index 3d3353c..7a3f7a1 100644
--- a/data/shaders/core.frag
+++ b/data/shaders/core.frag
@@ -3,8 +3,8 @@
//DEFINES
-in float bogus; // Nvidia will overwrite the first in variable with bogus data, so as a workaround we put a bogus variable here
-in mat4 colorMat;
+uniform mat4 colorMatrix;
+
in vec3 normal;
in vec4 color;
@@ -38,9 +38,6 @@ void main() {
#ifdef ENABLE_VERTEX_COLOR
frag *= color;
#endif
- gl_FragColor = colorMat * frag;
-#ifdef ENABLE_BOGUS
- gl_FragColor += vec4(0,0,0,bogus * 1e-10)
-#endif
+ gl_FragColor = colorMatrix * frag;
}
diff --git a/data/shaders/core.vert b/data/shaders/core.vert
index f47515b..d3b5f4f 100644
--- a/data/shaders/core.vert
+++ b/data/shaders/core.vert
@@ -2,30 +2,25 @@
//DEFINES
-varying float bogus;
+uniform mat4 positionMatrix;
+uniform mat3 normalMatrix;
in vec4 vertPos;
-uniform mat4 colorMatrix;
-varying mat4 colorMat;
-
in vec4 vertTexCoord;
+in vec3 vertNormal;
+in vec4 vertColor;
+
varying vec4 texCoord;
varying vec4 vTexCoord;
-
-in vec3 vertNormal;
varying vec3 normal;
varying vec3 vNormal;
-
-in vec4 vertColor;
varying vec4 color;
varying vec4 vColor;
void main() {
- bogus = 0.0;
- colorMat = colorMatrix; // In case no geometry shader is used (otherwise it sets this)
- gl_Position = gl_ModelViewProjectionMatrix * vertPos;
+ gl_Position = positionMatrix * vertPos;
vTexCoord = texCoord = vertTexCoord;
- vNormal = normal = normalize(gl_NormalMatrix * vertNormal);
+ vNormal = normal = normalMatrix * vertNormal;
vColor = color = vertColor;
}
diff --git a/data/shaders/dancenote.vert b/data/shaders/dancenote.vert
index 4499620..6d7df82 100644
--- a/data/shaders/dancenote.vert
+++ b/data/shaders/dancenote.vert
@@ -1,15 +1,18 @@
#version 120
+uniform mat4 positionMatrix;
+uniform mat3 normalMatrix;
+uniform int noteType;
+uniform float hitAnim;
+uniform float clock;
+uniform float scale;
+uniform vec2 position;
+
in vec4 vertPos;
in vec4 vertTexCoord;
in vec3 vertNormal;
in vec4 vertColor;
-varying float bogus;
-
-uniform mat4 colorMatrix;
-varying mat4 colorMat;
-
// Per-vextex for fragment shader (if no geometry shader)
varying vec4 texCoord;
varying vec3 normal;
@@ -20,13 +23,6 @@ varying vec4 vTexCoord;
varying vec3 vNormal;
varying vec4 vColor;
-
-uniform int noteType;
-uniform float hitAnim;
-uniform float clock;
-uniform float scale;
-uniform vec2 position;
-
mat4 scaleMat(in float sc) {
return mat4(sc, 0, 0, 0,
0, sc, 0, 0,
@@ -44,10 +40,8 @@ mat4 rotMat(in float ang) {
}
void main() {
- bogus = 0.0;
- colorMat = colorMatrix; // In case no geometry shader is used (otherwise it sets this)
vTexCoord = texCoord = vertTexCoord;
- vNormal = normal = normalize(gl_NormalMatrix * vertNormal);
+ vNormal = normal = normalMatrix * vertNormal;
vColor = color = vertColor;
mat4 trans = scaleMat(scale);
@@ -81,7 +75,6 @@ void main() {
);
}
- gl_Position = gl_ModelViewProjectionMatrix * trans * vertPos;
- gl_Position += gl_ModelViewProjectionMatrix * vec4(position.xy, 0, 0);
+ gl_Position = positionMatrix * (vec4(position, 0, 0) + trans * vertPos);
}
diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom
index 5831be2..b19f19b 100644
--- a/data/shaders/stereo3d.geom
+++ b/data/shaders/stereo3d.geom
@@ -8,12 +8,10 @@ in vec4 vTexCoord[];
in vec3 vNormal[];
in vec4 vColor[];
-out mat4 colorMat;
out vec4 texCoord;
out vec3 normal;
out vec4 color;
-uniform mat4 colorMatrix;
uniform float sepFactor;
uniform float z0;
@@ -25,7 +23,6 @@ void passthru(in int i) {
}
void main() {
- colorMat = colorMatrix; // Supply color matrix for fragment shader
// Fix Nvidia compile warnings ("might be used uninitialized")
gl_Position = vec4(0);
texCoord = vec4(0);
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:45:06
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Mar 13 01:44:37 2011 +0100
Notelines fixes and cleanup
---
game/notegraph.cc | 82 ++++++++++++++++++++++++++--------------------------
1 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/game/notegraph.cc b/game/notegraph.cc
index 2424160..39f0fc8 100644
--- a/game/notegraph.cc
+++ b/game/notegraph.cc
@@ -108,6 +108,13 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
m_baseY = -0.5 * (m_min + m_max) * m_noteUnit + dimensions.yc();
m_baseX = baseLine - m_time * pixUnit + dimensions.xc(); // FIXME: Moving in X direction requires additional love (is b0rked now, keep it centered at zero)
+ // Fading notelines handing
+ if (m_songit == m_vocal.notes.end() || m_songit->begin > m_time + 3.0) m_notealpha -= 0.02f;
+ else if (m_notealpha < 1.0f) m_notealpha += 0.02f;
+ if (m_notealpha <= 0.0f) { m_notealpha = 0.0f; return; }
+
+ ColorTrans c(Color(1.0, 1.0, 1.0, m_notealpha));
+
drawNotes();
if (config["game/pitch"].b()) drawWaves(database);
@@ -120,7 +127,7 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
float hh = -m_noteUnit;
float centery = m_baseY + (it->note + 0.4) * m_noteUnit; // Star is 0.4 notes higher than current note
float centerx = x + w - (player_star_offset + 1.2) * hh; // Star is 1.2 units from end
- float rot = fmod(time * 360, 360); // They rotate!
+ float rot = fmod(time * 5.0, 2.0 * M_PI); // They rotate!
float zoom = (std::abs((rot-180) / 360.0f) * 0.8f + 0.6f) * (position == NoteGraph::TOP ? 2.3 : 2.0) * hh;
using namespace glmath;
Transform trans(translate(vec3(centerx, centery, 0.0f)) * rotate(rot, vec3(0.0f, 0.0f, 1.0f)));
@@ -136,47 +143,40 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
void NoteGraph::drawNotes() {
// Draw note lines
- if (m_songit == m_vocal.notes.end() || m_songit->begin > m_time + 3.0) m_notealpha -= 0.02f;
- else if (m_notealpha < 1.0f) m_notealpha += 0.02f;
- if (m_notealpha <= 0.0f) {
- m_notealpha = 0.0f;
- } else {
- ColorTrans c(Color(1.0, 1.0, 1.0, m_notealpha));
- m_notelines.draw(Dimensions().stretch(dimensions.w(), (m_max - m_min - 13) * m_noteUnit).middle(dimensions.xc()).center(dimensions.yc()), TexCoords(0.0, (-m_min - 7.0) / 12.0f, 1.0, (-m_max + 6.0) / 12.0f));
-
- // Draw notes
- for (Notes::const_iterator it = m_songit; it != m_vocal.notes.end() && it->begin < m_time - (baseLine - 0.5) / pixUnit; ++it) {
- if (it->type == Note::SLEEP) continue;
- double alpha = it->power;
- Texture* t1;
- Texture* t2;
- switch (it->type) {
- case Note::NORMAL: case Note::SLIDE: t1 = &m_notebar; t2 = &m_notebar_hl; break;
- case Note::GOLDEN: t1 = &m_notebargold; t2 = &m_notebargold_hl; break;
- case Note::FREESTYLE: // Freestyle notes use custom handling
- {
- Dimensions dim;
- dim.middle(m_baseX + 0.5 * (it->begin + it->end) * pixUnit).center(m_baseY + it->note * m_noteUnit).stretch((it->end - it->begin) * pixUnit, -m_noteUnit * 12.0);
- float xoffset = 0.1 * m_time / m_notebarfs.ar();
- m_notebarfs.draw(dim, TexCoords(xoffset, 0.0, xoffset + dim.ar() / m_notebarfs.ar(), 1.0));
- if (alpha > 0.0) {
- float xoffset = rand() / double(RAND_MAX);
- m_notebarfs_hl.draw(dim, TexCoords(xoffset, 0.0, xoffset + dim.ar() / m_notebarfs_hl.ar(), 1.0));
- }
+ m_notelines.draw(Dimensions().stretch(dimensions.w(), (m_max - m_min - 13) * m_noteUnit).middle(dimensions.xc()).center(dimensions.yc()), TexCoords(0.0, (-m_min - 7.0) / 12.0f, 1.0, (-m_max + 6.0) / 12.0f));
+
+ // Draw notes
+ for (Notes::const_iterator it = m_songit; it != m_vocal.notes.end() && it->begin < m_time - (baseLine - 0.5) / pixUnit; ++it) {
+ if (it->type == Note::SLEEP) continue;
+ double alpha = it->power;
+ Texture* t1;
+ Texture* t2;
+ switch (it->type) {
+ case Note::NORMAL: case Note::SLIDE: t1 = &m_notebar; t2 = &m_notebar_hl; break;
+ case Note::GOLDEN: t1 = &m_notebargold; t2 = &m_notebargold_hl; break;
+ case Note::FREESTYLE: // Freestyle notes use custom handling
+ {
+ Dimensions dim;
+ dim.middle(m_baseX + 0.5 * (it->begin + it->end) * pixUnit).center(m_baseY + it->note * m_noteUnit).stretch((it->end - it->begin) * pixUnit, -m_noteUnit * 12.0);
+ float xoffset = 0.1 * m_time / m_notebarfs.ar();
+ m_notebarfs.draw(dim, TexCoords(xoffset, 0.0, xoffset + dim.ar() / m_notebarfs.ar(), 1.0));
+ if (alpha > 0.0) {
+ float xoffset = rand() / double(RAND_MAX);
+ m_notebarfs_hl.draw(dim, TexCoords(xoffset, 0.0, xoffset + dim.ar() / m_notebarfs_hl.ar(), 1.0));
}
- continue;
- default: throw std::logic_error("Unknown note type: don't know how to render");
- }
- double x = m_baseX + it->begin * pixUnit + m_noteUnit; // left x coordinate: begin minus border (side borders -noteUnit wide)
- double ybeg = m_baseY + (it->notePrev + 1) * m_noteUnit; // top y coordinate (on the one higher note line)
- double yend = m_baseY + (it->note + 1) * m_noteUnit; // top y coordinate (on the one higher note line)
- double w = (it->end - it->begin) * pixUnit - m_noteUnit * 2.0; // width: including borders on both sides
- double h = -m_noteUnit * 2.0; // height: 0.5 border + 1.0 bar + 0.5 border = 2.0
- drawNotebar(*t1, x, ybeg, yend, w, h);
- if (alpha > 0.0) {
- ColorTrans c(Color(1.0f, 1.0f, 1.0f, alpha));
- drawNotebar(*t2, x, ybeg, yend, w, h);
}
+ continue;
+ default: throw std::logic_error("Unknown note type: don't know how to render");
+ }
+ double x = m_baseX + it->begin * pixUnit + m_noteUnit; // left x coordinate: begin minus border (side borders -noteUnit wide)
+ double ybeg = m_baseY + (it->notePrev + 1) * m_noteUnit; // top y coordinate (on the one higher note line)
+ double yend = m_baseY + (it->note + 1) * m_noteUnit; // top y coordinate (on the one higher note line)
+ double w = (it->end - it->begin) * pixUnit - m_noteUnit * 2.0; // width: including borders on both sides
+ double h = -m_noteUnit * 2.0; // height: 0.5 border + 1.0 bar + 0.5 border = 2.0
+ drawNotebar(*t1, x, ybeg, yend, w, h);
+ if (alpha > 0.0) {
+ ColorTrans c(Color(1.0f, 1.0f, 1.0f, alpha));
+ drawNotebar(*t2, x, ybeg, yend, w, h);
}
}
}
@@ -206,7 +206,7 @@ void NoteGraph::drawWaves(Database const& database) {
double oldval = getNaN();
glutil::VertexArray va;
Notes::const_iterator noteIt = m_vocal.notes.begin();
- glmath::vec4 c(p->m_color.r, p->m_color.g, p->m_color.b, m_notealpha);
+ glmath::vec4 c(p->m_color.r, p->m_color.g, p->m_color.b, 1.0);
for (; idx < endIdx; ++idx, t += Engine::TIMESTEP) {
double const freq = pitch[idx].first;
// If freq is NaN, we have nothing to process
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:44:59
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sun Mar 13 01:30:50 2011 +0100 Various guitargraph graphics fixes and major cleanup. --- game/guitargraph.cc | 429 ++++++++++++++++++++++++++------------------------- game/guitargraph.hh | 6 +- 2 files changed, 219 insertions(+), 216 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 22:57:04
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sat Mar 12 23:56:33 2011 +0100 Proper color setting stack (new operation multiplies the previous one). Text rendering no longer takes alpha parameter. --- game/dancegraph.cc | 1 - game/guitargraph.cc | 54 +++++++++++++++++++++--------------------- game/instrumentgraph.cc | 3 +- game/instrumentgraph.hh | 4 +- game/layout_singer.cc | 4 +- game/layout_singer.hh | 3 +- game/notegraph.cc | 6 ++-- game/opengl_text.cc | 17 ++++-------- game/opengl_text.hh | 4 +- game/screen_audiodevices.cc | 5 ++- game/screen_intro.cc | 15 ++++++++---- game/screen_players.cc | 3 +- game/screen_sing.cc | 6 ++-- game/screen_songs.cc | 4 +- game/screenmanager.cc | 5 ++- game/video.cc | 2 +- game/video_driver.cc | 25 +++++++++++++++---- game/video_driver.hh | 33 +++++++++++--------------- 18 files changed, 103 insertions(+), 91 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 22:56:58
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sat Mar 12 23:00:27 2011 +0100 Fixed glutil::Color + cleanup --- game/dancegraph.cc | 2 +- game/glshader.cc | 10 ++-------- game/glshader.hh | 8 ++------ game/glutil.hh | 31 ------------------------------- game/guitargraph.cc | 16 ++++++++-------- game/notegraph.cc | 2 +- game/screen_songs.cc | 12 ++++++------ game/video_driver.cc | 17 ++++++++++++----- game/video_driver.hh | 14 ++++++++++++++ 9 files changed, 46 insertions(+), 66 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 22:56:51
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sat Mar 12 22:20:27 2011 +0100 Use local perspective for popups, joinmenus, etc. --- game/dancegraph.cc | 15 +++++++-------- game/dancegraph.hh | 2 +- game/guitargraph.cc | 22 ++++++++++------------ game/guitargraph.hh | 2 +- game/instrumentgraph.cc | 18 +++++++++--------- game/instrumentgraph.hh | 39 +++++++++++++++++++-------------------- 6 files changed, 47 insertions(+), 51 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 20:40:34
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 21:39:29 2011 +0100
Fix view/projection transforms (instrument perspective)
---
game/guitargraph.cc | 7 +------
game/video_driver.cc | 32 +++++++++++++++++++++++++-------
game/video_driver.hh | 10 ++++++++++
3 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 62518f4..7395222 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -796,12 +796,7 @@ void GuitarGraph::draw(double time) {
{ // Translate, rotate and scale to place
using namespace glmath;
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
- /*
- glutil::PushMatrixMode pmm(GL_PROJECTION);
- glTranslatef(frac * offsetX, 0.0f, 0.0f);
- glutil::PushMatrixMode pmb(GL_MODELVIEW);
- glTranslatef((1.0 - frac) * offsetX, 0.0f, 0.0f);
- */
+ ViewTrans view(offsetX, 0.0, frac);
mat4 m = translate(vec3(0.0f, dimensions.y2(), 0.0f)) * rotate(g_angle, vec3(1.0f, 0.0f, 0.0f)) * scale(dimensions.w() / 5.0f);
// Do some jumping for drums
if (m_drums) {
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 5d96406..eeddf08 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -148,13 +148,7 @@ void Window::updateStereo(float sepFactor) {
}
void Window::updateTransforms() {
- // Setup the projection matrix for 2D translates
using namespace glmath;
- {
- float h = virtH();
- const float f = near_ / z0;
- g_projection = frustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, near_, far_);
- }
mat4 position = g_projection * g_modelview;
mat3 normal(g_modelview);
for (ShaderMap::iterator it = m_shaders.begin(); it != m_shaders.end(); ++it) {
@@ -169,7 +163,7 @@ void Window::updateTransforms() {
void Window::render(boost::function<void (void)> drawFunc) {
glutil::GLErrorChecker glerror("Window::render");
- updateTransforms();
+ ViewTrans trans; // Default frustum
if (s_width < screen->w || s_height < screen->h) glClear(GL_COLOR_BUFFER_BIT); // Black bars
bool stereo = config["graphic/stereo3d"].b();
int type = config["graphic/stereo3dtype"].i();
@@ -318,6 +312,30 @@ void Window::resize() {
if (s_height > 0.8f * s_width) s_height = round(0.8f * s_width);
}
+ViewTrans::ViewTrans(double offsetX, double offsetY, double frac): m_old(g_projection) {
+ // Setup the projection matrix for 2D translates
+ using namespace glmath;
+ double h = virtH();
+ const double f = near_ / z0; // z0 to nearplane conversion factor
+ // Corners of the screen at z0
+ double x1 = -0.5, x2 = 0.5;
+ double y1 = 0.5 * h, y2 = -0.5 * h;
+ // Move the perspective point by frac of offset (i.e. move the image)
+ double persX = frac * offsetX, persY = frac * offsetY;
+ x1 -= persX; x2 -= persX;
+ y1 -= persY; y2 -= persY;
+ // Perspective projection + the rest of the offset in eye (world) space
+ g_projection = frustum(f * x1, f * x2, f * y1, f * y2, near_, far_)
+ * translate(vec3(offsetX - persX, offsetY - persY, 0.0));
+ ScreenManager::getSingletonPtr()->window().updateTransforms();
+}
+
+ViewTrans::~ViewTrans() {
+ g_projection = m_old;
+ ScreenManager::getSingletonPtr()->window().updateTransforms();
+}
+
+
Transform::Transform(glmath::mat4 const& m): m_old(g_modelview) {
g_modelview = g_modelview * m;
ScreenManager::getSingletonPtr()->window().updateTransforms();
diff --git a/game/video_driver.hh b/game/video_driver.hh
index c493035..eafd93d 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -12,6 +12,7 @@ static inline float virtH() { return float(screenH()) / screenW(); }
struct SDL_Surface;
+/// Apply a transform to current modelview stack
class Transform {
public:
Transform(glmath::mat4 const& m);
@@ -20,6 +21,15 @@ private:
glmath::mat4 m_old;
};
+/// Apply a subviewport with different perspective projection
+class ViewTrans {
+public:
+ ViewTrans(double offsetX = 0.0, double offsetY = 0.0, double frac = 1.0);
+ ~ViewTrans();
+private:
+ glmath::mat4 m_old;
+};
+
/// Performs a GL transform for displaying background image at far distance
glmath::mat4 farTransform();
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 19:34:16
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 20:25:06 2011 +0100
All FixedFunc transform stuff removed (gl2cleanup)
---
game/3dobject.hh | 5 ++---
game/dialog.hh | 8 ++++----
game/glutil.hh | 14 --------------
game/guitargraph.cc | 18 ++++++++++--------
game/instrumentgraph.cc | 3 +--
game/instrumentgraph.hh | 4 ++--
game/notegraph.cc | 5 ++---
game/screen_sing.cc | 4 ++--
8 files changed, 23 insertions(+), 38 deletions(-)
diff --git a/game/3dobject.hh b/game/3dobject.hh
index 1479c3b..5ce33f5 100644
--- a/game/3dobject.hh
+++ b/game/3dobject.hh
@@ -33,9 +33,8 @@ class Object3d: boost::noncopyable {
void drawVBO();
/// draws the object
void draw(float x = 0, float y = 0, float z = 0, float s = 1.0) {
- glutil::PushMatrix pm;
- glTranslatef(x, y, z); // Move to position
- if (s != 1.0) glScalef(s,s,s); // Scale if needed
+ using namespace glmath;
+ Transform trans(translate(vec3(x, y, z)) * scale(s)); // Move to position and scale
if (m_texture) {
UseTexture tex(*m_texture);
drawVBO();
diff --git a/game/dialog.hh b/game/dialog.hh
index b3e63a8..b33c1b3 100644
--- a/game/dialog.hh
+++ b/game/dialog.hh
@@ -1,9 +1,9 @@
#pragma once
-#include "opengl_text.hh"
+#include "configuration.hh"
#include "fs.hh"
+#include "opengl_text.hh"
#include "surface.hh"
-#include "configuration.hh"
/// class for printing dialogues
class Dialog {
@@ -18,8 +18,8 @@ class Dialog {
}
/// draws dialogue
void draw() {
- glutil::PushMatrix pm;
- glTranslatef(0.0f, 0.0f, 0.1f); // Raise a bit in 3D
+ using namespace glmath;
+ Transform(translate(vec3(0.0f, 0.0f, 0.1f))); // Raise a bit in 3D
m_dialog.draw();
m_svgText.draw(m_text);
}
diff --git a/game/glutil.hh b/game/glutil.hh
index f36cf91..9b737ff 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -13,20 +13,6 @@ glmath::mat4& getColorMatrix(); ///< A temporary hack for global access to the
namespace glutil {
/// wrapper struct for RAII
- struct PushMatrix {
- PushMatrix() { glPushMatrix(); }
- ~PushMatrix() { glPopMatrix(); }
- };
-
- /// wrapper struct for RAII
- struct PushMatrixMode {
- PushMatrixMode(GLenum mode) { glGetIntegerv(GL_MATRIX_MODE, &m_old); glMatrixMode(mode); glPushMatrix(); }
- ~PushMatrixMode() { glPopMatrix(); glMatrixMode(m_old); }
- private:
- GLint m_old;
- };
-
- /// wrapper struct for RAII
struct UseDepthTest {
/// enable depth test (for 3d objects)
UseDepthTest() {
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 38ada22..62518f4 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -23,7 +23,7 @@ namespace {
const size_t diffsz = sizeof(diffv) / sizeof(*diffv);
const int death_delay = 20; // Delay in notes after which the player is hidden
const float join_delay = 3.0f; // Time after join menu before playing when joining mid-game
- const float g_angle = 80.0f; // How much to rotate the fretboards
+ const float g_angle = 1.4f; // How many radians to rotate the fretboards
const float past = -0.2f; // Relative time from cursor that is considered past (out of screen)
const float future = 1.5f; // Relative time from cursor that is considered future (out of screen)
const float timescale = 25.0f; // Multiplier to get graphics units from time
@@ -794,20 +794,22 @@ void GuitarGraph::draw(double time) {
float ng_r = 0, ng_g = 0, ng_b = 0; // neck glow color components
int ng_ccnt = 0; // neck glow color count
{ // Translate, rotate and scale to place
+ using namespace glmath;
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
+ /*
glutil::PushMatrixMode pmm(GL_PROJECTION);
glTranslatef(frac * offsetX, 0.0f, 0.0f);
glutil::PushMatrixMode pmb(GL_MODELVIEW);
- glTranslatef((1.0 - frac) * offsetX, dimensions.y2(), 0.0f);
+ glTranslatef((1.0 - frac) * offsetX, 0.0f, 0.0f);
+ */
+ mat4 m = translate(vec3(0.0f, dimensions.y2(), 0.0f)) * rotate(g_angle, vec3(1.0f, 0.0f, 0.0f)) * scale(dimensions.w() / 5.0f);
// Do some jumping for drums
if (m_drums) {
float jumpanim = m_drumJump.get();
if (jumpanim == 1.0) m_drumJump.setTarget(0.0);
- if (jumpanim > 0) glTranslatef(0.0f, -m_drumJump.get() * 0.01, 0.0f);
+ if (jumpanim > 0) m = translate(vec3(0.0f, -m_drumJump.get() * 0.01, 0.0f)) * m;
}
- glRotatef(g_angle, 1.0f, 0.0f, 0.0f);
- float temp_s = dimensions.w() / 5.0f;
- glScalef(temp_s, temp_s, temp_s);
+ Transform trans(m);
// Draw the neck
{
@@ -1156,8 +1158,8 @@ void GuitarGraph::drawDrumfill(float tBeg, float tEnd) {
void GuitarGraph::drawInfo(double time, double offsetX, Dimensions dimensions) {
// Draw info
if (!menuOpen()) {
- glutil::PushMatrix mat;
- glTranslatef(0.0f, 0.0f, -0.5f);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0f, 0.0f, -0.5f)));
float xcor = 0.35 * dimensions.w();
float h = 0.075 * 2.0 * dimensions.w();
// Hack to show the scores better when there is more space (1 instrument)
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index 95de035..5a7aca9 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -75,10 +75,9 @@ void InstrumentGraph::drawMenu() {
// Some helper vars
ThemeInstrumentMenu& th = *m_menuTheme;
MenuOptions::const_iterator cur = static_cast<MenuOptions::const_iterator>(&m_menu.current());
- glutil::PushMatrix pm; // Save scaling state
double w = m_menu.dimensions.w();
const float s = std::min(m_width.get(), 0.5) / w;
- glScalef(s, s, 1.0f);
+ Transform trans(glmath::scale(s)); // Fit better menu on screen
// We need to multiply offset by inverse scale factor to keep it always constant
// All these vars are ultimately affected by the scaling matrix
const double offsetX = 0.5f * (dimensions.x1() + dimensions.x2()) / s;
diff --git a/game/instrumentgraph.hh b/game/instrumentgraph.hh
index 85d3585..fe6d0d4 100644
--- a/game/instrumentgraph.hh
+++ b/game/instrumentgraph.hh
@@ -34,8 +34,8 @@ class Popup {
glutil::Color color(m_color);
m_popupText->render(m_msg);
{
- glutil::PushMatrix mat;
- glTranslatef(0.0f, 0.0f, 0.5f * anim);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0f, 0.0f, 0.5f * anim)));
m_popupText->dimensions().center(0.1 - 0.03 * anim).middle(offsetX).stretch(0.2f, 0.2f);
m_popupText->draw();
}
diff --git a/game/notegraph.cc b/game/notegraph.cc
index f012ea8..f3c36e1 100644
--- a/game/notegraph.cc
+++ b/game/notegraph.cc
@@ -122,9 +122,8 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
float centerx = x + w - (player_star_offset + 1.2) * hh; // Star is 1.2 units from end
float rot = fmod(time * 360, 360); // They rotate!
float zoom = (std::abs((rot-180) / 360.0f) * 0.8f + 0.6f) * (position == NoteGraph::TOP ? 2.3 : 2.0) * hh;
- glutil::PushMatrix pm;
- glTranslatef(centerx, centery, 0.0f);
- glRotatef(rot, 0.0f, 0.0f, 1.0f);
+ using namespace glmath;
+ Transform trans(translate(vec3(centerx, centery, 0.0f)) * rotate(rot, vec3(0.0f, 0.0f, 1.0f)));
{
glutil::Color c(Color(it_col->r, it_col->g, it_col->b, it_col->a));
m_star_hl.draw(Dimensions().stretch(zoom*1.2, zoom*1.2).center().middle(), TexCoords());
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index f4c0d0a..fb3bc43 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -646,8 +646,8 @@ ScoreWindow::ScoreWindow(Instruments& instruments, Database& database, Dancers&
}
void ScoreWindow::draw() {
- glutil::PushMatrix block;
- glTranslatef(0.0, m_pos.get(), 0.0);
+ using namespace glmath;
+ Transform trans(translate(vec3(0.0, m_pos.get(), 0.0)));
m_bg.draw();
const double spacing = 0.1 + 0.1 / m_database.scores.size();
unsigned i = 0;
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-12 18:43:51
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Mar 12 19:43:37 2011 +0100
Fix FarTransform
---
game/screen_sing.cc | 2 +-
game/screen_songs.cc | 2 +-
game/video_driver.cc | 6 +++---
game/video_driver.hh | 7 +------
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 335fead..f4c0d0a 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -426,7 +426,7 @@ void ScreenSing::draw() {
// Rendering starts
{
- FarTransform ft;
+ Transform ft(farTransform());
double ar = arMax;
// Background image
if (m_background) {
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index 2bbc520..da69c36 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -148,7 +148,7 @@ void ScreenSongs::drawJukebox() {
void ScreenSongs::drawMultimedia() {
{
- FarTransform ft; // 3D effect
+ Transform ft(farTransform()); // 3D effect
double length = m_audio.getLength();
double time = clamp(m_audio.getPosition() - config["audio/video_delay"].f(), 0.0, length);
m_songbg_default->draw(); // Default bg
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 356deaf..5d96406 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -328,11 +328,11 @@ Transform::~Transform() {
ScreenManager::getSingletonPtr()->window().updateTransforms();
}
-FarTransform::FarTransform() {
+glmath::mat4 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.0 + 2.0 * getSeparation(); // A bit more for stereo3d (avoid black borders)
- glTranslatef(0.0f, 0.0f, -z + z0); // Very near the farplane
- glScalef(s, s, s);
+ using namespace glmath;
+ return translate(vec3(0.0f, 0.0f, -z + z0)) * scale(s); // Very near the farplane
}
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 8bb7eef..c493035 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -21,12 +21,7 @@ private:
};
/// Performs a GL transform for displaying background image at far distance
-class FarTransform {
-public:
- FarTransform();
-private:
- glutil::PushMatrix pm;
-};
+glmath::mat4 farTransform();
/// handles the window
class Window {
|