From 5cc874802b0b8c4462e7e873654e6daa54be00de Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 4 Jul 2004 11:56:18 +0000 Subject: SOL Demo --- lib/base.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'lib/base.cc') diff --git a/lib/base.cc b/lib/base.cc index acfc654..fd5c1da 100644 --- a/lib/base.cc +++ b/lib/base.cc @@ -46,10 +46,11 @@ int mogltk::base::GetHeight(void) { return height; } -void mogltk::base::Flip() { +void mogltk::base::Flip(bool clear) { mogltk::engine::pollevents(); SDL_Flip(surface); - SDL_FillRect(surface, NULL, 0); + if (clear) + SDL_FillRect(surface, NULL, 0); } mogltk::base::base(int w, int h, int flags, int) : surface(0) { @@ -108,3 +109,49 @@ void mogltk::base::ToggleFullscreen() { surface = SDL_SetVideoMode(surface->w, surface->h, surface->format->BitsPerPixel, SDL_HWSURFACE | newflags); } + +inline static unsigned int nextpower(unsigned int n) { + unsigned int i; + + if (!n) + return n; + + if (ISPOT(n)) + return n; + + for (i = 31; i >= 0; i--) { + if ((n >> i) & 1) { + return 1 << (i + 1); + } + } +} + +mogltk::texture * mogltk::base::GrabTexture() { + int w = nextpower(GetWidth()); + int h = nextpower(GetHeight()); + texture * r = new texture(w, h); + + SDL_BlitSurface(getsurface(), NULL, r->GetSurface(), NULL); + + return r; +} + +SDL_Surface * mogltk::base::GrabSurface() { + SDL_Surface * r = SDL_CreateRGBSurface(SDL_SWSURFACE, GetWidth(), GetHeight(), 24, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + 0xff000000, + 0x00ff0000, + 0x0000ff00, + 0x00000000 +#else + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0x00000000 +#endif + ); + + SDL_BlitSurface(getsurface(), NULL, r, NULL); + + return r; +} -- cgit v1.2.3