summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Makefile.am2
-rw-r--r--include/glfont.h1
-rw-r--r--include/glshape.h29
-rw-r--r--include/glwidgets.h14
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/engine.cc17
-rw-r--r--lib/glfont.cc4
-rw-r--r--lib/glshape.cc122
-rw-r--r--lib/gltexture.cc10
-rw-r--r--lib/glwidgets.cc10
-rw-r--r--src/test.cc61
11 files changed, 216 insertions, 57 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index fa972cf..0aa8482 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,4 +1,4 @@
pkginclude_HEADERS = \
-engine.h glbase.h glfont.h gltexture.h sprite.h
+engine.h glbase.h glfont.h gltexture.h glshape.h glwidgets.h sprite.h
noinst_HEADERS = gettext.h
diff --git a/include/glfont.h b/include/glfont.h
index 464cd47..4ace74a 100644
--- a/include/glfont.h
+++ b/include/glfont.h
@@ -37,6 +37,7 @@ namespace mogltk {
Color textcolor;
int shadow;
};
+ extern font * SystemFont;
};
#endif
diff --git a/include/glshape.h b/include/glshape.h
new file mode 100644
index 0000000..cd9fef0
--- /dev/null
+++ b/include/glshape.h
@@ -0,0 +1,29 @@
+#ifndef __GLSHAPE_H__
+#define __GLSHAPE_H__
+
+#include <Exceptions.h>
+#include <Color.h>
+#include <gltexture.h>
+
+namespace mogltk {
+ class shape : public Base {
+ public:
+ static void box(int x1, int y1, int x2, int y2, Color = WHITE);
+ static void box(int x1, int y1, int x2, int y2, Color, Color, Color, Color);
+ static void obox(int x1, int y1, int x2, int y2, Color = WHITE);
+ static void obox(int x1, int y1, int x2, int y2, Color, Color, Color, Color);
+ static void tbox(texture *, int x1, int y1, int x2, int y2, int tx = 0, int ty = 0, double = 1.0, Color = WHITE);
+ static void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, Color = WHITE);
+ static void tbox(texture *, int x1, int y1, int x2, int y2, Color, Color, Color, Color, int tx = 0, int ty = 0, double = 1.0);
+ static void tbox(texture *, int x1, int y1, int x2, int y2, Color, Color, Color, Color, int tx1, int ty1, int tx2, int ty2);
+ static void hline(int x1, int x2, int y, Color = WHITE);
+ static void hline(int x1, int x2, int y, Color, Color);
+ static void vline(int x, int y1, int y2, Color = WHITE);
+ static void vline(int x, int y1, int y2, Color, Color);
+ private:
+ static bool in2D(bool);
+ static void out2D(bool);
+ };
+};
+
+#endif
diff --git a/include/glwidgets.h b/include/glwidgets.h
new file mode 100644
index 0000000..3529fab
--- /dev/null
+++ b/include/glwidgets.h
@@ -0,0 +1,14 @@
+#ifndef __GLWIDGETS_H__
+#define __GLWIDGETS_H__
+
+#include "Exceptions.h"
+
+namespace mogltk {
+ class widget : public Base {
+ public:
+ widget();
+ virtual ~widget();
+ };
+};
+
+#endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 54077cc..269a346 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,5 +5,6 @@ LIBS = @SDL_LIBS@ @BALTISOT_LIBS@
INCLUDES = -I.. -I../include -I$(includedir)
lib_LTLIBRARIES = libmogltk.la
-libmogltk_la_SOURCES = engine.cc glbase.cc glfont.cc gltexture.cc sprite.cc
+libmogltk_la_SOURCES = engine.cc glbase.cc glfont.cc gltexture.cc glshape.cc \
+glwidgets.cc sprite.cc
diff --git a/lib/engine.cc b/lib/engine.cc
index ac813f9..c30b1d9 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -1,6 +1,15 @@
+#include <SDL.h>
+#include <Input.h>
#include "engine.h"
+#include "glfont.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef _
#define _(x) x
+#endif
bool mogltk::engine::inited = false, mogltk::engine::postsetuped = false;
bool mogltk::engine::appactive = false, mogltk::engine::cursorvisible = false, mogltk::engine::quitrequest = false;
@@ -13,7 +22,7 @@ Uint32 mogltk::engine::curticks;
int mogltk::engine::setup() throw(GeneralException) {
if (inited) {
- printm(M_WARNING, "mogltk::engine::setup() called twice, ignoring second call.\n");
+ printm(M_WARNING, _("mogltk::engine::setup() called twice, ignoring second call.\n"));
return -1;
}
if (SDL_Init(0) < 0) {
@@ -22,13 +31,15 @@ int mogltk::engine::setup() throw(GeneralException) {
atexit(SDL_Quit);
inited = true;
+
+ mogltk::SystemFont = new mogltk::font(&Input("font.bin"));
return 0;
}
int mogltk::engine::postsetup() throw(GeneralException) {
if (postsetuped) {
- printm(M_WARNING, "mogltk::engine::postsetup() called twice, ignoring second call.\n");
+ printm(M_WARNING, _("mogltk::engine::postsetup() called twice, ignoring second call.\n"));
return -1;
}
@@ -124,6 +135,8 @@ void mogltk::engine::pollevents() {
frames = 0;
curticks = ticks;
}
+ } else {
+ curfps = -1;
}
while(true) {
diff --git a/lib/glfont.cc b/lib/glfont.cc
index 383601c..5cb1646 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -308,3 +308,7 @@ int mogltk::font::singletextsize(const String & s) const {
return r;
}
+
+mogltk::font * mogltk::SystemFont;
+
+
diff --git a/lib/glshape.cc b/lib/glshape.cc
new file mode 100644
index 0000000..cad1e36
--- /dev/null
+++ b/lib/glshape.cc
@@ -0,0 +1,122 @@
+#include <SDL_opengl.h>
+#include "glbase.h"
+#include "glshape.h"
+#include "gltexture.h"
+
+#define ENTER bool was2d = in2D(true)
+#define ENTERT bool was2d = in2D(false)
+#define LEAVE out2D(was2d)
+
+void mogltk::shape::box(int x1, int y1, int x2, int y2, Color c) {
+ ENTER;
+
+ c.Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glVertex2i(x1, y1);
+ glVertex2i(x2 + 1, y1);
+ glVertex2i(x1, y2 + 1);
+ glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::box(int x1, int y1, int x2, int y2, Color c1, Color c2, Color c3, Color c4) {
+ ENTER;
+
+ glBegin(GL_TRIANGLE_STRIP);
+ c1.Bind(); glVertex2i(x1, y1);
+ c2.Bind(); glVertex2i(x2 + 1, y1);
+ c3.Bind(); glVertex2i(x1, y2 + 1);
+ c4.Bind(); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::hline(int x1, int x2, int y, Color c) {
+ box(x1, y, x2, y, c);
+}
+
+void mogltk::shape::vline(int x, int y1, int y2, Color c) {
+ box(x, y1, x, y2, c);
+}
+
+void mogltk::shape::hline(int x1, int x2, int y, Color c1, Color c2) {
+ box(x1, y, x2, y, c1, c2, c1, c2);
+}
+
+void mogltk::shape::vline(int x, int y1, int y2, Color c1, Color c2) {
+ box(x, y1, x, y2, c1, c1, c2, c2);
+}
+
+void mogltk::shape::obox(int x1, int y1, int x2, int y2, Color c) {
+ ENTER;
+ hline(x1, x2, y1, c);
+ hline(x1, x2, y2, c);
+ vline(x1, y1, y2, c);
+ vline(x2, y1, y2, c);
+ LEAVE;
+}
+
+void mogltk::shape::obox(int x1, int y1, int x2, int y2, Color c1, Color c2, Color c3, Color c4) {
+ ENTER;
+ hline(x1, x2, y1, c1, c2);
+ hline(x1, x2, y2, c3, c4);
+ vline(x1, y1, y2, c1, c3);
+ vline(x2, y1, y2, c2, c4);
+ LEAVE;
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, Color c) {
+ tbox(t, x1, y1, x2, y2, tx, ty, tx + (x2 - x1) * f, ty + (y2 - y1) * f, c);
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, Color c1, Color c2, Color c3, Color c4, int tx, int ty, double f) {
+ tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (x2 - x1) * f, ty + (y2 - y1) * f);
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, Color c) {
+ ENTERT;
+
+ c.Bind();
+ t->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
+ glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
+ glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
+ glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, Color c1, Color c2, Color c3, Color c4, int tx1, int ty1, int tx2, int ty2) {
+ ENTERT;
+
+ t->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ c1.Bind(); glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
+ c2.Bind(); glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
+ c3.Bind(); glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
+ c4.Bind(); glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+bool mogltk::shape::in2D(bool unbind) {
+ bool was2D = mogltk::glbase::is2D();
+
+ if (!was2D)
+ mogltk::glbase::Enter2DMode();
+
+ if (unbind) mogltk::texture::Unbind();
+
+ return was2D;
+}
+
+void mogltk::shape::out2D(bool was2D) {
+ if (!was2D)
+ mogltk::glbase::Leave2DMode();
+}
diff --git a/lib/gltexture.cc b/lib/gltexture.cc
index 19fc9bf..9b8f7e3 100644
--- a/lib/gltexture.cc
+++ b/lib/gltexture.cc
@@ -241,12 +241,14 @@ GLuint mogltk::texture::GetHeight() {
}
void mogltk::texture::Unbind(void) {
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
- active = 0;
+ if (active) {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDisable(GL_TEXTURE_2D);
+ active = 0;
#ifdef DEBUG
- printm(M_INFO, _("Unbinding texture.\n"));
+ printm(M_INFO, _("Unbinding texture.\n"));
#endif
+ }
}
void mogltk::texture::Taint(void) {
diff --git a/lib/glwidgets.cc b/lib/glwidgets.cc
new file mode 100644
index 0000000..b381092
--- /dev/null
+++ b/lib/glwidgets.cc
@@ -0,0 +1,10 @@
+#include <SDL.h>
+#include <Input.h>
+#include "glfont.h"
+#include "glwidgets.h"
+
+mogltk::widget::widget() {
+}
+
+mogltk::widget::~widget() {
+}
diff --git a/src/test.cc b/src/test.cc
index 74b4b9b..55b4a14 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -7,21 +7,18 @@
#include "glbase.h"
#include "gltexture.h"
#include "glfont.h"
+#include "glwidgets.h"
#include "engine.h"
#include "sprite.h"
+#include "glshape.h"
CODE_BEGINS
virtual int startup() throw (GeneralException) {
verbosity = M_INFO;
mogltk::glbase::setup();
new Archive("datas.paq");
- Input * fonte = new Input("font.bin");
- mogltk::font font(fonte);
- delete fonte;
- Input * cursor = new Input("cursor.rgba");
- printm(M_INFO, "Sprite file size: %i\n", cursor->GetSize());
- mogltk::Sprite * s = new mogltk::Sprite(cursor, 25, 25);
- delete cursor;
+ mogltk::font font(&Input("font-2.bin"));
+ mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25);
mogltk::engine::setcursorvisible(true);
mogltk::engine::setappactive(true);
@@ -33,46 +30,10 @@ virtual int startup() throw (GeneralException) {
while (!mogltk::engine::quitrequested()) {
mogltk::glbase::Enter2DMode();
- mytex->Bind();
- glBegin(GL_TRIANGLE_STRIP);
- glColor3d(0, 0, 0);
- glTexCoord2i(0, 0);
- glVertex2f(50, 50);
- glColor3d(1, 0, 0);
- glTexCoord2i(511, 0);
- glVertex2f(561, 50);
- glColor3d(0, 1, 0);
- glTexCoord2i(0, 511);
- glVertex2f(50, 561);
- glColor3d(0, 0, 1);
- glTexCoord2i(511, 511);
- glVertex2f(561, 561);
- glEnd();
-
- mogltk::texture::Unbind();
- glBegin(GL_TRIANGLE_STRIP);
- glColor3d(0, 0, 0);
- glVertex2f(400, 100);
- glColor3d(1, 0, 0);
- glVertex2f(450, 100);
- glColor3d(0, 1, 0);
- glVertex2f(400, 150);
- glColor3d(0, 0, 1);
- glVertex2f(450, 150);
- glEnd();
-
-
- glBegin(GL_TRIANGLE_STRIP);
- CORNFLOWERBLUE.Bind();
- glVertex2f( 5, 5);
- DEEPSKYBLUE.Bind();
- glVertex2f(150, 5);
- MIDNIGHTBLUE.Bind();
- glVertex2f( 5, 80);
- NAVY.Bind();
- glVertex2f(150, 80);
- glEnd();
+ mogltk::shape::tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE);
+ mogltk::shape::box(400, 100, 450, 150, BLACK, RED, LIME, BLUE);
+ mogltk::shape::box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY);
font.setshadow(1);
font.putcursor(10, 30);
font.setcolor(WHITE);
@@ -82,10 +43,12 @@ virtual int startup() throw (GeneralException) {
"I can't believe it!\n"
);
- font.putcursor(550, 450);
- font.printf("FPS: %.2f", mogltk::engine::FPS());
+ font.putcursor(550, 400);
+ font.printf("FPS: %.2f\n", mogltk::engine::FPS());
+ font.printf("mx: %i\n", mogltk::engine::mouseX());
+ font.printf("my: %i\n", mogltk::engine::mouseY());
- s->draw(mogltk::engine::mouseX() - 9, mogltk::engine::mouseY() - 7);
+ s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6);
mogltk::glbase::Leave2DMode();
mogltk::glbase::Flip();