summaryrefslogtreecommitdiff
path: root/lib/base.cc
diff options
context:
space:
mode:
authorpixel <pixel>2004-07-04 11:56:18 +0000
committerpixel <pixel>2004-07-04 11:56:18 +0000
commit5cc874802b0b8c4462e7e873654e6daa54be00de (patch)
treed97bfbfe26998b1ee9cf01d830ba446e61094a86 /lib/base.cc
parentbf452e7f6a3fa0e41964fc8e2c57e1e577cd1682 (diff)
SOL Demo
Diffstat (limited to 'lib/base.cc')
-rw-r--r--lib/base.cc51
1 files changed, 49 insertions, 2 deletions
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;
+}