Name: Anonymous 2009-11-30 3:58
Ok, this is my minimal testcase for a problem I'm having with SDL_CreateRGBSurface(), or something around that area... It's supposed to display a white box but something is wrong with the mask values I give to SDL_CreateRGBSurface and the only color I can get is this dark red. I know it has nothing to do with the palette values so don't even bother. Can anyone who's familiar with SDL tell me how to fix this shit?
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <SDL/SDL.h>
void setpalette(SDL_Surface* surface);
/*** Main Entry ***/
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) {
SDL_Surface* screen;
SDL_Event event;
/* Start SDL */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
printf("Failed to initialize a subsystem.\n");
exit(1);
}
assert((screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE)) != NULL);
setpalette(screen);
// Clear the screen
SDL_FillRect(screen, NULL, 0);
SDL_Surface *area;
SDL_Rect rectarea = { 100, 100, 400, 400 };
/*** FAIL TIEM ***/
area = SDL_CreateRGBSurface(SDL_SWSURFACE, 111, 221, 8, 0x000000FF,0x0000FF00,0x00FF0000,0);
assert(area != NULL);
assert(!SDL_FillRect(area, NULL, 15)); // Color 15 should give me a white box
SDL_BlitSurface(area, NULL, screen, &rectarea);
SDL_Flip(screen);
SDL_FreeSurface(area);
while (1) {
SDL_PollEvent(&event);
if (event.key.type == SDL_KEYDOWN) {
// Escape: exit the program
if (event.key.keysym.sym == SDLK_ESCAPE)
break;
}
}
SDL_Quit();
return 0;
}
void setpalette(SDL_Surface* surface) {
SDL_Color colors[256];
colors[0].r = 0; colors[0].g = 0; colors[0].b = 0;
colors[15].r = 255; colors[15].g = 255; colors[15].b = 255;
SDL_SetColors(surface, colors, 0, 256);
}