PDA

Ver la versión completa : SDL aumentar una imagen



robloz
31/01/2009, 17:52
Hola estoy trabajando con unos titles muy pequeños asik el tamaño de la ventana es demasiado pequeño por eso quiero poder redimensionarla de manera que se aumente los titles (y no de que se muestre más parte del mapa), es decir mi objetivo es el mismo que ocurre cuando redimensionas una pantalla de un programa (que la imagen aumenta sola) es conseguir más o menos el mismo efecto que "SDL_FULLSCREEN" pero controlando el tamaño

Gracias.

Aiken
31/01/2009, 19:31
supongo que SDL rotozoom te podria valer. es una libreria adicional a la sdl, pero que ya funcionaba con gp32 asi que supongo que te funcionara con gp2x.

Aiken

LTK666
31/01/2009, 20:49
Espero que esto te pueda ayudar.

Extraído de http://www.sdltutorials.com/sdl-scale-surface y añadidas las funciones ReadPixel y DrawPixel


Uint32 ReadPixel(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 DrawPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
Here p is the address to the pixel we want to set
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;
}
}

Aquí la función. Devuelve una SDL_Surface con el tamaño indicado en Width Height


SDL_Surface *ScaleSurface(SDL_Surface *Surface, Uint16 Width, Uint16 Height)
{
if (!Surface || !Width || !Height)
return 0;

SDL_Surface *_ret = SDL_CreateRGBSurface(Surface->flags, Width, Height, Surface->format->BitsPerPixel,
Surface->format->Rmask, Surface->format->Gmask, Surface->format->Bmask, Surface->format->Amask);

double _stretch_factor_x = (static_cast<double>(Width) / static_cast<double>(Surface->w)),
_stretch_factor_y = (static_cast<double>(Height) / static_cast<double>(Surface->h));

for (Sint32 y = 0; y < Surface->h; y++)
for (Sint32 x = 0; x < Surface->w; x++)
for (Sint32 o_y = 0; o_y < _stretch_factor_y; ++o_y)
for (Sint32 o_x = 0; o_x < _stretch_factor_x; ++o_x)
DrawPixel(_ret, static_cast<Sint32>(_stretch_factor_x * x) + o_x,
static_cast<Sint32>(_stretch_factor_y * y) + o_y, ReadPixel(Surface, x, y));

return _ret;
}

robloz
01/02/2009, 15:39
Gracias parece k esto es lo k me hacía falta XD