summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 18:00:25 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 18:00:25 +0200
commit88b1e9e505dad78fd2c3ff927495d322b11491ca (patch)
treebc1a13c3204a6fea70a56344f949c56d2efbd854
parent2626d880a58b99ff70e43f36575517c3fbb2c7b9 (diff)
Added support for multiple resolutions.
-rw-r--r--application.cpp40
-rw-r--r--config.h16
-rw-r--r--player.cpp4
-rw-r--r--textures/background.pngbin13359 -> 18092 bytes
4 files changed, 33 insertions, 27 deletions
diff --git a/application.cpp b/application.cpp
index ebf412d..2ef8e79 100644
--- a/application.cpp
+++ b/application.cpp
@@ -203,25 +203,26 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, Config::window_w, 0, Config::window_h, 0, 10);
+ float xo = float(Config::window_w)/float(Config::window_h)/2.5 - 0.5;
+ glOrtho(-xo, 1 + xo, 0, 0.8, 0, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, background->tex());
glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2i(0, 0);
glTexCoord2f(0, 1);
- glVertex2i(0, Config::window_h);
- glTexCoord2f(1, 1);
- glVertex2i(Config::window_w, Config::window_h);
+ glVertex2f(-1.9/9.0, 0);
+ glTexCoord2f(0, 0);
+ glVertex2f(-1.9/9.0, 0.8);
glTexCoord2f(1, 0);
- glVertex2i(Config::window_w, 0);
+ glVertex2f(10.9/9.0, 0.8);
+ glTexCoord2f(1, 1);
+ glVertex2f(10.9/9.0, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
- glColor4f(0, 0, 0, 1);
+ glColor4f(1, 1, 0, 1);
char s[0xff];
@@ -236,12 +237,17 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
glRasterPos2f(Config::fps_x, Config::fps_y);
font->Render(s);
+ float v_x = Config::window_w * (Config::viewport_x + xo) / (1 + 2 * xo);
+ float v_y = Config::window_h * Config::viewport_y;
+ float v_w = Config::window_h * Config::viewport_w;
+ float v_h = Config::window_h * Config::viewport_h;
+
glViewport(
- Config::viewport_x - Config::viewport_overscan,
- Config::viewport_y - Config::viewport_overscan,
- Config::viewport_w + Config::viewport_overscan * 2,
- Config::viewport_h + Config::viewport_overscan * 2);
- glScissor(Config::viewport_x, Config::viewport_y, Config::viewport_w, Config::viewport_h);
+ v_x - Config::viewport_overscan,
+ v_y - Config::viewport_overscan,
+ v_w + Config::viewport_overscan * 2,
+ v_h + Config::viewport_overscan * 2);
+ glScissor(v_x, v_y, v_w, v_h);
glEnable(GL_SCISSOR_TEST);
glClearColor(0.2, 0.2, 0.2, 0);
@@ -277,10 +283,10 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(
- -float(Config::viewport_overscan) / float(Config::viewport_w),
- 1.0 + float(Config::viewport_overscan) / float(Config::viewport_w),
- -float(Config::viewport_overscan) / float(Config::viewport_w),
- Config::viewport_aspect + float(Config::viewport_overscan) / float(Config::viewport_w),
+ -float(Config::viewport_overscan) / float(v_w),
+ 1.0 + float(Config::viewport_overscan) / float(v_w),
+ -float(Config::viewport_overscan) / float(v_w),
+ Config::viewport_aspect + float(Config::viewport_overscan) / float(v_w),
0, 10);
glMatrixMode(GL_MODELVIEW);
diff --git a/config.h b/config.h
index cb69153..6884b1a 100644
--- a/config.h
+++ b/config.h
@@ -2,20 +2,20 @@
#define CONFIG_H
namespace Config {
- const unsigned int window_w = 1920;
- const unsigned int window_h = 1080;
+ const unsigned int window_w = 1280;
+ const unsigned int window_h = 800;
- const unsigned int viewport_x = 300;
- const unsigned int viewport_y = 15;
- const unsigned int viewport_w = 900;
- const unsigned int viewport_h = 1050;
+ const float viewport_x = 15.0 / 1080.0;
+ const float viewport_y = 15.0 / 1080.0;
+ const float viewport_w = 900.0 / 1080.0;
+ const float viewport_h = 1050.0 / 1080.0;
const unsigned int viewport_overscan = 10;
const float viewport_aspect = float(viewport_h) / float(viewport_w);
- const unsigned int fps_x = 1;
- const unsigned int fps_y = 1;
+ const float fps_x = 0.0;
+ const float fps_y = 0.0;
};
#endif
diff --git a/player.cpp b/player.cpp
index 3db0237..4a159ca 100644
--- a/player.cpp
+++ b/player.cpp
@@ -44,6 +44,6 @@ void Player::update() {
y_speed /= sqrtf(2);
}
- x = fmaxf(fminf(x + x_speed, 1.0 - 16.0 / Config::viewport_w), 16.0 / Config::viewport_w);
- y = fmaxf(fminf(y + y_speed, Config::viewport_aspect - 16.0 / Config::viewport_h), 16.0 / Config::viewport_h);
+ x = fmaxf(fminf(x + x_speed, 1.0 - 0.018), 0.018);
+ y = fmaxf(fminf(y + y_speed, Config::viewport_aspect - 0.018), 0.018);
}
diff --git a/textures/background.png b/textures/background.png
index a97cc05..c7c0f8d 100644
--- a/textures/background.png
+++ b/textures/background.png
Binary files differ