summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 00:51:01 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 00:51:01 +0200
commitca56469cbb3ebf77dba433da9b23698ff5138a3d (patch)
tree01e6d6d2dc32fff88b8ed9ca47436dfb833c58e9
parentd991499bd4ac6debef314ce9d870687e2d283627 (diff)
Added background.
-rw-r--r--application.cpp92
-rw-r--r--application.h1
-rw-r--r--background.pngbin0 -> 13359 bytes
-rw-r--r--config.h14
4 files changed, 63 insertions, 44 deletions
diff --git a/application.cpp b/application.cpp
index b9a6173..87797b1 100644
--- a/application.cpp
+++ b/application.cpp
@@ -143,6 +143,7 @@ void Application::run() {
font = new FTPixmapFont("VeraMono.ttf");
font->FaceSize(12);
+ background = new TextureSDL("background.png");
texture = new TextureSDL("foo4.png");
shader = new GLShaderProgram();
@@ -185,8 +186,53 @@ void Application::run() {
}
void Application::main_loop(unsigned int tick, unsigned int step) {
+ if(!paused) {
+ elapsed += step;
+ for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
+ (*it)->update(elapsed, step);
+ }
+ }
+
+ glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glViewport(0, 0, Config::window_w, Config::window_h);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, Config::window_w, 0, Config::window_h, 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);
+ glTexCoord2f(1, 0);
+ glVertex2i(Config::window_w, 0);
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+ glColor4f(0, 0, 0, 1);
+
+ char s[0xff];
+
+ if(tick - lastframes >= 1000) {
+ fps = (float)frames * ((float)(tick - lastframes) / 1000.0f);
+ frames = 1;
+ lastframes = tick;
+ } else {
+ frames++;
+ }
+ snprintf(s, 0xff, "FPS: %.2f", fps);
+ glRasterPos2f(Config::fps_x, Config::fps_y);
+ font->Render(s);
+
glViewport(
Config::viewport_x - Config::viewport_overscan,
Config::viewport_y - Config::viewport_overscan,
@@ -194,28 +240,24 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
Config::viewport_h + Config::viewport_overscan * 2);
glScissor(Config::viewport_x, Config::viewport_y, Config::viewport_w, Config::viewport_h);
glEnable(GL_SCISSOR_TEST);
-
+
+ glClearColor(0.2, 0.2, 0.2, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (float)660 / (float)740, 1, 100);
-
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- if(!paused) {
- elapsed += step;
- for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
- (*it)->update(elapsed, step);
- }
- }
-
float f = elapsed * 0.0005;
gluLookAt(
5 * sinf(f), 1, 5 * cosf(f),
0, 0, 0,
5 * sinf(f), 2, 5 * cosf(f));
-
+
glBegin(GL_LINES);
for(int i = -10; i < 11; i++) {
if(i % 5 == 0)
@@ -228,7 +270,7 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
glVertex3f(10, 0, i);
}
glEnd();
-
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(
@@ -237,10 +279,10 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
-float(Config::viewport_overscan) / float(Config::viewport_h),
Config::viewport_aspect + float(Config::viewport_overscan) / float(Config::viewport_h),
0, 10);
-
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
+
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
shader->use();
@@ -256,33 +298,9 @@ void Application::main_loop(unsigned int tick, unsigned int step) {
bp->draw();
}
- glDisable(GL_TEXTURE_2D);
glUseProgram(0);
glDisable(GL_SCISSOR_TEST);
- glViewport(0, 0, Config::window_w, Config::window_h);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, Config::window_w, 0, Config::window_h, 0, 10);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glColor4f(1, 1, 1, 1);
-
- char s[0xff];
-
- if(tick - lastframes >= 1000) {
- fps = (float)frames * ((float)(tick - lastframes) / 1000.0f);
- frames = 1;
- lastframes = tick;
- } else {
- frames++;
- }
- snprintf(s, 0xff, "FPS: %.2f", fps);
- glRasterPos2f(Config::fps_x, Config::fps_y);
- font->Render(s);
SDL_GL_SwapBuffers();
}
diff --git a/application.h b/application.h
index e40af07..1378be6 100644
--- a/application.h
+++ b/application.h
@@ -22,6 +22,7 @@ class Application {
float fps;
FTFont* font;
+ Texture* background;
Texture* texture;
GLShaderProgram* shader;
diff --git a/background.png b/background.png
new file mode 100644
index 0000000..a97cc05
--- /dev/null
+++ b/background.png
Binary files differ
diff --git a/config.h b/config.h
index fdab6e2..cb69153 100644
--- a/config.h
+++ b/config.h
@@ -2,19 +2,19 @@
#define CONFIG_H
namespace Config {
- const unsigned int window_w = 1280;
- const unsigned int window_h = 720;
+ const unsigned int window_w = 1920;
+ const unsigned int window_h = 1080;
- const unsigned int viewport_x = 20;
- const unsigned int viewport_y = 20;
- const unsigned int viewport_w = 600;
- const unsigned int viewport_h = 680;
+ 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 unsigned int viewport_overscan = 10;
const float viewport_aspect = float(viewport_h) / float(viewport_w);
- const unsigned int fps_x = 641;
+ const unsigned int fps_x = 1;
const unsigned int fps_y = 1;
};