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-05-11 15:16:25 +0000
committerStijn Buys <ingar@osirion.org>2008-05-11 15:16:25 +0000
commitd2e93235b9ccd37bf8c8fb7c4376ab1911c83639 (patch)
tree61bfbf023228ba10abe488d8c8bd27359171c9f7 /src/render
parentd82c8f449c604d0f957e3dd190f7beae3596e6f9 (diff)
console font
Diffstat (limited to 'src/render')
-rw-r--r--src/render/text.cc43
-rw-r--r--src/render/text.h33
-rw-r--r--src/render/textures.cc31
-rw-r--r--src/render/textures.h8
4 files changed, 79 insertions, 36 deletions
diff --git a/src/render/text.cc b/src/render/text.cc
index 768ebf8..668f4ec 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -4,12 +4,23 @@
the terms of the GNU General Public License version 2
*/
-#include "render/render.h"
+#include "render/text.h"
+#include "render/textures.h"
#include "sys/sys.h"
namespace render {
-void draw_text(float x, float y, const char ascii)
+float Text::text_fontwidth = 16.0f;
+float Text::text_fontheight = 24.0f;
+
+void Text::setfont(const char *texture, float width, float height)
+{
+ Textures::bind(texture, false);
+ text_fontwidth = width;
+ text_fontheight = height;
+
+}
+void Text::draw(float x, float y, const char ascii)
{
if (ascii != ' ') {
int row = (int) ascii >> 4;
@@ -21,49 +32,45 @@ void draw_text(float x, float y, const char ascii)
gl::begin(gl::Quads);
glTexCoord2f(fcol, frow);
- gl::vertex(x,y,0);
+ gl::vertex(x,y,1);
glTexCoord2f(fcol + 0.0625f, frow);
- gl::vertex(x+CHARWIDTH,y,0);
+ gl::vertex(x+text_fontwidth,y,1);
glTexCoord2f(fcol +0.0625f, frow + 0.0625f);
- gl::vertex(x+CHARWIDTH,y+CHARHEIGHT,0);
+ gl::vertex(x+text_fontwidth,y+text_fontheight,1);
glTexCoord2f(fcol, frow+0.0625f);
- gl::vertex(x,y+CHARHEIGHT,0);
+ gl::vertex(x,y+text_fontheight,1);
gl::end();
}
}
-void draw_text(float x, float y, const char *text)
+void Text::draw(float x, float y, const char *text)
{
const char *c = text;
while (*c) {
- draw_text(x, y, *c);
+ draw(x, y, *c);
c++;
- x += CHARWIDTH;
+ x += text_fontwidth;
}
}
-void draw_text(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)) {
- draw_text(x, y, line);
- y += CHARHEIGHT;
+ draw(x, y, line);
+ y += text_fontheight;
}
textstream.clear();
}
-void draw_text(float x, float y, const std::string & text)
+void Text::draw(float x, float y, const std::string & text)
{
- for (size_t i =0; i < text.size(); i++) {
- draw_text(x, y, text[i]);
- x += CHARWIDTH;
- }
+ draw(x, y, text.c_str());
}
}
-
diff --git a/src/render/text.h b/src/render/text.h
index ac7d104..47d88fd 100644
--- a/src/render/text.h
+++ b/src/render/text.h
@@ -10,22 +10,39 @@
#include <string>
#include <sstream>
-#define CHARWIDTH 16
-#define CHARHEIGHT 24
-
namespace render {
- /// draw a character
- void draw_text(float x, float y, const char ascii);
+class Text {
+public:
/// draw a text string
- void draw_text(float x, float y, const std::string & text);
+ static void draw(float x, float y, const std::string & text);
+
/// draw a text string
- void draw_text(float x, float y, const char *text);
+
+ static void draw(float x, float y, const char *text);
/// draw a text stream
/** If the stream contains multiple lines, each new line will be
* drawn at the same x value. The stream is cleared after reading
*/
- void draw_text(float x, float y, std::stringstream & textstream);
+ static void draw(float x, float y, std::stringstream & textstream);
+
+ /// draw a character
+ static void draw(float x, float y, const char ascii);
+
+ /// set the font
+ static void setfont(const char *texture, float width, float height);
+
+ /// current font width
+ static inline float fontwidth() { return text_fontwidth; }
+
+ /// current font height
+ static inline float fontheight() { return text_fontheight; }
+
+private:
+ static float text_fontwidth;
+ static float text_fontheight;
+};
+
}
#endif //__INCLUDED_RENDER_TEXT_H__
diff --git a/src/render/textures.cc b/src/render/textures.cc
index eef5f1d..8dac3a3 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -28,8 +28,14 @@ void Textures::init()
load("textures/common/notex");
// console characters
- if (load("bitmaps/conchars") == 0) {
- con_error << "Essential file bitmaps/conchars missing" << std::endl;
+ if (!load("bitmaps/fonts/console", false)) {
+ con_error << "Essential file bitmaps/fonts/console missing" << std::endl;
+ core::application()->shutdown();
+ }
+
+ // console characters
+ if (!load("bitmaps/fonts/gui", false)) {
+ con_error << "Essential file bitmaps/fonts/gui missing" << std::endl;
core::application()->shutdown();
}
@@ -59,7 +65,7 @@ void Textures::clear()
index = 0;
}
-size_t Textures::load(std::string name)
+size_t Textures::load(std::string name, bool filter)
{
// check if it is already loaded
iterator it = registry.find(name);
@@ -97,8 +103,7 @@ size_t Textures::load(std::string name)
gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(),
image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data());
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
+ set_filter(filter);
// add to the registry
registry[name] = id;
@@ -119,7 +124,7 @@ size_t Textures::find(std::string name)
return id;
}
-size_t Textures::bind(std::string name)
+size_t Textures::bind(std::string name, bool filter)
{
size_t id = 0;
iterator it = registry.find(name);
@@ -129,17 +134,29 @@ size_t Textures::bind(std::string name)
id = load(name);
glBindTexture(GL_TEXTURE_2D, textures[id]);
+ set_filter(filter);
return id;
}
-size_t Textures::bind(size_t texture)
+size_t Textures::bind(size_t texture, bool filter)
{
size_t id = texture;
if (texture >= index)
id = 0;
glBindTexture(GL_TEXTURE_2D, textures[id]);
+ set_filter(filter);
return id;
}
+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);
+ } else {
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_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 f8e35b3..12873ef 100644
--- a/src/render/textures.h
+++ b/src/render/textures.h
@@ -29,15 +29,15 @@ public:
/// Load a texture
/** Returns 0 on failure, and the texture index on success
*/
- static size_t load(std::string name);
+ 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
*/
- static size_t bind(std::string name);
+ static size_t bind(std::string name, bool filter = true);
/// bind a texture for OpenGL usage
- static size_t bind(size_t texture);
+ static size_t bind(size_t texture, bool filter = true);
/// find the texture index for a given name
static size_t find(std::string name);
@@ -45,6 +45,8 @@ public:
private:
static void clear();
+ static void set_filter(bool filter);
+
typedef std::map<std::string, size_t>::iterator iterator;
static std::map<std::string, size_t> registry;