summaryrefslogtreecommitdiff
path: root/application.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'application.cpp')
-rw-r--r--application.cpp92
1 files changed, 55 insertions, 37 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();
}