From 3e2e4fe9e05d73ba1c1b5de93160bb1cdb7cb56e Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 28 Mar 2003 13:36:38 +0000 Subject: SDL backend mostly finished --- lib/sprite.cc | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'lib/sprite.cc') diff --git a/lib/sprite.cc b/lib/sprite.cc index 60f944c..74ea522 100644 --- a/lib/sprite.cc +++ b/lib/sprite.cc @@ -1,5 +1,6 @@ #include -#include "glbase.h" +#include "engine.h" +#include "base.h" #include "sprite.h" #define TEXSIZE 256 @@ -107,6 +108,11 @@ void mogltk::Sprite::TexList::Bind() const { tex->Bind(); } +SDL_Surface * mogltk::Sprite::TexList::GetSurface() { + return tex->GetSurface(); +} + + bool mogltk::Sprite::intersect(int x1, int y1, int x2, int y2) const { int sx1 = posx, sy1 = posy, sx2 = posx + sx, sy2 = posy + sy; @@ -124,27 +130,24 @@ 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; + bool locked = false; + + if (SDL_MUSTLOCK(mogltk::engine::base_o->getsurface())) { + locked = true; + SDL_LockSurface(mogltk::engine::base_o->getsurface()); + } - was2D = mogltk::glbase::is2D(); + SDL_Rect src, dst; - if (!was2D) - mogltk::glbase::Enter2DMode(); - - c.Bind(); + src.x = posx; src.y = posy; src.w = sx; src.h = sy; + dst.x = dx; dst.y = dy; dst.w = sx; dst.h = sy; - tlist->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); - glEnd(); - - if (!was2D) - mogltk::glbase::Leave2DMode(); -#endif + printm(M_INFO, "Drawing sprite at %i %i\n", dx, dy); + + SDL_BlitSurface(tlist->GetSurface(), &src, mogltk::engine::base_o->getsurface(), &dst); + + if (locked) + SDL_UnlockSurface(mogltk::engine::base_o->getsurface()); } void mogltk::Sprite::Bind() { -- cgit v1.2.3