Could somebody please just run this code and tell me what shows up?
This code makes a white background, and then tries to blit a red square
in the upper left corner, upper right corner, and lower left corner.
However, the one in the upper left corner turns up black, and the one
in the lower left corner doesn’t show up at all. Experiments with other
bit depths are even more screwed up.
#include<SDL.h>
#include<SDL_gfxPrimitives.h>
int main(int argc, char** argv)
{
SDL_Rect r;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(400, 400, 32, 0);
boxRGBA(SDL_GetVideoSurface(), 0, 0, 399, 399, 255, 255, 255, 255);
Uint32 mask1 = 0xff000000; Uint32 mask2 = 0x00ff0000;
Uint32 mask3 = 0x0000ff00; Uint32 mask4 = 0x000000ff;
SDL_Surface* s1 =
SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
boxRGBA(s1, 0, 0, 199, 199, 255, 0, 0, 254);
r.x = 0; r.y = 0;
SDL_BlitSurface(s1, 0, SDL_GetVideoSurface(), &r);
SDL_Surface* s2 =
SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
boxRGBA(s2, 0, 0, 199, 199, 255, 0, 0, 254);
r.x = 0; r.y = 200;
SDL_BlitSurface(s2, 0, SDL_GetVideoSurface(), &r);
SDL_Surface* s3 =
SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
boxRGBA(s3, 0, 0, 199, 199, 255, 0, 0, 255);
r.x = 200; r.y = 0;
SDL_BlitSurface(s3, 0, SDL_GetVideoSurface(), &r);
SDL_Flip(SDL_GetVideoSurface());
SDL_Event e;
for(; {
SDL_PollEvent(&e);
if(e.type == SDL_QUIT)
break;
}
}