parent
6e48d82ede
commit
4ecdb03594
@ -0,0 +1,192 @@
|
|||||||
|
/* $Id: gfxengine.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */
|
||||||
|
/* GFX Game Engine */
|
||||||
|
|
||||||
|
#include "bomberclone.h"
|
||||||
|
|
||||||
|
int blitdb_nr = 0, blitrects_nr = 0;
|
||||||
|
static _gfxblit blitdb[MAX_BLITRECTS]; /* unsorted list of blitdb's */
|
||||||
|
static _gfxblit *sortblitdb[MAX_BLITRECTS]; /* sorted list of blitdb's */
|
||||||
|
static SDL_Rect blitrects[MAX_BLITRECTS]; /* SDLUpdate Rects */
|
||||||
|
|
||||||
|
/* sort the list of blitting objects highest will be drawn at last */
|
||||||
|
void gfx_blitsort () {
|
||||||
|
register int i,y;
|
||||||
|
|
||||||
|
gfx_blitsortclear ();
|
||||||
|
for (i = 0; i < MAX_BLITRECTS && i < blitdb_nr; i++) {
|
||||||
|
for (y = i; (y > 0 && blitdb[i].y < sortblitdb[y-1]->y); y--)
|
||||||
|
sortblitdb[y] = sortblitdb[y-1];
|
||||||
|
sortblitdb[y] = &blitdb[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* delete sorted order of gfx updates */
|
||||||
|
inline void gfx_blitsortclear () {
|
||||||
|
register int i;
|
||||||
|
for (i = 0; i < MAX_BLITRECTS; i++)
|
||||||
|
sortblitdb[i] = NULL;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* delete all updaterect entrys */
|
||||||
|
inline void gfx_blitupdaterectclear () {
|
||||||
|
register int i;
|
||||||
|
for (i = 0; i < MAX_BLITRECTS; i++)
|
||||||
|
blitrects[i].x = blitrects[i].y = blitrects[i].h = blitrects[i].w = -1;
|
||||||
|
blitrects_nr = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* SDL Update of the rects */
|
||||||
|
void gfx_blitupdaterectdraw () {
|
||||||
|
if (blitrects_nr > 0)
|
||||||
|
SDL_UpdateRects (gfx.screen, blitrects_nr, blitrects);
|
||||||
|
|
||||||
|
blitrects_nr = 0;
|
||||||
|
gfx_blitupdaterectclear ();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* add updaterect entrys and skipp unneeded or double rects */
|
||||||
|
void gfx_blitupdaterectadd (SDL_Rect *rect) {
|
||||||
|
_point p1a, p1e, p2a, p2e;
|
||||||
|
int i, done = 0;
|
||||||
|
|
||||||
|
/* search for a match or an close update rect */
|
||||||
|
p2a.x = rect->x;
|
||||||
|
p2a.y = rect->y;
|
||||||
|
p2e.x = rect->x + rect->w;
|
||||||
|
p2e.y = rect->y + rect->h;
|
||||||
|
|
||||||
|
for (i = 0; i < blitrects_nr && !done; i++) {
|
||||||
|
p1a.x = blitrects[i].x;
|
||||||
|
p1a.y = blitrects[i].y;
|
||||||
|
p1e.x = blitrects[i].x + blitrects[i].w;
|
||||||
|
p1e.y = blitrects[i].y + blitrects[i].h;
|
||||||
|
|
||||||
|
if (p2a.x >= p1a.x && p2e.x <= p1e.x &&
|
||||||
|
p2a.y >= p1a.y && p2e.y <= p1e.y) {
|
||||||
|
/* p2 is in p1 >> drop rects */
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* p1 is in p2 >> change rect */
|
||||||
|
else if (p1a.x >= p2a.x && p1e.x <= p2e.x &&
|
||||||
|
p1a.y >= p2a.y && p1e.y <= p2e.y) {
|
||||||
|
blitrects[i].x = rect->x;
|
||||||
|
blitrects[i].y = rect->y;
|
||||||
|
blitrects[i].w = rect->w;
|
||||||
|
blitrects[i].h = rect->h;
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no match found, add new */
|
||||||
|
if (i == blitrects_nr && !done) {
|
||||||
|
blitrects_nr++;
|
||||||
|
blitrects[i] = *rect;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
gfx_blitdraw ()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (blitdb_nr <= 0) {
|
||||||
|
blitdb_nr = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_blitsort ();
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_BLITRECTS && sortblitdb[i] != NULL; i++) {
|
||||||
|
SDL_BlitSurface (sortblitdb[i]->srci, &sortblitdb[i]->srcr, sortblitdb[i]->desti, &sortblitdb[i]->destr);
|
||||||
|
gfx_blitupdaterectadd (&sortblitdb[i]->destr);
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_blitupdaterectdraw ();
|
||||||
|
blitdb_nr = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Add a new image to draw/blit on the screen and in thw right order.
|
||||||
|
srcr srci: source image and rect
|
||||||
|
destr desti: destination image and rect
|
||||||
|
y: deep of the image */
|
||||||
|
void
|
||||||
|
gfx_blit (SDL_Surface *srci, SDL_Rect *srcr, SDL_Surface *desti, SDL_Rect *destr, int y)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* check if the rects are out of the images and drop this blitting */
|
||||||
|
if (srcr->x > srci->w || srcr->y > srci->h ||
|
||||||
|
destr->x > desti->w || destr->y > desti->h)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* clipping src */
|
||||||
|
if (srcr->x < 0) { // x < 0
|
||||||
|
srcr->w += srcr->x;
|
||||||
|
destr->w += srcr->x;
|
||||||
|
destr->x -= srcr->x;
|
||||||
|
srcr->x = 0;
|
||||||
|
}
|
||||||
|
if (srcr->x+srcr->w > srci->w) { // x+w > img.w
|
||||||
|
i = srcr->x+srcr->w - srci->w;
|
||||||
|
srcr->w -= i;
|
||||||
|
destr->w -= i;
|
||||||
|
}
|
||||||
|
if (srcr->y < 0) { // y < 0
|
||||||
|
srcr->h += srcr->y;
|
||||||
|
destr->h += srcr->h;
|
||||||
|
destr->y -= srcr->y;
|
||||||
|
srcr->y = 0;
|
||||||
|
}
|
||||||
|
if (srcr->y+srcr->h > srci->h) { // y+h > img.h
|
||||||
|
i = srcr->y+srcr->h - srci->h;
|
||||||
|
srcr->h -= i;
|
||||||
|
destr->h -= i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clipping dest */
|
||||||
|
if (destr->x < 0) { // x < 0
|
||||||
|
destr->w += destr->x;
|
||||||
|
srcr->w += destr->x;
|
||||||
|
srcr->x -= destr->x;
|
||||||
|
destr->x = 0;
|
||||||
|
}
|
||||||
|
if (destr->x+destr->w > desti->w) { // x+w > img.w
|
||||||
|
i = destr->x+destr->w - desti->w;
|
||||||
|
srcr->w -= i;
|
||||||
|
destr->w -= i;
|
||||||
|
}
|
||||||
|
if (destr->y < 0) { // y < 0
|
||||||
|
destr->h += destr->y;
|
||||||
|
srcr->h += destr->h;
|
||||||
|
srcr->y -= destr->y;
|
||||||
|
destr->y = 0;
|
||||||
|
}
|
||||||
|
if (destr->y+destr->h > desti->h) { // y+h > img.h
|
||||||
|
i = destr->y+destr->h - desti->h;
|
||||||
|
srcr->h -= i;
|
||||||
|
destr->h -= i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add to list */
|
||||||
|
if (blitdb_nr < 0)
|
||||||
|
blitdb_nr = 0;
|
||||||
|
else if (blitdb_nr >= MAX_BLITRECTS) {
|
||||||
|
d_fatal ("blitdb_nr > MAX_BLITRECTS\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blitdb[blitdb_nr].srcr = *srcr;
|
||||||
|
blitdb[blitdb_nr].srci = srci;
|
||||||
|
blitdb[blitdb_nr].destr = *destr;
|
||||||
|
blitdb[blitdb_nr].desti = desti;
|
||||||
|
blitdb[blitdb_nr].y = y;
|
||||||
|
|
||||||
|
blitdb_nr++;
|
||||||
|
};
|
@ -0,0 +1,372 @@
|
|||||||
|
/* $Id: gfxpixelimage.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */
|
||||||
|
/* gfx pixel manipulation and image manipulation */
|
||||||
|
|
||||||
|
#include "bomberclone.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B)
|
||||||
|
{
|
||||||
|
Uint32 pixel = 0;
|
||||||
|
Uint8 r,
|
||||||
|
g,
|
||||||
|
b;
|
||||||
|
|
||||||
|
/* Lock the screen for direct access to the pixels */
|
||||||
|
if (SDL_MUSTLOCK (surface))
|
||||||
|
if (SDL_LockSurface (surface) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pixel = getpixel (surface, x, y);
|
||||||
|
if (SDL_MUSTLOCK (surface)) {
|
||||||
|
SDL_UnlockSurface (surface);
|
||||||
|
}
|
||||||
|
SDL_GetRGB (pixel, surface->format, &r, &g, &b);
|
||||||
|
*R = r;
|
||||||
|
*G = g;
|
||||||
|
*B = b;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Uint32
|
||||||
|
getpixel (SDL_Surface * surface, int x, int y)
|
||||||
|
{
|
||||||
|
int bpp = surface->format->BytesPerPixel;
|
||||||
|
|
||||||
|
/* Here p is the address to the pixel we want to retrieve */
|
||||||
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
|
||||||
|
switch (bpp) {
|
||||||
|
case 1:
|
||||||
|
return *p;
|
||||||
|
case 2:
|
||||||
|
return *(Uint16 *) p;
|
||||||
|
case 3:
|
||||||
|
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||||
|
return p[0] << 16 | p[1] << 8 | p[2];
|
||||||
|
|
||||||
|
else
|
||||||
|
return p[0] | p[1] << 8 | p[2] << 16;
|
||||||
|
case 4:
|
||||||
|
return *(Uint32 *) p;
|
||||||
|
default:
|
||||||
|
return 0; /* shouldn't happen, but avoids warnings */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||||
|
{
|
||||||
|
/* Here p is the address to the pixel we want to set */
|
||||||
|
int bpp = surface->format->BytesPerPixel;
|
||||||
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
|
||||||
|
|
||||||
|
switch (bpp) {
|
||||||
|
case 1:
|
||||||
|
*p = pixel;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
*(Uint16 *) p = pixel;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
|
||||||
|
p[0] = (pixel >> 16) & 0xff;
|
||||||
|
p[1] = (pixel >> 8) & 0xff;
|
||||||
|
p[2] = pixel & 0xff;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p[0] = pixel & 0xff;
|
||||||
|
p[1] = (pixel >> 8) & 0xff;
|
||||||
|
p[2] = (pixel >> 16) & 0xff;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
*(Uint32 *) p = pixel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
scale (short int *dpattern, short int x, short int y)
|
||||||
|
{
|
||||||
|
int a,
|
||||||
|
dx,
|
||||||
|
dy;
|
||||||
|
if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) {
|
||||||
|
for (x = 0; x < SCALE_MAXRES; x++)
|
||||||
|
dpattern[x] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x > y) {
|
||||||
|
dy = 2 * y;
|
||||||
|
dx = a = 2 * x - dy;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (a <= 0) {
|
||||||
|
dpattern[(y--) - 1] = x;
|
||||||
|
a = a + dx;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
a = a - dy;
|
||||||
|
} while (x--);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
dy = 2 * x;
|
||||||
|
dx = a = 2 * y - dy;
|
||||||
|
|
||||||
|
do {
|
||||||
|
dpattern[y] = x;
|
||||||
|
if (a <= 0) {
|
||||||
|
x--;
|
||||||
|
a = a + dx;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
a = a - dy;
|
||||||
|
} while (y--);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SDL_Surface *
|
||||||
|
scale_image (SDL_Surface * orginal, int newx, int newy)
|
||||||
|
{
|
||||||
|
Uint32 rmask,
|
||||||
|
gmask,
|
||||||
|
bmask,
|
||||||
|
amask;
|
||||||
|
SDL_Surface *surface;
|
||||||
|
int y,
|
||||||
|
x;
|
||||||
|
short int xpattern[SCALE_MAXRES];
|
||||||
|
short int ypattern[SCALE_MAXRES];
|
||||||
|
|
||||||
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||||
|
rmask = 0xff000000;
|
||||||
|
gmask = 0x00ff0000;
|
||||||
|
bmask = 0x0000ff00;
|
||||||
|
amask = 0x000000ff;
|
||||||
|
|
||||||
|
#else /* */
|
||||||
|
rmask = 0x00ff0000;
|
||||||
|
gmask = 0x0000ff00;
|
||||||
|
bmask = 0x000000ff;
|
||||||
|
amask = 0xff000000;
|
||||||
|
|
||||||
|
#endif /* */
|
||||||
|
|
||||||
|
surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask);
|
||||||
|
if (surface == NULL) {
|
||||||
|
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lock the screen for direct access to the pixels */
|
||||||
|
if (SDL_MUSTLOCK (surface))
|
||||||
|
if (SDL_LockSurface (surface) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (orginal))
|
||||||
|
if (SDL_LockSurface (orginal) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (surface)) {
|
||||||
|
SDL_UnlockSurface (surface);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do the scaling work */
|
||||||
|
scale (xpattern, orginal->w - 1, newx);
|
||||||
|
scale (ypattern, orginal->h - 1, newy);
|
||||||
|
for (x = newx - 1; x >= 0; x--)
|
||||||
|
for (y = newy - 1; y >= 0; y--)
|
||||||
|
putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y]));
|
||||||
|
if (SDL_MUSTLOCK (orginal)) {
|
||||||
|
SDL_UnlockSurface (orginal);
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (surface)) {
|
||||||
|
SDL_UnlockSurface (surface);
|
||||||
|
}
|
||||||
|
return surface;
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_Surface *
|
||||||
|
makegray_image (SDL_Surface * org)
|
||||||
|
{
|
||||||
|
Uint32 rmask,
|
||||||
|
gmask,
|
||||||
|
bmask,
|
||||||
|
amask;
|
||||||
|
Uint32 pixel,
|
||||||
|
transpixel = 0;
|
||||||
|
SDL_Surface *dest;
|
||||||
|
int y,
|
||||||
|
x;
|
||||||
|
Uint8 r,
|
||||||
|
g,
|
||||||
|
b,
|
||||||
|
gray;
|
||||||
|
|
||||||
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||||
|
rmask = 0xff000000;
|
||||||
|
gmask = 0x00ff0000;
|
||||||
|
bmask = 0x0000ff00;
|
||||||
|
amask = 0x000000ff;
|
||||||
|
#else
|
||||||
|
rmask = 0x00ff0000;
|
||||||
|
gmask = 0x0000ff00;
|
||||||
|
bmask = 0x000000ff;
|
||||||
|
amask = 0xff000000;
|
||||||
|
#endif
|
||||||
|
dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask);
|
||||||
|
if (dest == NULL) {
|
||||||
|
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lock the screen for direct access to the pixels */
|
||||||
|
if (SDL_MUSTLOCK (dest))
|
||||||
|
if (SDL_LockSurface (dest) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org))
|
||||||
|
if (SDL_LockSurface (org) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
for (x = 0; x < org->w; x++)
|
||||||
|
for (y = 0; y < org->h; y++) {
|
||||||
|
pixel = getpixel (org, x, y);
|
||||||
|
if (x == 0 && y == 0)
|
||||||
|
transpixel = pixel;
|
||||||
|
if (pixel != transpixel) {
|
||||||
|
SDL_GetRGB (pixel, org->format, &r, &g, &b);
|
||||||
|
gray = (r / 3 + g / 3 + b / 3);
|
||||||
|
pixel = SDL_MapRGB (dest->format, gray, gray, gray);
|
||||||
|
}
|
||||||
|
putpixel (dest, x, y, pixel);
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org)) {
|
||||||
|
SDL_UnlockSurface (org);
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel);
|
||||||
|
return dest;
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_Surface *
|
||||||
|
gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SDL_Surface * org4)
|
||||||
|
{
|
||||||
|
Uint32 pixel;
|
||||||
|
SDL_Surface *dest;
|
||||||
|
int y,
|
||||||
|
x;
|
||||||
|
|
||||||
|
dest = SDL_CreateRGBSurface (SDL_HWSURFACE, org1->w, org1->h, org1->format->BitsPerPixel,
|
||||||
|
org1->format->Rmask, org1->format->Gmask,
|
||||||
|
org1->format->Bmask, org1->format->Amask);
|
||||||
|
if (dest == NULL) {
|
||||||
|
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lock the screen for direct access to the pixels */
|
||||||
|
if (SDL_MUSTLOCK (dest))
|
||||||
|
if (SDL_LockSurface (dest) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org1))
|
||||||
|
if (SDL_LockSurface (org1) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org2))
|
||||||
|
if (SDL_LockSurface (org2) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org3))
|
||||||
|
if (SDL_LockSurface (org3) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK (org4))
|
||||||
|
if (SDL_LockSurface (org4) < 0) {
|
||||||
|
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
for (x = 0; x < org1->w / 2; x++)
|
||||||
|
for (y = 0; y < org1->h / 2; y++) {
|
||||||
|
pixel = getpixel (org1, x, y);
|
||||||
|
putpixel (dest, x, y, pixel);
|
||||||
|
}
|
||||||
|
for (x = org1->w / 2; x < org1->w; x++)
|
||||||
|
for (y = 0; y < org1->h / 2; y++) {
|
||||||
|
pixel = getpixel (org2, x, y);
|
||||||
|
putpixel (dest, x, y, pixel);
|
||||||
|
}
|
||||||
|
for (x = 0; x < org1->w / 2; x++)
|
||||||
|
for (y = org1->h / 2; y < org1->h; y++) {
|
||||||
|
pixel = getpixel (org3, x, y);
|
||||||
|
putpixel (dest, x, y, pixel);
|
||||||
|
}
|
||||||
|
for (x = org1->w / 2; x < org1->w; x++)
|
||||||
|
for (y = org1->h / 2; y < org1->h; y++) {
|
||||||
|
pixel = getpixel (org4, x, y);
|
||||||
|
putpixel (dest, x, y, pixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_MUSTLOCK (org1))
|
||||||
|
SDL_UnlockSurface (org1);
|
||||||
|
if (SDL_MUSTLOCK (org2))
|
||||||
|
SDL_UnlockSurface (org2);
|
||||||
|
if (SDL_MUSTLOCK (org3))
|
||||||
|
SDL_UnlockSurface (org3);
|
||||||
|
if (SDL_MUSTLOCK (org4))
|
||||||
|
SDL_UnlockSurface (org4);
|
||||||
|
if (SDL_MUSTLOCK (dest)) {
|
||||||
|
SDL_UnlockSurface (dest);
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SDL_Surface *
|
||||||
|
gfx_copyscreen (SDL_Rect * wnd)
|
||||||
|
{
|
||||||
|
SDL_Surface *res;
|
||||||
|
SDL_Rect dest;
|
||||||
|
res =
|
||||||
|
SDL_CreateRGBSurface (SDL_HWSURFACE, wnd->w, wnd->h, gfx.screen->format->BitsPerPixel,
|
||||||
|
gfx.screen->format->Rmask, gfx.screen->format->Gmask,
|
||||||
|
gfx.screen->format->Bmask, gfx.screen->format->Amask);
|
||||||
|
dest.x = 0;
|
||||||
|
dest.y = 0;
|
||||||
|
dest.w = wnd->w;
|
||||||
|
dest.h = wnd->h;
|
||||||
|
SDL_BlitSurface (gfx.screen, wnd, res, &dest);
|
||||||
|
return res;
|
||||||
|
};
|
Loading…
Reference in new issue