}
void
-Surface::draw(float x, float y, Uint8 alpha, bool update)
+Surface::draw(float x, float y, Uint8 alpha, bool upside_down, bool update)
{
if (impl)
{
- if (impl->draw(x, y, alpha, update) == -2)
+ if (impl->draw(x, y, alpha, upside_down, update) == -2)
reload();
}
}
{
if (impl)
{
- w = w_;
- h = h_;
+ w = w_;
+ h = h_;
if (impl->resize(w_,h_) == -2)
reload();
}
}
+Surface* Surface::CaptureScreen()
+{
+ Surface *cap_screen;
+
+ if (!(screen->flags & SDL_OPENGL))
+ {
+ cap_screen = new Surface(SDL_GetVideoSurface(),false);
+ }
+
+#ifndef NOOPENGL
+ if (use_gl)
+ {
+ SDL_Surface *temp;
+ unsigned char *pixels;
+ int i;
+ temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ 0x000000FF, 0x0000FF00, 0x00FF0000, 0
+#else
+ 0x00FF0000, 0x0000FF00, 0x000000FF, 0
+#endif
+ );
+ if (temp == NULL)
+ st_abort("Error while trying to capture the screen in OpenGL mode","");
+
+ pixels = (unsigned char*) malloc(3 * screen->w * screen->h);
+ if (pixels == NULL)
+ {
+ SDL_FreeSurface(temp);
+ st_abort("Error while trying to capture the screen in OpenGL mode","");
+ }
+
+ glReadPixels(0, 0, screen->w, screen->h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ for (i=0; i<screen->h; i++)
+ memcpy(((char *) temp->pixels) + temp->pitch * i, pixels + 3*screen->w * (screen->h-i-1), screen->w*3);
+ free(pixels);
+
+ cap_screen = new Surface(temp,false);
+ SDL_FreeSurface(temp);
+
+ }
+#endif
+
+return cap_screen;
+}
+
SDL_Surface*
sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, int use_alpha)
{
dest.w = w;
dest.h = h;
int ret = SDL_SoftStretch(sdl_surface, NULL,
- sdl_surface, &dest);
+ sdl_surface, &dest);
return ret;
}
}
int
-SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update)
+SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool upside_down, bool update)
{
float pw = power_of_two(w);
float ph = power_of_two(h);
glBindTexture(GL_TEXTURE_2D, gl_texture);
glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(x, y);
- glTexCoord2f((float)w / pw, 0);
- glVertex2f((float)w+x, y);
- glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)w+x, (float)h+y);
- glTexCoord2f(0, (float)h / ph);
- glVertex2f(x, (float)h+y);
+ if(upside_down)
+ {
+ glTexCoord2f(0, 0);
+ glVertex2f(x, (float)h+y);
+
+ glTexCoord2f((float)w / pw, 0);
+ glVertex2f((float)w+x, (float)h+y);
+
+ glTexCoord2f((float)w / pw, (float)h / ph);
+ glVertex2f((float)w+x, y);
+
+ glTexCoord2f(0, (float)h / ph);
+ glVertex2f(x, y);
+ }
+ else
+ {
+ glTexCoord2f(0, 0);
+ glVertex2f(x, y);
+
+ glTexCoord2f((float)w / pw, 0);
+ glVertex2f((float)w+x, y);
+
+ glTexCoord2f((float)w / pw, (float)h / ph);
+ glVertex2f((float)w+x, (float)h+y);
+
+ glTexCoord2f(0, (float)h / ph);
+ glVertex2f(x, (float)h+y);
+ }
glEnd();
glDisable(GL_TEXTURE_2D);
}
int
-SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update)
+SurfaceSDL::draw(float x, float y, Uint8 alpha, bool upside_down, bool update)
{
SDL_Rect dest;
dest.w = w;
dest.h = h;
+ if(upside_down) // FIXME: feel free to replace this hack
+ {
+ for(float sy = 0; sy < h; sy++)
+ if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, update) == -2)
+ return -2;
+ return 0;
+ }
+
if(alpha != 255)
{
/* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update)
{
SDL_Rect dest;
-
+
dest.x = (int)x;
dest.y = (int)y;
dest.w = (int)sw;
if(alpha != 255)
SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
-
-
- SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
- sw, sh, sdl_surface->format->BitsPerPixel,
- sdl_surface->format->Rmask, sdl_surface->format->Gmask,
- sdl_surface->format->Bmask,
- 0);
- SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
+
+ SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
+ sw, sh, sdl_surface->format->BitsPerPixel,
+ sdl_surface->format->Rmask, sdl_surface->format->Gmask,
+ sdl_surface->format->Bmask,
+ 0);
+
+ SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);