summaryrefslogtreecommitdiff
path: root/lib/glshape.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glshape.cc')
-rw-r--r--lib/glshape.cc122
1 files changed, 122 insertions, 0 deletions
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();
+}