From eb075660e7cb61b138c2da337115c59857f89e17 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 16 Jul 2008 22:55:07 +0000 Subject: network protocol cleanup, radar test (doesn't work) --- src/client/console.cc | 1 + src/client/keyboard.cc | 4 +- src/client/radar.cc | 36 +++++++++++++- src/client/view.cc | 131 ++++++++++++++++++++++++++----------------------- 4 files changed, 107 insertions(+), 65 deletions(-) (limited to 'src/client') diff --git a/src/client/console.cc b/src/client/console.cc index b52f8a0..7bb1aaf 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -69,6 +69,7 @@ void Console::clear() } void Console::draw() { + flush(); if (visible()) draw_console(); else diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index 83d31e8..be2240a 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -315,7 +315,7 @@ void Keyboard::add_key(const char *name, const unsigned int keysym, const char a void Keyboard::list_keys() { for (iterator it = begin(); it != end(); it++) { - con_print << " " << aux::spaces((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl; + con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl; } con_print << keys.size() << " keys" << std::endl; } @@ -325,7 +325,7 @@ void Keyboard::list_binds() size_t n =0; for (iterator it = begin(); it != end(); it++) { if ((*it).second->bind().size()) { - con_print << " " << aux::spaces((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl; + con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl; n++; } } diff --git a/src/client/radar.cc b/src/client/radar.cc index cc4257e..cdf5391 100644 --- a/src/client/radar.cc +++ b/src/client/radar.cc @@ -4,14 +4,48 @@ the terms of the GNU General Public License version 2 */ +#include "auxiliary/functions.h" #include "core/core.h" #include "client/radar.h" #include "client/video.h" #include "render/draw.h" #include "render/render.h" +#include "render/text.h" + namespace client { +void Radar::draw() { + using namespace render; + + if (!core::localcontrol()) + return; + + float y = 4 + Text::fontheight(); + Text::draw(4, y, "^N------------ ^BRadar test ^N--------------"); + y += Text::fontheight(); + + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + + std::map::iterator it; + for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + core::ClientState *state = entity->state(); + + if (state && state->targetable() && entity->label().size()) { + gl::color(entity->color()); + std::ostringstream line; + line << aux::pad_right(entity->name(), 24) << + state->state_screenlocation[0] << " " << + state->state_screenlocation[1] << " " << + state->state_screenlocation[2] << " "; + Text::draw(4, y, line.str()); + y += Text::fontheight(); + } + } + +} +/* void Radar::draw() { using namespace render; @@ -75,5 +109,5 @@ void Radar::draw() glDisableClientState(GL_NORMAL_ARRAY); //glDisableClientState(GL_COLOR_ARRAY); } - +*/ } diff --git a/src/client/view.cc b/src/client/view.cc index 2bbae15..63718e1 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -63,69 +63,12 @@ void shutdown() { } -void reset() -{ - using namespace render; - - // set clear color - gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); - - // shading model: Gouraud (smooth, the default) - gl::shademodel(GL_SMOOTH); - //gl::shademodel(GL_FLAT); - - // load identity matrices - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); - - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); - - // lighting - GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f }; - GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); - - // color tracking - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); - - GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance); - glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128 - - gl::disable(GL_LIGHTING); - gl::enable(GL_LIGHT0); - gl::disable(GL_COLOR_MATERIAL); - - // culling - gl::cullface(GL_BACK); - gl::frontface(GL_CCW); - gl::disable(GL_CULL_FACE); - - // depth - gl::depthmask(GL_TRUE); - gl::disable(GL_DEPTH_TEST); - - // alpha-blending - gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - gl::enable(GL_BLEND); - - // client state -} - void draw_loader() { using namespace render; render::Textures::bind("bitmaps/loader"); - gl::color(1.0f, 1.0f, 1.0f, 1.0f); - + gl::begin(gl::Quads); glTexCoord2f(0.0f, 0.0f); @@ -139,6 +82,7 @@ void draw_loader() glTexCoord2f(0.0f, 1.0f); gl::vertex(0,video::height,0); + gl::end(); } @@ -282,6 +226,62 @@ void draw_cursor() gl::end(); } +void reset() +{ + using namespace render; + + // set clear color + gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); + + // load identity matrices + gl::matrixmode(GL_MODELVIEW); + gl::loadidentity(); + + gl::matrixmode(GL_MODELVIEW); + gl::loadidentity(); + + // shading model: Gouraud (smooth, the default) + gl::shademodel(GL_SMOOTH); + //gl::shademodel(GL_FLAT); + + // lighting settings for the default light GL_LIGHT0 + GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f }; + GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); + glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); + + // GL_LIGHT0 is always enabled + gl::enable(GL_LIGHT0); + + // color tracking + glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); + + // material settings + GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance); + glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128 + + // alpha blending function + gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + gl::disable(GL_LIGHTING); + gl::disable(GL_COLOR_MATERIAL); + + gl::cullface(GL_BACK); + gl::frontface(GL_CCW); + gl::disable(GL_CULL_FACE); + gl::disable(GL_DEPTH_TEST); + gl::disable(GL_BLEND); + + gl::disable(GL_TEXTURE_2D); + +} + void frame(float seconds) { using namespace render; @@ -300,21 +300,20 @@ void frame(float seconds) if (core::application()->connected() && core::game()->serverframetime()) { render::draw(seconds); // draw the world - if (draw_radar->value()) { - Radar::draw(); - } } // switch to ortographic projection to draw the GUI gl::matrixmode(GL_PROJECTION); gl::loadidentity(); - glOrtho(0, video::width, video::height, 0, -1000.0f, 1000.0f); + glOrtho(0, video::width, video::height, 0, -1024.0f, 1024.0f); gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); gl::enable(GL_TEXTURE_2D); + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + if (!core::application()->connected()) { // draw the loader bitmap draw_loader(); @@ -322,9 +321,15 @@ void frame(float seconds) // draw text elements if (draw_ui->value()) { + Text::setfont("bitmaps/fonts/gui", 16, 24); + draw_status(); + if (draw_radar->value()) { + Radar::draw(); + } + // draw the mouse cursor draw_cursor(); } @@ -334,6 +339,8 @@ void frame(float seconds) console()->draw(); gl::disable(GL_TEXTURE_2D); + + gl::disable(GL_BLEND); } } //namespace view -- cgit v1.2.3