Tenía las siguientes funciones para configurar píxeles en una SDL_Surface. Hay dos versiones para superficies de 32 bits, 24 bits, 16 bits y 8 bits. Si solo quiere establecer un solo píxel, usaría las versiones normales. Pero si desea establecer un conjunto de píxeles, primero bloquea la superficie, luego utiliza la versión nolock (llamada así porque no bloquea la superficie) y luego se desbloquea. De esta forma, no estás bloqueando y desbloqueando la superficie repetidamente, lo que se supone que es una operación costosa, aunque no creo que alguna vez lo haya probado realmente.
void PutPixel32_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint32));
*((Uint32*)pixel) = color;
}
void PutPixel24_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint8) * 3);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
pixel[0] = (color >> 24) & 0xFF;
pixel[1] = (color >> 16) & 0xFF;
pixel[2] = (color >> 8) & 0xFF;
#else
pixel[0] = color & 0xFF;
pixel[1] = (color >> 8) & 0xFF;
pixel[2] = (color >> 16) & 0xFF;
#endif
}
void PutPixel16_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint16));
*((Uint16*)pixel) = color & 0xFFFF;
}
void PutPixel8_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint8));
*pixel = color & 0xFF;
}
void PutPixel32(SDL_Surface * surface, int x, int y, Uint32 color)
{
if(SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
PutPixel32_nolock(surface, x, y, color);
if(SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
}
void PutPixel24(SDL_Surface * surface, int x, int y, Uint32 color)
{
if(SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
PutPixel24_nolock(surface, x, y, color);
if(SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
}
void PutPixel16(SDL_Surface * surface, int x, int y, Uint32 color)
{
if(SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
PutPixel16_nolock(surface, x, y, color);
if(SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
}
void PutPixel8(SDL_Surface * surface, int x, int y, Uint32 color)
{
if(SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
PutPixel8_nolock(surface, x, y, color);
if(SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
}
im no cambiar cualquier pixel particular en este caso. simplemente estoy copiando todo e intentando copiarlo todo nuevamente. Y por formato, ¿qué quieres decir? – nory
¿Se da cuenta de que su código no hace nada? 'pantalla-> píxeles = pantalla-> píxeles;'. –
por supuesto.Solo estoy jugando, conociendo la sintaxis y cosas – nory