Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-04 00:54:30 +0000
committerStijn Buys <ingar@osirion.org>2008-02-04 00:54:30 +0000
commit840f9b8678f607aecc15d47bc77248c4ac8b8574 (patch)
treef90688ca7afabb8e4123e1a811dd168a86717a3c /src/client/view.cc
parent43b994017a560a2fa97894ebfe121375d6614b6f (diff)
tweaked console
client status with timer and fps core connect/disconnect
Diffstat (limited to 'src/client/view.cc')
-rw-r--r--src/client/view.cc158
1 files changed, 117 insertions, 41 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
index 3b5f785..1dd0df6 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -12,6 +12,11 @@
#include "sys/sys.h"
#include "math/mathlib.h"
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+
using namespace render;
namespace client
@@ -41,25 +46,26 @@ void View::shutdown()
}
void View::reset() {
- // Our shading model--Gouraud (smooth).
+ // shading model: Gouraud (smooth).
gl::shademodel(GL_SMOOTH);
- // Culling
+ // culling
gl::cullface( GL_BACK );
gl::frontface(GL_CCW );
+ // alpha-blending
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ gl::disable(GL_BLEND);
+
+ // depth
+ gl::depthmask(GL_TRUE);
+ gl::disable(GL_DEPTH_TEST);
+ gl::disable( GL_CULL_FACE );
}
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();
@@ -73,17 +79,11 @@ void View::draw_world(float elapsed)
stardrawer->draw(elapsed);
gl::pop();
- gl::disable( GL_CULL_FACE );
-
}
void View::draw_background(float elapsed)
{
using namespace gl;
-
- // enable Alpha blending
- gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- gl::enable(GL_BLEND);
// galactic axis
begin(Lines);
@@ -125,42 +125,107 @@ void View::draw_background(float elapsed)
vertex(gridsize-dx, y, i-dz);
}
end();
-
- gl::disable(GL_BLEND);
- gl::disable(GL_DEPTH_TEST);
}
-void View::draw(float elapsed)
+void View::draw_loader()
{
- // Clear the color and depth buffers.
- gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ gl::enable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga
+ gl::color(1.0f, 1.0f, 1.0f, 1.0f);
+
+ gl::begin(gl::Quads);
+
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(0,0, 0);
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(video.width,0,0);
- // Change to the projection matrix and set our viewing volume.
- gl::matrixmode( GL_PROJECTION );
- gl::loadidentity();
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(video.width,video.height,0);
- //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 );
- const float frustumsize = 0.5f;
- x = -frustumsize * video.ratio;
- width = video.ratio;
- y = -frustumsize;
- height = 1;
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(0,video.height,0);
+ gl::end();
- //gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f);
- gl::frustum(x, x+width, y, y +height, 1.0f, 1024.0f);
+ gl::disable(GL_TEXTURE_2D);
+}
- gl::matrixmode( GL_MODELVIEW );
- gl::loadidentity();
- gl::rotate(90.0f, 0, 1.0, 0);
+void View::draw_status()
+{
+ using namespace std;
+
+ if (console.visible())
+ return;
+
+ glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga
+ gl::enable(GL_TEXTURE_2D);
+
+ // print the status in the upper left corner
+ gl::color(1.0f, 1.0f, 1.0f, 1.0f);
+ std::stringstream status;
- // Camera transformation
- camera.draw(elapsed);
+ int hours = (int) sys::time() / 3600;
+ int minutes = (int) (sys::time() - 3600*hours) / 60;
+ int seconds = (int) (sys::time() - 3600*hours - 60 *minutes);
+ status << " clock " << setfill('0') << setw(2) << hours << ":"
+ << setfill('0') << setw(2) << minutes << ":"
+ << setfill('0') << setw(2) << seconds;
+
+ minutes = (int) floorf(core::time() / 60.0f);
+ seconds = (int) floorf(core::time() - (float) minutes* 60.0f);
+
+ status << " time " << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds;
+ status << " fps " << setw(4) << client::fps();
+ draw_text(0, 4, status);
+
+ // print the version number in the upper right corner
+ gl::color(0.0f, 1.0f, 0.0f, 1.0f);
+ std::string version("ver. ");
+ version.append(VERSION);
+ draw_text(video.width-(version.size()+1)*CHARWIDTH, 4, version);
+
+ gl::disable(GL_TEXTURE_2D);
+}
- // draw the world
- draw_world(elapsed);
+void View::frame(float seconds)
+{
+ // Clear the color and depth buffers.
+ gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ if (core::connected()) {
+ // draw the game world
+
+ // Change to the projection matrix and set our viewing volume.
+ gl::matrixmode( GL_PROJECTION );
+ gl::loadidentity();
+
+ const float frustumsize = 0.5f;
+ x = -frustumsize * video.ratio;
+ width = video.ratio;
+ y = -frustumsize;
+ height = 1;
+ gl::frustum(x, x+width, y, y +height, 1.0f, 1024.0f);
+
+ gl::matrixmode( GL_MODELVIEW );
+ gl::loadidentity();
+ gl::rotate(90.0f, 0, 1.0, 0);
- // draw the semi-static background
- draw_background(elapsed);
+ // Camera transformation
+ camera.draw(seconds);
+
+ gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
+ gl::enable(GL_CULL_FACE); // enable culling
+
+ draw_world(seconds); // draw the world
+
+ gl::disable(GL_CULL_FACE); // disable culling
+ gl::enable(GL_BLEND); // enable alpha blending
+
+ draw_background(seconds); // draw the spacegrid
+
+ gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
+ }
// switch to ortographic projection to draw the GUI
gl::matrixmode( GL_PROJECTION );
@@ -169,9 +234,20 @@ void View::draw(float elapsed)
gl::matrixmode( GL_MODELVIEW );
gl::loadidentity();
+
+ if (!core::connected()) {
+ // draw the loader bitmap
+ draw_loader();
+ gl::enable(GL_BLEND); // enable alpha blending
+ }
// draw the console
console.draw();
+
+ // draw the status line
+ draw_status();
+
+ gl::disable(GL_BLEND);
}
} // namespace view