diff options
Diffstat (limited to 'lib/glshape.cc')
-rw-r--r-- | lib/glshape.cc | 506 |
1 files changed, 253 insertions, 253 deletions
diff --git a/lib/glshape.cc b/lib/glshape.cc index 617e1dd..937173d 100644 --- a/lib/glshape.cc +++ b/lib/glshape.cc @@ -1,253 +1,253 @@ -/* - * mogltk - * Copyright (C) 1999-2004 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: glshape.cc,v 1.14 2004-07-15 14:21:31 pixel Exp $ */ - -#include <SDL_opengl.h> -#include "glbase.h" -#include "glshape.h" -#include "texture.h" -#include "glfont.h" -#include "engine.h" - -#define ENTER bool was2d = Enter(true) -#define ENTERT bool was2d = Enter(false) -#define LEAVE Leave(was2d) - -void mogltk::glshape::box(int x1, int y1, int x2, int y2, ColorP 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::glshape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP 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::glshape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) { - box(x1, y, x2, y, c1, c2, c1, c2); -} - -void mogltk::glshape::hline(int x1, int x2, int y, ColorP c) { - box(x1, y, x2, y, c, c, c, c); -} - -void mogltk::glshape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) { - box(x, y1, x, y2, c1, c1, c2, c2); -} - -void mogltk::glshape::vline(int x, int y1, int y2, ColorP c) { - box(x, y1, x, y2, c, c, c, c); -} - -void mogltk::glshape::pixel(int x, int y, ColorP c) { - box(x, y, x, y, c); -} - -void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c) { - ENTER; - shape::obox(x1, y1, x2, y2, c); - LEAVE; -} - -void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) { - ENTER; - - hline(x1, x2, y1, c1, c2); - hline(x1, x2, y2, c3, c4); - vline(x1, y1 + 1, y2 - 1, c1, c3); - vline(x2, y1 + 1, y2 - 1, c2, c4); - - LEAVE; -} - -void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) { - tbox(t, x1, y1, x2, y2, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f), c); -} -void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP 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::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) { - tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f)); -} - -void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP 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; -} - -void mogltk::glshape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) { - ENTER; - - if (!bevel) { - shade1.Bind(); - } else { - shade2.Bind(); - } - glBegin(GL_TRIANGLE_FAN); - glVertex2i(x1, y1); - glVertex2i(x2 + 1, y1); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x1, y2 + 1); - glEnd(); - - if (!bevel) { - shade2.Bind(); - } else { - shade1.Bind(); - } - glBegin(GL_TRIANGLE_FAN); - glVertex2i(x2 + 1, y2 + 1); - glVertex2i(x1, y2 + 1); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x2 + 1, y1); - glEnd(); - - face.Bind(); - glBegin(GL_TRIANGLE_STRIP); - glVertex2i(x1 + depth, y1 + depth); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x2 + 1 - depth, y2 + 1 - depth); - glEnd(); - - LEAVE; -} - -bool mogltk::glshape::Enter(bool unbind) { - bool was2D = mogltk::engine::glbase_o->is2D(); - - if (!was2D) - mogltk::engine::glbase_o->Enter2DMode(); - - if (unbind) mogltk::texture::Unbind(); - - return was2D; -} - -bool mogltk::glshape::Enter() { - return Enter(true); -} - -void mogltk::glshape::Leave(bool was2D) { - if (!was2D) - mogltk::engine::glbase_o->Leave2DMode(); -} - -void mogltk::glshape::fdraw(fill * f, ColorP c, int sx, int sy) { - ENTERT; - - if (!f) - return; - - texture * t = f->GetTexture(); - - if (!t) { - filldrawer * w = new filldrawer(f, t = f->Talloc(), WHITE); - f->walk(w); - delete w; - } - - c.Bind(); - t->Bind(); - int w = t->GetWidth(); - int h = t->GetHeight(); - int x = f->GetMinX() + sx; - int y = f->GetMinY() + sy; - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2i(0, 0); glVertex2i(x , y ); - glTexCoord2i(w, 0); glVertex2i(x + w, y ); - glTexCoord2i(0, h); glVertex2i(x , y + h); - glTexCoord2i(w, h); glVertex2i(x + w, y + h); - glEnd(); - - LEAVE; -} - -void mogltk::glshape::sdraw(fill * f, ColorP c, int sx, int sy) { - ENTERT; - - if (!f) - return; - - texture * t = f->GetSTexture(); - - if (!t) { - segdrawer * w = new segdrawer(f, t = f->STalloc(), WHITE); - f->swalk(w); - delete w; - } - - c.Bind(); - t->Bind(); - int w = t->GetWidth(); - int h = t->GetHeight(); - int x = f->GetMinX() + sx; - int y = f->GetMinY() + sy; - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2i(0, 0); glVertex2i(x , y ); - glTexCoord2i(w, 0); glVertex2i(x + w, y ); - glTexCoord2i(0, h); glVertex2i(x , y + h); - glTexCoord2i(w, h); glVertex2i(x + w, y + h); - glEnd(); - - LEAVE; -} +/*
+ * mogltk
+ * Copyright (C) 1999-2004 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: glshape.cc,v 1.15 2004-11-27 21:44:53 pixel Exp $ */
+
+#include <SDL_opengl.h>
+#include "glbase.h"
+#include "glshape.h"
+#include "texture.h"
+#include "glfont.h"
+#include "engine.h"
+
+#define ENTER bool was2d = Enter(true)
+#define ENTERT bool was2d = Enter(false)
+#define LEAVE Leave(was2d)
+
+void mogltk::glshape::box(int x1, int y1, int x2, int y2, ColorP 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::glshape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP 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::glshape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) {
+ box(x1, y, x2, y, c1, c2, c1, c2);
+}
+
+void mogltk::glshape::hline(int x1, int x2, int y, ColorP c) {
+ box(x1, y, x2, y, c, c, c, c);
+}
+
+void mogltk::glshape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) {
+ box(x, y1, x, y2, c1, c1, c2, c2);
+}
+
+void mogltk::glshape::vline(int x, int y1, int y2, ColorP c) {
+ box(x, y1, x, y2, c, c, c, c);
+}
+
+void mogltk::glshape::pixel(int x, int y, ColorP c) {
+ box(x, y, x, y, c);
+}
+
+void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c) {
+ ENTER;
+ shape::obox(x1, y1, x2, y2, c);
+ LEAVE;
+}
+
+void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
+ ENTER;
+
+ hline(x1, x2, y1, c1, c2);
+ hline(x1, x2, y2, c3, c4);
+ vline(x1, y1 + 1, y2 - 1, c1, c3);
+ vline(x2, y1 + 1, y2 - 1, c2, c4);
+
+ LEAVE;
+}
+
+void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) {
+ tbox(t, x1, y1, x2, y2, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f), c);
+}
+void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP 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::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) {
+ tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f));
+}
+
+void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP 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;
+}
+
+void mogltk::glshape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) {
+ ENTER;
+
+ if (!bevel) {
+ shade1.Bind();
+ } else {
+ shade2.Bind();
+ }
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2i(x1, y1);
+ glVertex2i(x2 + 1, y1);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x1, y2 + 1);
+ glEnd();
+
+ if (!bevel) {
+ shade2.Bind();
+ } else {
+ shade1.Bind();
+ }
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2i(x2 + 1, y2 + 1);
+ glVertex2i(x1, y2 + 1);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x2 + 1, y1);
+ glEnd();
+
+ face.Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glVertex2i(x1 + depth, y1 + depth);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x2 + 1 - depth, y2 + 1 - depth);
+ glEnd();
+
+ LEAVE;
+}
+
+bool mogltk::glshape::Enter(bool unbind) {
+ bool was2D = mogltk::engine::glbase_o->is2D();
+
+ if (!was2D)
+ mogltk::engine::glbase_o->Enter2DMode();
+
+ if (unbind) mogltk::texture::Unbind();
+
+ return was2D;
+}
+
+bool mogltk::glshape::Enter() {
+ return Enter(true);
+}
+
+void mogltk::glshape::Leave(bool was2D) {
+ if (!was2D)
+ mogltk::engine::glbase_o->Leave2DMode();
+}
+
+void mogltk::glshape::fdraw(fill * f, ColorP c, int sx, int sy) {
+ ENTERT;
+
+ if (!f)
+ return;
+
+ texture * t = f->GetTexture();
+
+ if (!t) {
+ filldrawer * w = new filldrawer(f, t = f->Talloc(), WHITE);
+ f->walk(w);
+ delete w;
+ }
+
+ c.Bind();
+ t->Bind();
+ int w = t->GetWidth();
+ int h = t->GetHeight();
+ int x = f->GetMinX() + sx;
+ int y = f->GetMinY() + sy;
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(0, 0); glVertex2i(x , y );
+ glTexCoord2i(w, 0); glVertex2i(x + w, y );
+ glTexCoord2i(0, h); glVertex2i(x , y + h);
+ glTexCoord2i(w, h); glVertex2i(x + w, y + h);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::glshape::sdraw(fill * f, ColorP c, int sx, int sy) {
+ ENTERT;
+
+ if (!f)
+ return;
+
+ texture * t = f->GetSTexture();
+
+ if (!t) {
+ segdrawer * w = new segdrawer(f, t = f->STalloc(), WHITE);
+ f->swalk(w);
+ delete w;
+ }
+
+ c.Bind();
+ t->Bind();
+ int w = t->GetWidth();
+ int h = t->GetHeight();
+ int x = f->GetMinX() + sx;
+ int y = f->GetMinY() + sy;
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(0, 0); glVertex2i(x , y );
+ glTexCoord2i(w, 0); glVertex2i(x + w, y );
+ glTexCoord2i(0, h); glVertex2i(x , y + h);
+ glTexCoord2i(w, h); glVertex2i(x + w, y + h);
+ glEnd();
+
+ LEAVE;
+}
|