diff options
-rw-r--r-- | engine/background.cpp | 37 | ||||
-rw-r--r-- | engine/background.h | 9 | ||||
-rw-r--r-- | engine/engine.cpp | 43 | ||||
-rw-r--r-- | engine/stage.cpp | 13 | ||||
-rw-r--r-- | engine/stage.h | 3 |
5 files changed, 63 insertions, 42 deletions
diff --git a/engine/background.cpp b/engine/background.cpp new file mode 100644 index 0000000..076c6cf --- /dev/null +++ b/engine/background.cpp @@ -0,0 +1,37 @@ +#include "background.h" + +#include <SDL/SDL_opengl.h> +#include <cmath> + +void Background::draw() { + 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(); + + static float f = 0.0; + f += 0.01; + + 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) + glColor3f(1, 1, 1); + else + glColor3f(.5, .5, .5); + glVertex3f(i, 0, -10); + glVertex3f(i, 0, 10); + glVertex3f(-10, 0, i); + glVertex3f(10, 0, i); + } + glEnd(); +} diff --git a/engine/background.h b/engine/background.h new file mode 100644 index 0000000..4c294c8 --- /dev/null +++ b/engine/background.h @@ -0,0 +1,9 @@ +#ifndef BACKGROUND_H +#define BACKGROUND_H + +class Background { + public: + void draw(); +}; + +#endif diff --git a/engine/engine.cpp b/engine/engine.cpp index 2e681e7..e67ead3 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -101,51 +101,10 @@ void Engine::update() { float v_w = Config::window_h * Config::viewport_w; float v_h = Config::window_h * Config::viewport_h; - glViewport( - v_x - v_w * 0.5, - v_y - v_h * 0.5, - v_w * 2, - v_h * 2); + glViewport(v_x - v_w * 0.5, v_y - v_h * 0.5, v_w * 2, v_h * 2); glScissor(v_x, v_y, v_w, v_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(); - - float f = tick * 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) - glColor3f(1, 1, 1); - else - glColor3f(.5, .5, .5); - glVertex3f(i, 0, -10); - glVertex3f(i, 0, 10); - glVertex3f(-10, 0, i); - glVertex3f(10, 0, i); - } - glEnd(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-0.5, 1.5, -Config::viewport_aspect * 0.5, Config::viewport_aspect * 1.5, 0, 10); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - stage->draw(); glDisable(GL_SCISSOR_TEST); diff --git a/engine/stage.cpp b/engine/stage.cpp index 39cf52a..6bcd622 100644 --- a/engine/stage.cpp +++ b/engine/stage.cpp @@ -1,11 +1,15 @@ #include "stage.h" +#include "config.h" + #include <wriggle/texturesdl.h> #include <SDL/SDL_opengl.h> #include <cmath> Stage::Stage() { + background = new Background(); + player = new Player(); texture = new TextureSDL("textures/shot1.png"); @@ -37,6 +41,15 @@ void Stage::update() { } void Stage::draw() { + background->draw(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 1.5, -Config::viewport_aspect * 0.5, Config::viewport_aspect * 1.5, 0, 10); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + player->draw(); for(std::vector<Enemy*>::iterator it = enemy_list.begin(); it < enemy_list.end(); it++) { diff --git a/engine/stage.h b/engine/stage.h index bc687da..a53b5fd 100644 --- a/engine/stage.h +++ b/engine/stage.h @@ -1,6 +1,7 @@ #ifndef STAGE_H #define STAGE_H +#include "background.h" #include "player.h" #include <wriggle/shader.h> #include <wriggle/texture.h> @@ -11,6 +12,8 @@ class Stage { private: + Background* background; + Player* player; GLShaderProgram* shader; |