diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/base.cc | 28 | ||||
| -rw-r--r-- | lib/engine.cc | 5 | ||||
| -rw-r--r-- | lib/font.cc | 7 | ||||
| -rw-r--r-- | lib/glcolor.cc | 13 | ||||
| -rw-r--r-- | lib/glfont.cc | 10 | ||||
| -rw-r--r-- | lib/glshape.cc | 21 | ||||
| -rw-r--r-- | lib/glsprite.cc | 137 | ||||
| -rw-r--r-- | lib/gltexture.cc | 120 | ||||
| -rw-r--r-- | lib/glwidgets.cc | 4 | ||||
| -rw-r--r-- | lib/mcolor.cc | 6 | ||||
| -rw-r--r-- | lib/shape.cc | 35 | ||||
| -rw-r--r-- | lib/sprite.cc | 22 | ||||
| -rw-r--r-- | lib/texture.cc | 111 | 
14 files changed, 204 insertions, 317 deletions
| diff --git a/lib/Makefile.am b/lib/Makefile.am index c1bc885..f7fd3be 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 glcolor.cc glfont.cc gltexture.cc \ +libmogltk_la_SOURCES = engine.cc glbase.cc glfont.cc glsprite.cc \  glshape.cc glwidgets.cc sprite.cc base.cc font.cc shape.cc mcolor.cc texture.cc diff --git a/lib/base.cc b/lib/base.cc index 049f53c..8741978 100644 --- a/lib/base.cc +++ b/lib/base.cc @@ -8,12 +8,7 @@  #endif  #include "gettext.h" -int mogltk::base::setup(int w, int h, int flags) : surface(0) throw(GeneralException) { -    if (inited) { -        printm(M_WARNING, "mogltk::base::setup called twice, ignoring second call...\n"); -        return -1; -    } - +mogltk::base::base(int w, int h, int flags) throw(GeneralException) : surface(0) {      width = w;      height = h; @@ -33,15 +28,16 @@ int mogltk::base::setup(int w, int h, int flags) : surface(0) throw(GeneralExcep      printm(M_INFO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", surface->w, surface->h, surface->format->BitsPerPixel, ratio); -    inited = 1; -          SDL_ShowCursor(0);      SDL_FillRect(surface, NULL, 0); -    SDL_SwapBuffers(); +    SDL_Flip(surface);      SDL_FillRect(surface, NULL, 0);      mogltk::engine::postsetup();  } +mogltk::base::~base() { +} +  int mogltk::base::GetWidth(void) {      return width;  } @@ -50,23 +46,17 @@ int mogltk::base::GetHeight(void) {      return height;  } -int mogltk::base::GetInited(void) { -    return inited; -} -  void mogltk::base::Flip() {      printm(M_INFO, "Flipping\n");      mogltk::engine::pollevents(); -    SDL_SwapBuffers(); +    SDL_Flip(surface);      SDL_FillRect(surface, NULL, 0);  } -int mogltk::base::setup(int w, int h, int flags) : surface(0) { +mogltk::base::base(int w, int h, int flags, int) : surface(0) {      width = w;      height = h; -    inited = 1; -          SDL_ShowCursor(0);  } @@ -75,3 +65,7 @@ void mogltk::base::setsurface(SDL_Surface * _surface) throw (GeneralException) {  	throw GeneralException("Can't set video surface twice");      surface = _surface;  } + +SDL_Surface * mogltk::base::getsurface() { +    return surface; +} diff --git a/lib/engine.cc b/lib/engine.cc index 99843c0..036aa25 100644 --- a/lib/engine.cc +++ b/lib/engine.cc @@ -6,10 +6,7 @@  #ifdef HAVE_CONFIG_H  #include "config.h"  #endif - -#ifndef _ -#define _(x) x -#endif +#include "gettext.h"  bool mogltk::engine::inited = false, mogltk::engine::postsetuped = false;  bool mogltk::engine::appactive = false, mogltk::engine::cursorvisible = false, mogltk::engine::quitrequest = false; diff --git a/lib/font.cc b/lib/font.cc index 204e60d..9e77ae2 100644 --- a/lib/font.cc +++ b/lib/font.cc @@ -167,7 +167,7 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {      int trueentry, cx, cy, px, py;      return; -     +#if 0          was2D = mogltk::glbase::is2D();      if (!was2D) @@ -201,6 +201,7 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {      if (!was2D)  	mogltk::glbase::Leave2DMode(); +#endif  }  void mogltk::font::putcursor(int x, int y) { @@ -318,3 +319,7 @@ mogltk::font * mogltk::SystemFont;  mogltk::texture * mogltk::font::alloctexture() {      return new mogltk::texture(256, 256);  } + +void mogltk::font::Bind(int f) { +    fonttex[f]->Bind(); +} diff --git a/lib/glcolor.cc b/lib/glcolor.cc deleted file mode 100644 index c38b4e5..0000000 --- a/lib/glcolor.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include <SDL_opengl.h> -#include "glcolor.h" - -mogltk::glColorP::glColorP(const Color & ac) : ColorP(ac) { -} - -mogltk::glColorP::glColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : ColorP(ar, ag, ab, aa) { -} - -void mogltk::glColorP::Bind() { -    glColor4d((double) MIN(MAX(c.R, Min.R), Max.R) / 255, (double) MIN(MAX(c.G, Min.G), Max.G) / 255, (double) MIN(MAX(c.B, Min.B), Max.B) / 255, (double) MIN(MAX(c.A, Min.A), Max.A) / 255); -} - diff --git a/lib/glfont.cc b/lib/glfont.cc index 38f5c78..cd2fca3 100644 --- a/lib/glfont.cc +++ b/lib/glfont.cc @@ -11,7 +11,7 @@ mogltk::glfont::glfont(Handle * ffont) : font(ffont) {  mogltk::glfont::~glfont() {  } -void mogltk::glfont::drawentry(Uint16 entry, int x, int y, glColorP c) { +void mogltk::glfont::drawentry(Uint16 entry, int x, int y, ColorP c) {      bool was2D;      int trueentry, cx, cy, px, py; @@ -49,11 +49,3 @@ void mogltk::glfont::drawentry(Uint16 entry, int x, int y, glColorP c) {      if (!was2D)  	mogltk::engine::glbase_o->Leave2DMode();  } - -void mogltk::glfont::Bind(int index) { -    ((mogltk::gltexture *) fonttex[index])->Bind(); -} - -mogltk::gltexture * mogltk::glfont::alloctexture() { -    return new mogltk::gltexture(256, 256, true); -} diff --git a/lib/glshape.cc b/lib/glshape.cc index 831be32..c38d062 100644 --- a/lib/glshape.cc +++ b/lib/glshape.cc @@ -1,7 +1,7 @@  #include <SDL_opengl.h>  #include "glbase.h"  #include "glshape.h" -#include "gltexture.h" +#include "texture.h"  #include "glfont.h"  #include "engine.h" @@ -9,7 +9,7 @@  #define ENTERT bool was2d = Enter(false)  #define LEAVE Leave(was2d) -void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c) { +void mogltk::glshape::box(int x1, int y1, int x2, int y2, ColorP c) {      ENTER;      c.Bind(); @@ -23,7 +23,7 @@ void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c) {      LEAVE;  } -void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP c4) { +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); @@ -36,7 +36,10 @@ void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c1, glColorP      LEAVE;  } -void mogltk::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, glColorP c) { +void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) { +    shape::tbox(t, x1, y1, x2, y2, tx, ty, 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(); @@ -51,7 +54,11 @@ void mogltk::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2      LEAVE;  } -void mogltk::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP c4, int tx1, int ty1, int tx2, int ty2) { +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) { +    shape::tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, 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(); @@ -65,7 +72,7 @@ void mogltk::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2      LEAVE;  } -void mogltk::glshape::box3d(int x1, int y1, int x2, int y2, glColorP face, glColorP shade1, glColorP shade2, int depth, bool bevel) { +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) { @@ -111,7 +118,7 @@ bool mogltk::glshape::Enter(bool unbind) {      if (!was2D)  	mogltk::engine::glbase_o->Enter2DMode(); -    if (unbind) mogltk::gltexture::Unbind(); +    if (unbind) mogltk::texture::Unbind();      return was2D;  } diff --git a/lib/glsprite.cc b/lib/glsprite.cc index 282eefe..68350c9 100644 --- a/lib/glsprite.cc +++ b/lib/glsprite.cc @@ -1,146 +1,37 @@  #include <SDL.h>  #include "glbase.h" -#include "sprite.h" +#include "glsprite.h" +#include "engine.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()->GetPixels() + TEXSIZE * y + posx, sx * 4); -    } -} - -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()->GetPixels() + TEXSIZE * y + posx, sx * 4); -	p += sx * 4; -    } -} - -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 (posy = 0; (posy < (TEXSIZE - sy)) && !found; posy++) { -	    for (posx = 0; (posx < (TEXSIZE - sx)) && !found; posx++) { -		if (p->sprheader->canfit(posx, posy, posx + sx, posy + sy)) { -		    found = true; -		} -	    } -	} -    } -     -    if (!found) { -#ifdef DEBUG -	printm(M_INFO, "Allocating a new texture for sprites\n"); -#endif -	posx = posy = 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; -} - -mogltk::texture * mogltk::Sprite::TexList::GetTex() { -    return tex; -} - -const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetHead() { -    return header; -} - -const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetNext() const { -    return next; -} - -mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetNext() { -    return next; -} - -void mogltk::Sprite::TexList::Bind() const { -    tex->Bind(); +mogltk::glSprite::glSprite(Handle * h, int asx, int asy) : Sprite(h, asx, asy) {  } -bool mogltk::Sprite::intersect(int x1, int y1, int x2, int y2) const { -    int sx1 = posx, sy1 = posy, sx2 = posx + sx, sy2 = posy + sy; -     -    return !((sx1 >= x2) || (sx2 <= x1) || (sy1 >= y1) || (sy2 <= y2)); +mogltk::glSprite::glSprite(Uint8 * p, int asx, int asy) : Sprite(p, asx, asy) {  } -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(x1, y1, x2, y2); -	else -	    return false; +mogltk::glSprite::~glSprite() {  } -void mogltk::Sprite::draw(int dx, int dy, ColorP c) { +void mogltk::glSprite::draw(int dx, int dy, ColorP c) {      bool was2D; -    was2D = mogltk::glbase::is2D(); +    was2D = mogltk::engine::glbase_o->is2D();      if (!was2D) -	mogltk::glbase::Enter2DMode(); +	mogltk::engine::glbase_o->Enter2DMode();      c.Bind(); -    tlist->Bind(); +    Bind();      glBegin(GL_TRIANGLE_STRIP); -    glTexCoord2i(posx         , posy         ); glVertex2i(dx         , dy         ); -    glTexCoord2i(posx + sx - 1, posy         ); glVertex2i(dx + sx - 1, dy         ); -    glTexCoord2i(posx         , posy + sy - 1); glVertex2i(dx         , dy + sy - 1); -    glTexCoord2i(posx + sx - 1, posy + sy - 1); glVertex2i(dx + sx - 1, dy + sy - 1); +    glTexCoord2i(GetPX()              , GetPY()              ); glVertex2i(dx              , dy              ); +    glTexCoord2i(GetPX() + GetSX() - 1, GetPY()              ); glVertex2i(dx + GetSX() - 1, dy              ); +    glTexCoord2i(GetPX()              , GetPY() + GetSY() - 1); glVertex2i(dx              , dy + GetSY() - 1); +    glTexCoord2i(GetPX() + GetSX() - 1, GetPY() + GetSY() - 1); glVertex2i(dx + GetSX() - 1, dy + GetSY() - 1);      glEnd();      if (!was2D) -	mogltk::glbase::Leave2DMode(); +	mogltk::engine::glbase_o->Leave2DMode();  } diff --git a/lib/gltexture.cc b/lib/gltexture.cc deleted file mode 100644 index ff79112..0000000 --- a/lib/gltexture.cc +++ /dev/null @@ -1,120 +0,0 @@ -#include <sys/types.h> -#include <SDL.h> -#include <SDL_opengl.h> -#include <generic.h> -#include "gltexture.h" -#include "engine.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include "gettext.h" - -mogltk::gltexture * mogltk::gltexture::active = 0; - -mogltk::gltexture::gltexture(int w, int h, bool plane) throw (GeneralException) : -    texture(w, h), texture_allocated(false), planar(plane), tainted(true) { -} - -mogltk::gltexture::gltexture(Handle * h, bool plane) throw (GeneralException) : -    texture(h), texture_allocated(false), planar(plane), tainted(true) { -} - -mogltk::gltexture::~gltexture() { -    if (texture_allocated) { -	glDeleteTextures(1, &tex); -    } -} - -void mogltk::gltexture::Generate() { -    if (texture_allocated) { -	glDeleteTextures(1, &tex); -    } -     -    glGenTextures(1, &tex); -#ifdef DEBUG -    printm(M_INFO, _("Generated gltexture index: %i\n"), tex); -#endif - -    glBindTexture(GL_TEXTURE_2D, tex); - -#if 0 -    if (planar) { -#ifdef DEBUG -	printm(M_INFO, _("Generating planar gltexture: %i\n"), tex); -#endif -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); -	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); -    } else { -#endif -#ifdef DEBUG -	printm(M_INFO, _("Generating 3D gltexture: %i\n"), tex); -#endif -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, GetWidth(), GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, GetPixels()); -//	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);	 -#if 0 -    } -#endif - -    texture_allocated = true; -    tainted = false; -} - -void mogltk::gltexture::Bind(bool expand) { -    if ((!texture_allocated) || tainted) -	Generate(); -    glEnable(GL_TEXTURE_2D); -    if (active == this) -	return; -#ifdef DEBUG -    printm(M_INFO, _("Binding gltexture index %i.\n"), tex); -#endif -    glBindTexture(GL_TEXTURE_2D, tex); -    if (expand) { -	glMatrixMode(GL_TEXTURE); -	glLoadIdentity(); -	glScaled(1 / (double) GetWidth(), 1 / (double) GetHeight(), 1); -	glMatrixMode(GL_MODELVIEW); -    } -     -    active = this; -     -#ifdef TRACE_TEXTURES -    if (header == this) -	return; -     -    if (prev) { -	prev->next = next; -    } -     -    if (next) { -	next->prev = prev; -    } -     -    if (footer = this) { -	footer = prev; -    } -     -    header->prev = this; -    header = this; -#endif -} - -void mogltk::gltexture::Unbind(void) { -    if (active) { -	glBindTexture(GL_TEXTURE_2D, 0); -	glDisable(GL_TEXTURE_2D); -	active = 0; -#ifdef DEBUG -	printm(M_INFO, _("Unbinding gltexture.\n")); -#endif -    } -} - -void mogltk::gltexture::Taint(void) { -    tainted = true; -} diff --git a/lib/glwidgets.cc b/lib/glwidgets.cc index 0ac5f8b..f8e0389 100644 --- a/lib/glwidgets.cc +++ b/lib/glwidgets.cc @@ -7,9 +7,7 @@  #include "config.h"  #endif -#ifndef _ -#define _(x) x -#endif +#include "gettext.h"  mogltk::widget * mogltk::widget::cur_root = 0; diff --git a/lib/mcolor.cc b/lib/mcolor.cc index 91c8a1d..04e0467 100644 --- a/lib/mcolor.cc +++ b/lib/mcolor.cc @@ -1,4 +1,5 @@  #include <SDL.h> +#include <SDL_opengl.h>  #include "mcolor.h"  Color mogltk::ColorP::Min(0, 0, 0, 0), mogltk::ColorP::Max = WHITE; @@ -8,3 +9,8 @@ mogltk::ColorP::ColorP(const Color & ac) : c(ac) {  mogltk::ColorP::ColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : c(ar, ag, ab, aa) {  } + +void mogltk::ColorP::Bind() { +    glColor4d((double) MIN(MAX(c.R, Min.R), Max.R) / 255, (double) MIN(MAX(c.G, Min.G), Max.G) / 255, (double) MIN(MAX(c.B, Min.B), Max.B) / 255, (double) MIN(MAX(c.A, Min.A), Max.A) / 255); +} + diff --git a/lib/shape.cc b/lib/shape.cc index 088deb7..9386e41 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -1,4 +1,5 @@  #include <SDL.h> +#include "engine.h"  #include "base.h"  #include "shape.h"  #include "texture.h" @@ -8,6 +9,7 @@  #define LEAVE Leave(flag)  void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) { +#if 0      ENTER;      c.Bind(); @@ -19,9 +21,11 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {      glEnd();      LEAVE; +#endif  }  void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) { +#if 0      ENTER;      glBegin(GL_TRIANGLE_STRIP); @@ -32,6 +36,7 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, Co      glEnd();      LEAVE; +#endif  }  void mogltk::shape::hline(int x1, int x2, int y, ColorP c) { @@ -113,6 +118,7 @@ void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, Co  }  void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP c) { +#if 0      ENTERT;      c.Bind(); @@ -125,9 +131,11 @@ void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, in      glEnd();      LEAVE; +#endif  }  void mogltk::shape::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) { +#if 0      ENTERT;      t->Bind(); @@ -139,9 +147,11 @@ void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, Co      glEnd();      LEAVE; +#endif  }  void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) { +#if 0      ENTER;      if (!bevel) { @@ -179,6 +189,7 @@ void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP sh      glEnd();      LEAVE; +#endif  }  void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, bool bevel) { @@ -266,22 +277,16 @@ void mogltk::shape::button(int x1, int y1, int x2, int y2,      LEAVE;  } -bool mogltk::shape::Enter(bool unbind) { -    bool was2D = mogltk::glbase::is2D(); -     -    if (!was2D) -	mogltk::glbase::Enter2DMode(); -     -    if (unbind) mogltk::texture::Unbind(); -     -    return was2D; -} -  bool mogltk::shape::Enter() { -    return Enter(false); +    if (SDL_MUSTLOCK(mogltk::engine::base_o->getsurface())) { +	SDL_LockSurface(mogltk::engine::base_o->getsurface()); +	return true; +    } else { +	return false; +    }  } -void mogltk::shape::Leave(bool was2D) { -    if (!was2D) -	mogltk::glbase::Leave2DMode(); +void mogltk::shape::Leave(bool locked) { +    if (locked) +	SDL_UnlockSurface(mogltk::engine::base_o->getsurface());  } diff --git a/lib/sprite.cc b/lib/sprite.cc index 282eefe..60f944c 100644 --- a/lib/sprite.cc +++ b/lib/sprite.cc @@ -124,6 +124,7 @@ bool mogltk::Sprite::canfit(int x1, int y1, int x2, int y2) const {  }  void mogltk::Sprite::draw(int dx, int dy, ColorP c) { +#if 0      bool was2D;      was2D = mogltk::glbase::is2D(); @@ -143,4 +144,25 @@ void mogltk::Sprite::draw(int dx, int dy, ColorP c) {      if (!was2D)  	mogltk::glbase::Leave2DMode(); +#endif +} + +void mogltk::Sprite::Bind() { +    tlist->Bind(); +} + +int mogltk::Sprite::GetPX() { +    return posx; +} + +int mogltk::Sprite::GetPY() { +    return posy; +} + +int mogltk::Sprite::GetSX() { +    return sx; +} + +int mogltk::Sprite::GetSY() { +    return sy;  } diff --git a/lib/texture.cc b/lib/texture.cc index 36297ac..80853ca 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -1,5 +1,6 @@  #include <sys/types.h>  #include <SDL.h> +#include <SDL_opengl.h>  #include <generic.h>  #include "texture.h"  #include "engine.h" @@ -8,6 +9,8 @@  #endif  #include "gettext.h" +#define DEBUG 1 +  #ifdef TRACE_TEXTURES  mogltk::texture * mogltk::texture::header = 0;  mogltk::texture * mogltk::texture::footer = 0; @@ -15,7 +18,7 @@ mogltk::texture * mogltk::texture::footer = 0;  mogltk::texture * mogltk::texture::active = 0; -mogltk::texture::texture(int w, int h) throw (GeneralException) : width(w), height(h), +mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h),      texture_allocated(false), planar(plane), tainted(true) {      if ((!ISPOT(w)) || (!ISPOT(h)))  	throw GeneralException(_("Size of the texture not a power of 2!")); @@ -49,7 +52,9 @@ mogltk::texture::texture(int w, int h) throw (GeneralException) : width(w), heig  #endif  } -mogltk::texture::texture(Handle * h) throw (GeneralException) { +mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : +    texture_allocated(false), planar(plane), tainted(true) { +      SDL_Surface * temp;      temp = LoadNTEX(h); @@ -118,6 +123,10 @@ mogltk::texture::~texture() {  	SDL_FreeSurface(surface);      } +    if (texture_allocated) { +	glDeleteTextures(1, &tex); +    } +      #ifdef TRACE_TEXTURES      if (prev) {  	prev->next = next; @@ -145,14 +154,108 @@ SDL_Surface * mogltk::texture::GetSurface() {      return surface;  } -Uint32 mogltk::texture::GetWidth() { +void mogltk::texture::Generate() { +    if (texture_allocated) { +	glDeleteTextures(1, &tex); +    } +     +    glGenTextures(1, &tex); +#ifdef DEBUG +    printm(M_INFO, _("Generated texture index: %i\n"), tex); +#endif + +    glBindTexture(GL_TEXTURE_2D, tex); + +#if 0 +    if (planar) { +#ifdef DEBUG +	printm(M_INFO, _("Generating planar texture: %i\n"), tex); +#endif +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); +    } else { +#endif +#ifdef DEBUG +	printm(M_INFO, _("Generating 3D texture: %i\n"), tex); +#endif +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); +	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); +//	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);	 +#if 0 +    } +#endif + +    texture_allocated = true; +    tainted = false; +} + +void mogltk::texture::Bind(bool expand) { +    if ((!texture_allocated) || tainted) +	Generate(); +    glEnable(GL_TEXTURE_2D); +    if (active == this) +	return; +#ifdef DEBUG +    printm(M_INFO, _("Binding texture index %i.\n"), tex); +#endif +    glBindTexture(GL_TEXTURE_2D, tex); +    if (expand) { +	glMatrixMode(GL_TEXTURE); +	glLoadIdentity(); +	glScaled(1 / (double) width, 1 / (double) height, 1); +	glMatrixMode(GL_MODELVIEW); +    } +     +    active = this; +     +#ifdef TRACE_TEXTURES +    if (header == this) +	return; +     +    if (prev) { +	prev->next = next; +    } +     +    if (next) { +	next->prev = prev; +    } +     +    if (footer = this) { +	footer = prev; +    } +     +    header->prev = this; +    header = this; +#endif +} + +GLuint mogltk::texture::GetWidth() {      return width;  } -Uint32 mogltk::texture::GetHeight() { +GLuint mogltk::texture::GetHeight() {      return height;  } +void mogltk::texture::Unbind(void) { +    if (active) { +	glBindTexture(GL_TEXTURE_2D, 0); +	glDisable(GL_TEXTURE_2D); +	active = 0; +#ifdef DEBUG +	printm(M_INFO, _("Unbinding texture.\n")); +#endif +    } +} + +void mogltk::texture::Taint(void) { +    tainted = true; +} +  #ifdef WORDS_BIGENDIAN  #define NTEX_SIGNATURE 0x4e544558  #else | 
