diff options
Diffstat (limited to 'src/client/view.cc')
-rw-r--r-- | src/client/view.cc | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/src/client/view.cc b/src/client/view.cc index 8754549..8881ac2 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -22,14 +22,14 @@ namespace client ShipDrawer *shipdrawer = 0; StarDrawer *stardrawer = 0; -game::Ship *target =0; // the view's target +game::Ship *target = 0; // the view's target void View::init() { // draw scene if (!shipdrawer) { - stardrawer = new StarDrawer(&game::star); - shipdrawer = new ShipDrawer(&game::ship); - target = &game::ship; + stardrawer = new StarDrawer(&game.star); + shipdrawer = new ShipDrawer(&game.ship); + target = &game.ship; } } @@ -43,28 +43,47 @@ void View::shutdown() } void View::reset() { - // Change to the projection matrix and set our viewing volume. - gl::matrixmode( GL_PROJECTION ); - gl::loadidentity(); + // Our shading model--Gouraud (smooth). + gl::shademodel(GL_SMOOTH); + + // Culling + gl::cullface( GL_BACK ); + gl::frontface(GL_CCW ); +} + + +void View::draw_world(float elapsed) +{ + + gl::enable( GL_CULL_FACE ); + + // Depth buffer writing + gl::depthmask(GL_TRUE); + gl::enable(GL_DEPTH_TEST); + + // draw the world + gl::push(); + + gl::translate(game.ship.location - target->location); + gl::scale(0.2f, 0.2f, 0.2f); + shipdrawer->draw(elapsed); + gl::pop(); + + gl::push(); + gl::translate(game.star.location - target->location); + stardrawer->draw(elapsed); + gl::pop(); + + gl::disable( GL_CULL_FACE ); - //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 ); - const float frustumsize=0.5f; - gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f); - /* - map world coordinates to GL coordinates - - The world coordinates are identical to GL coordinates, - but the default viewing pitch (0 degrees) - is the positive X-axis - */ - gl::rotate(90.0f, 0, 1.0, 0); } void View::draw_background(float elapsed) { using namespace gl; -// // // enable Alpha blending + // enable Alpha blending + gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl::enable(GL_BLEND); // galactic axis @@ -109,23 +128,7 @@ void View::draw_background(float elapsed) end(); gl::disable(GL_BLEND); -} - -void View::draw_world(float elapsed) -{ - // draw the world - gl::push(); - - gl::translate(game::ship.location - target->location); - gl::scale(0.2f, 0.2f, 0.2f); - shipdrawer->draw(elapsed); - gl::pop(); - - gl::push(); - gl::translate(game::star.location - target->location); - stardrawer->draw(elapsed); - gl::pop(); - + gl::disable(GL_DEPTH_TEST); } void View::draw(float elapsed) @@ -133,10 +136,20 @@ void View::draw(float elapsed) // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - // We don't want to modify the projection matrix. - gl::matrixmode( GL_MODELVIEW ); + // Change to the projection matrix and set our viewing volume. + gl::matrixmode( GL_PROJECTION ); gl::loadidentity(); + //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 ); + const float frustumsize = 0.5f; + gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f); + + + gl::matrixmode( GL_MODELVIEW ); + + gl::loadidentity(); + gl::rotate(90.0f, 0, 1.0, 0); + // Camera transformation camera.draw(elapsed); @@ -146,7 +159,14 @@ void View::draw(float elapsed) // draw the semi-static background draw_background(elapsed); - SDL_GL_SwapBuffers(); + // draw the console + //gl::matrixmode( GL_PROJECTION ); + //gl::loadidentity(); + + gl::matrixmode( GL_MODELVIEW ); + gl::loadidentity(); + + console.draw(); } } // namespace view |