Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/render.cc18
-rw-r--r--src/render/text.cc90
-rw-r--r--src/render/text.h25
-rw-r--r--src/render/textures.cc21
-rw-r--r--src/render/textures.h13
5 files changed, 132 insertions, 35 deletions
diff --git a/src/render/render.cc b/src/render/render.cc
index 8c4f0fb..e602673 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -56,13 +56,11 @@ bool texture(const char *filename, size_t id)
void init()
{
- con_print << "Initializing renderer..." << std::endl;
+ con_print << "^BInitializing renderer..." << std::endl;
- con_print << " renderer " << gl::renderer() << std::endl;
- con_print << " vendor " << gl::vendor() << std::endl;
- con_print << " version " << gl::version() << std::endl;
-
- Textures::init();
+ con_print << " renderer ^B" << gl::renderer() << std::endl;
+ con_print << " vendor ^B" << gl::vendor() << std::endl;
+ con_print << " version ^B" << gl::version() << std::endl;
// size of the vertex array in megabytes
r_arraysize = core::Cvar::get("r_arraysize", 0.0f , core::Cvar::Archive);
@@ -81,11 +79,17 @@ void init()
r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive);
r_wireframe->set_info("[bool] render wireframe");
+
+ Textures::init();
+
+ Text::init();
}
void shutdown()
{
- con_print << "Shutting down renderer..." << std::endl;
+ con_print << "^BShutting down renderer..." << std::endl;
+
+ Text::shutdown();
Textures::shutdown();
diff --git a/src/render/text.cc b/src/render/text.cc
index 668f4ec..7c1ae8e 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -1,18 +1,83 @@
/*
render/text.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
+#include "auxiliary/functions.h"
#include "render/text.h"
#include "render/textures.h"
#include "sys/sys.h"
-namespace render {
+namespace render
+{
float Text::text_fontwidth = 16.0f;
float Text::text_fontheight = 24.0f;
+math::Color * Text::base_color[10];
+math::Color * Text::core_color[26];
+
+void Text::init()
+{
+ // base colors
+ // Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7
+ base_color[0] = new math::Color(0, 0, 0);
+ base_color[1] = new math::Color(1, 0, 0);
+ base_color[2] = new math::Color(0, 1, 0);
+ base_color[3] = new math::Color(1, 1, 0);
+ base_color[4] = new math::Color(0, 0, 1);
+ base_color[5] = new math::Color(0, 1, 1);
+ base_color[6] = new math::Color(1, 0, 1);
+ base_color[7] = new math::Color(1, 1, 1);
+
+ for (size_t i=0; i< 26; i++) {
+ core_color[i] = new math::Color(.7, .7, .7);
+ }
+
+ // N - normal color
+ core_color[(size_t)('N'-'A')]->assign(.7, .7, .7);
+ // D - Debug color
+ core_color[(size_t)('D'-'A')]->assign(.6, .6, .6);
+ // B - bold color
+ core_color[(size_t)('B'-'A')]->assign(1, 1, 1);
+ // W - warning color
+ core_color[(size_t)('W'-'A')]->assign(1, 1, 0);
+ // R - Error color
+ core_color[(size_t)('R'-'A')]->assign(1, 0, 0);
+ // F - Fancy color
+ core_color[(size_t)('F'-'A')]->assign(0, 1, 0);
+}
+
+void Text::shutdown()
+{
+ for (size_t i=0; i< 7; i++) {
+ delete base_color[i];
+ base_color[i] = 0;
+ }
+
+ for (size_t i=0; i< 26; i++) {
+ delete core_color[i];
+ core_color[i] = 0;
+ }
+}
+
+void Text::setcolor(const char color)
+{
+ if (('A' <= color) && (color <= 'Z')) {
+ gl::color(*core_color[(size_t) (color - 'A')]);
+ }
+
+ else if (('0' <= color) && (color <= '9')) {
+ gl::color(*base_color[(size_t) (color - '0')]);
+ }
+
+ else {
+ gl::color(1, 1, 1);
+ }
+
+}
+
void Text::setfont(const char *texture, float width, float height)
{
Textures::bind(texture, false);
@@ -20,6 +85,7 @@ void Text::setfont(const char *texture, float width, float height)
text_fontheight = height;
}
+
void Text::draw(float x, float y, const char ascii)
{
if (ascii != ' ') {
@@ -28,9 +94,9 @@ void Text::draw(float x, float y, const char ascii)
float frow = row * 0.0625f;
float fcol = col * 0.0625f;
-
+
gl::begin(gl::Quads);
-
+
glTexCoord2f(fcol, frow);
gl::vertex(x,y,1);
@@ -52,13 +118,21 @@ void Text::draw(float x, float y, const char *text)
{
const char *c = text;
while (*c) {
- draw(x, y, *c);
+ if (aux::is_base_color_code(c)) {
+ c++;
+ gl::color(*base_color[ (size_t)(*c - '0')]);
+ } else if (aux::is_core_color_code(c)) {
+ c++;
+ gl::color(*core_color[ (size_t)(*c - 'A')]);
+ } else {
+ draw(x, y, *c);
+ x += text_fontwidth;
+ }
c++;
- x += text_fontwidth;
}
}
-void Text::draw(float x, float y, std::stringstream & textstream)
+void Text::draw(float x, float y, std::stringstream & textstream)
{
char line[MAXCMDSIZE];
while (textstream.getline(line, MAXCMDSIZE-1)) {
diff --git a/src/render/text.h b/src/render/text.h
index 47d88fd..5cf18ea 100644
--- a/src/render/text.h
+++ b/src/render/text.h
@@ -1,7 +1,7 @@
/*
render/text.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_TEXT_H__
@@ -10,10 +10,19 @@
#include <string>
#include <sstream>
-namespace render {
+#include "math/color.h"
-class Text {
+namespace render
+{
+
+class Text
+{
public:
+
+ static void init();
+
+ static void shutdown();
+
/// draw a text string
static void draw(float x, float y, const std::string & text);
@@ -31,6 +40,9 @@ public:
/// set the font
static void setfont(const char *texture, float width, float height);
+
+ /// set the color
+ static void setcolor(const char color);
/// current font width
static inline float fontwidth() { return text_fontwidth; }
@@ -38,6 +50,11 @@ public:
/// current font height
static inline float fontheight() { return text_fontheight; }
+ enum Color {Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7};
+
+ static math::Color * base_color[10];
+ static math::Color * core_color[26];
+
private:
static float text_fontwidth;
static float text_fontheight;
diff --git a/src/render/textures.cc b/src/render/textures.cc
index 8dac3a3..cfd627c 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -1,7 +1,7 @@
/*
render/textures.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
@@ -13,7 +13,8 @@
#include "sys/sys.h"
#include "core/application.h"
-namespace render {
+namespace render
+{
std::map<std::string, size_t> Textures::registry;
size_t Textures::index = 0;
@@ -22,7 +23,7 @@ GLuint Textures::textures[MAXTEXTURES];
void Textures::init()
{
clear();
- con_print << "Loading textures..." << std::endl;
+ con_print << "^BLoading textures..." << std::endl;
// "no texture" bitmap
load("textures/common/notex");
@@ -44,7 +45,7 @@ void Textures::init()
// crosshairs
load("bitmaps/crosshair");
-
+
// light flares
load("bitmaps/fx/flare00");
load("bitmaps/fx/flare01");
@@ -72,7 +73,7 @@ size_t Textures::load(std::string name, bool filter)
if (it != registry.end())
return (*it).second;
- // try the tga version
+ // try the tga version
std::string filename(name);
filename.append(".tga");
Image *image = TGA::load(filename.c_str());
@@ -101,7 +102,7 @@ size_t Textures::load(std::string name, bool filter)
texture_type = GL_RGB;
gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(),
- image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data());
+ image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data());
set_filter(filter);
@@ -153,10 +154,10 @@ void Textures::set_filter(bool filter)
{
if (filter) {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- }
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
}
+}
diff --git a/src/render/textures.h b/src/render/textures.h
index 12873ef..43e312d 100644
--- a/src/render/textures.h
+++ b/src/render/textures.h
@@ -1,7 +1,7 @@
/*
render/textures.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_TEXTURES_H__
@@ -12,11 +12,12 @@
#include "render/gl.h"
-namespace render {
+namespace render
+{
const size_t MAXTEXTURES = 256;
-/// Texture managment
+/// Texture managment
class Textures
{
public:
@@ -27,12 +28,12 @@ public:
static void shutdown();
/// Load a texture
- /** Returns 0 on failure, and the texture index on success
+ /** Returns 0 on failure, and the texture index on success
*/
static size_t load(std::string name, bool filter = true);
/// bind a texture for OpenGL usage
- /** Returns 0 on failure, and the texture index on success
+ /** Returns 0 on failure, and the texture index on success
*/
static size_t bind(std::string name, bool filter = true);