summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--include/Makefile.am2
-rw-r--r--include/gltexture.h7
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/Makefile.sol.mingw2
-rw-r--r--lib/glfont.cc8
-rw-r--r--lib/gltexture.cc6
-rw-r--r--lib/sprite.cc132
-rw-r--r--src/test.cc2
9 files changed, 149 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index 30f7436..b1ae7a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,7 @@ AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC
AM_PROG_LIBTOOL
+AC_C_BIGENDIAN
# Checks for libraries.
AC_CHECK_LIB([c], [printf])
diff --git a/include/Makefile.am b/include/Makefile.am
index be0dd07..fa972cf 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,4 +1,4 @@
pkginclude_HEADERS = \
-engine.h glbase.h glfont.h gltexture.h
+engine.h glbase.h glfont.h gltexture.h sprite.h
noinst_HEADERS = gettext.h
diff --git a/include/gltexture.h b/include/gltexture.h
index 06f2e8a..4f5e162 100644
--- a/include/gltexture.h
+++ b/include/gltexture.h
@@ -5,17 +5,16 @@
#include <SDL_opengl.h>
#include <Handle.h>
#include <Exceptions.h>
+#include <generic.h>
namespace mogltk {
- enum texture_type {
- RAW_RGBA,
- };
class texture : public Base {
public:
texture(int = 256, int = 256, bool = false) throw (GeneralException);
- texture(Handle *, bool = false, texture_type = RAW_RGBA) throw (GeneralException);
+ texture(Handle *, bool = false) throw (GeneralException);
virtual ~texture();
SDL_Surface * GetSurface();
+ Uint32 * GetPixels();
static SDL_Surface * LoadNTEX(Handle * h) throw (GeneralException) ;
void Generate();
void Bind(bool = true);
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ffe8471..54077cc 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,5 +5,5 @@ 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
+libmogltk_la_SOURCES = engine.cc glbase.cc glfont.cc gltexture.cc sprite.cc
diff --git a/lib/Makefile.sol.mingw b/lib/Makefile.sol.mingw
index abbcdb1..3aea9cb 100644
--- a/lib/Makefile.sol.mingw
+++ b/lib/Makefile.sol.mingw
@@ -3,7 +3,7 @@ CXX = i586-mingw32msvc-g++
AR = i586-mingw32msvc-ar
RANLIB = i586-mingw32msvc-ranlib
CPPFLAGS = -I../include -DFORCE64 -I../../Baltisot/include `/usr/local/win32/bin/sdl-config --cflags` -I/usr/local/win32/include
-OBJECTS = engine.o glbase.o glfont.o gltexture.o
+OBJECTS = engine.o glbase.o glfont.o gltexture.o sprite.o
TARGET = mogltk-sol.a
all: $(TARGET)
diff --git a/lib/glfont.cc b/lib/glfont.cc
index e4556ff..0956b36 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -168,9 +168,8 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, Color c) {
was2D = mogltk::glbase::is2D();
- if (!was2D) {
+ if (!was2D)
mogltk::glbase::Enter2DMode();
- }
if (shadow) {
int os = shadow;
@@ -198,9 +197,8 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, Color c) {
glTexCoord2i(px + maxX - 1, py + maxY - 1); glVertex2i(x + maxX - 1, y + maxY - 1);
glEnd();
- if (!was2D) {
+ if (!was2D)
mogltk::glbase::Leave2DMode();
- }
}
void mogltk::font::Bind(int index) {
@@ -287,7 +285,7 @@ int mogltk::font::printf(const char * p, ...) {
m.p = p;
- va_start(ap, m);
+ va_start(ap, p);
r = printf(m, ap);
va_end(ap);
diff --git a/lib/gltexture.cc b/lib/gltexture.cc
index accdb3a..19fc9bf 100644
--- a/lib/gltexture.cc
+++ b/lib/gltexture.cc
@@ -55,7 +55,7 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi
#endif
}
-mogltk::texture::texture(Handle * h, bool plane, texture_type ttype) throw (GeneralException) :
+mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) :
texture_allocated(false), planar(plane), tainted(true) {
SDL_Surface * temp;
@@ -149,6 +149,10 @@ mogltk::texture::~texture() {
#endif
}
+Uint32 * mogltk::texture::GetPixels() {
+ return (Uint32 *) surface->pixels;
+}
+
SDL_Surface * mogltk::texture::GetSurface() {
return surface;
}
diff --git a/lib/sprite.cc b/lib/sprite.cc
new file mode 100644
index 0000000..be2fd3b
--- /dev/null
+++ b/lib/sprite.cc
@@ -0,0 +1,132 @@
+#include <SDL.h>
+#include "sprite.h"
+
+#define TEXSIZE 256
+
+mogltk::Sprite::TexList * mogltk::Sprite::TexList::header = 0;
+
+mogltk::Sprite::Sprite(Handle * h, int asx, int asy) : sx(asx), sy(asy) {
+ alloc();
+ for (int y = 0; y < sy; y++) {
+ h->read(tlist->GetTex()->pixels + TEXSIZE * y + posx, sx);
+ }
+}
+
+mogltk::Sprite::Sprite(Uint8 * p, int asx, int asy) : sx(asx), sy(asy) {
+ alloc();
+ for (int y = 0; y < sy; y++) {
+ bcopy(p, tlist->GetTex()->pixels + TEXSIZE * y + posx, sx);
+ p += sx;
+ }
+}
+
+mogltk::Sprite::~Sprite() {
+ if (prev)
+ prev->next = next
+ else
+ tlist->sprheader = next;
+ if (next)
+ next->prev = prev;
+
+ if (!tlist->sprheader) {
+ delete tlist;
+ }
+}
+
+void mogltk::Sprite::alloc() {
+ /* FIXMEEEEEEEEEEEEE */
+ bool found = false;
+ TexList * p;
+
+ for (p = tlist; p && !found; p = p->GetNext()) {
+ for (y = 0; (py < (TEXSIZE - sy)) && !found; py++) {
+ for (x = 0; (px < (TEXSIZE - sx)) && !found; px++) {
+ if (p->strheader->canfit(x, y, x + sx, y + sy)) {
+ found = true;
+ }
+ }
+ }
+ }
+
+ if (!found) {
+#ifdef DEBUG
+ printm(M_INFO, "Allocating a new texture for sprites\n");
+#endif
+ x = y = 0;
+ p = new TexList(TEXSIZE);
+ }
+
+ tlist = p;
+}
+
+mogltk::Sprite::TexList::TexList(int size) {
+ tex = new texture(size, size, true);
+
+ if (header)
+ header->next->prev = this;
+ prev = 0;
+ next = header;
+ header = this;
+}
+
+mogltk::Sprite::TexList::~TexList() {
+ delete tex;
+ if (prev)
+ prev->next = next
+ else
+ header = next;
+ if (next)
+ next->prev = prev;
+}
+
+const mogltk::texture * mogltk::Sprite::TexList::GetTex() const {
+ return tex;
+}
+
+const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetHead() const {
+ return header;
+}
+
+const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetNext() const {
+ return next;
+}
+
+void mogltk::Sprite::TexList::Bind() const {
+ tex->Bind();
+}
+
+bool mogltk::Sprite::intersect(int x1, int y1, int x2, int y2) const {
+ int sx1 = x, sy1 = y, sx2 = x + sx, sy2 = y + sy;
+
+ return !((sx1 >= x2) || (sx2 <= x1) || (sy1 >= y1) || (sy2 <= y2));
+}
+
+bool mogltk::Sprite::canfit(int x1, int y1, int x2, int y2) const {
+ if (!intersect(x1, y1, x2, y2))
+ return true
+ else
+ if (next)
+ return next->canfit()
+ else
+ return false;
+}
+
+void mogltk::Sprite::draw(int dx, int dy, Color c) {
+ bool was2D;
+
+ was2D = mogltk::glbase::is2D();
+
+ if (!was2D)
+ mogltk::glbase::Enter2DMode();
+
+ tlist->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(x , y ); glVertex2i(dx , dy );
+ glTexCoord2i(x + sx - 1, y ); glVertex2i(dx + sx - 1, dy );
+ glTexCoord2i(x , y + sy - 1); glVertex2i(dx , dy + sy - 1);
+ glTexCoord2i(x + sx - 1, y + sy - 1); glVertex2i(dx + sx - 1, dy + sy - 1);
+ glEnd();
+
+ if (!was2D)
+ mogltk::glbase::Leave2DMode();
+}
diff --git a/src/test.cc b/src/test.cc
index 0efe319..129127a 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -23,6 +23,8 @@ virtual int startup() throw (GeneralException) {
mogltk::texture * mytex = new mogltk::texture(pattern, true);
delete pattern;
+// mogltk::engine::setappactive(true);
+
while (!mogltk::engine::quitrequested()) {
mogltk::glbase::Enter2DMode();