summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2002-12-17 01:14:52 +0000
committerpixel <pixel>2002-12-17 01:14:52 +0000
commitc329122f425342ac620696b40f7421753f70a8b6 (patch)
treecdaa1f94b60b27ead86246f0fe4b86317e2e3b62
parentf0981aa6b09e67ec57b7cb92421513415292e97f (diff)
Woo, printf working.
-rw-r--r--include/glfont.h3
-rw-r--r--lib/glfont.cc24
-rw-r--r--src/test.cc46
3 files changed, 29 insertions, 44 deletions
diff --git a/include/glfont.h b/include/glfont.h
index cbff848..c1f7df9 100644
--- a/include/glfont.h
+++ b/include/glfont.h
@@ -16,6 +16,8 @@ namespace mogltk {
void putcursor(int, int);
void putentry(Uint16, Color = Color(255, 255, 255, 255));
void newline(void);
+ int printf(const String &, ...);
+ void setcolor(Color);
private:
Uint8 * sizes;
@@ -25,6 +27,7 @@ namespace mogltk {
Uint16 * corresp;
void Bind(int);
int cx, cy, ox;
+ Color textcolor;
};
};
diff --git a/lib/glfont.cc b/lib/glfont.cc
index d935d95..4d2cbd9 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -5,6 +5,7 @@
Uint8 prescale2[4] = { 0, 85, 170, 255 }, prescale3[8] = { 0, 36, 72, 109, 145, 182, 218, 255 };
#define DEBUG 1
+#define STRBUFSIZ 512
/*
@@ -71,7 +72,7 @@ nbT = number of textures
*/
-mogltk::font::font(Handle * ffont) {
+mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255) {
int i;
ffont->SetZ();
@@ -204,3 +205,24 @@ void mogltk::font::newline(void) {
cx = ox;
cy += maxY;
}
+
+int mogltk::font::printf(const String & m, ...) {
+ static char buffer[STRBUFSIZ + 1];
+ va_list ap;
+ char * p;
+ int r;
+
+ va_start(ap, m);
+ r = vsnprintf(buffer, STRBUFSIZ, m.to_charp(), ap);
+ va_end(ap);
+
+ for (p = buffer; *p; p++) {
+ putentry(*p, textcolor);
+ }
+
+ return r;
+}
+
+void mogltk::font::setcolor(Color c) {
+ textcolor = c;
+}
diff --git a/src/test.cc b/src/test.cc
index 43abd28..073771b 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -68,63 +68,23 @@ virtual int startup() throw (GeneralException) {
mogltk::texture::Unbind();
glBegin(GL_TRIANGLE_STRIP);
-// glTexCoord2i(0, 0);
glColor3d(0, 0, 0);
glVertex2f(400, 100);
-// glTexCoord2i(256, 0);
glColor3d(1, 0, 0);
glVertex2f(450, 100);
-// glTexCoord2i(0, 256);
glColor3d(0, 1, 0);
glVertex2f(400, 150);
-// glTexCoord2i(256, 256);
glColor3d(0, 0, 1);
glVertex2f(450, 150);
glEnd();
mogltk::glbase::Leave2DMode();
font.putcursor(10, 10);
- font.putentry('P');
- font.putentry('i');
- font.putentry('x');
- font.putentry('e');
- font.putentry('l');
- font.putentry('P');
- font.putentry('a');
- font.putentry('w');
- font.putentry('a');
- font.putentry('!');
+ font.printf("PixelPawa!");
font.newline();
- font.putentry('I');
- font.putentry('t');
- font.putentry(' ');
- font.putentry('w');
- font.putentry('o');
- font.putentry('r');
- font.putentry('k');
- font.putentry('s');
- font.putentry('!');
- font.putentry('!');
+ font.printf("It works!!");
font.newline();
- font.putentry('I');
- font.putentry(' ');
- font.putentry('c');
- font.putentry('a');
- font.putentry('n');
- font.putentry('\'');
- font.putentry('t');
- font.putentry(' ');
- font.putentry('b');
- font.putentry('e');
- font.putentry('l');
- font.putentry('i');
- font.putentry('e');
- font.putentry('v');
- font.putentry('e');
- font.putentry(' ');
- font.putentry('i');
- font.putentry('t');
- font.putentry('!');
+ font.printf("I can't believe it!");
mogltk::glbase::Flip();