Hello,
Could anybody tell me why I see a BLUE screen with this code when I expected
to see a GREEN one?
SDL_Surface *superficieImagen, *superficieAuxiliar;
int ancho = 640;
int alto = 480;
int main() {
superficieImagen = SDL_SetVideoMode(ancho, alto, 32, SDL_SWSURFACE);
if (superficieImagen == NULL) {
fprintf(stderr, “No se puede establecer el modo de video: %s\n”,
SDL_GetError());
exit(1);
}
superficieAuxiliar = SDL_CreateRGBSurface(SDL_SWSURFACE, ancho, alto, 32,
superficieImagen->format->Rmask, superficieImagen->format->Gmask,
superficieImagen->format->Bmask, superficieImagen->format->Amask);
if (SDL_MUSTLOCK(superficieImagen)) {
if (SDL_LockSurface(superficieImagen) < 0) {
fprintf(stderr, “No puedo bloquear la pantalla: %s\n”, SDL_GetError());
return -1;
}
}
for (int y=0;y<alto;y++) {
for (int x=0;x<ancho;x++) {
*((Uint32 )superficieImagen->pixels + yancho + x) = 0xFF0000FF;
}
}
if (SDL_MUSTLOCK(superficieImagen)) {
SDL_UnlockSurface(superficieImagen);
}
if (SDL_MUSTLOCK(superficieAuxiliar)) {
if (SDL_LockSurface(superficieAuxiliar) < 0) {
fprintf(stderr, “No puedo bloquear la pantalla: %s\n”, SDL_GetError());
return -1;
}
}
for (int y=0;y<alto;y++) {
for (int x=0;x<ancho;x++) {
*((Uint32 )superficieAuxiliar->pixels + yancho + x) = 0xFF00FF00;
}
}
if (SDL_MUSTLOCK(superficieAuxiliar)) {
SDL_UnlockSurface(superficieAuxiliar);
}
superficieImagen->pixels = superficieAuxiliar->pixels;
SDL_UpdateRect(superficieImagen, 0, 0, 0, 0);
pause();
return 0;
}
It seems that the instruction “superficieImagen->pixels =
superficieAuxiliar->pixels;” don’t do anything. I know that I can do this
with SDL_BlitSurface(superficieAuxiliar, NULL, superficieImagen, NULL) and
work correctly, but why it doesn’t work what I do?
ThanQ