Hello, I’ve got a little problem using an SDL surface (SDL_Surface). When I create a new surface using SDL_CreateRGBSurface(), I can’t draw it to the screen, it just doesn’t appears.
This is my code:
Code:
//////////////
// main.cpp //
//////////////
#include <SDL/SDL.h>
extern SDL_Surface *screen;
int main(int argc, char *argv[])
{
game_init(); // my function, inits SDL, the window (screen) etc., window appears
// screen size is 640x480, color depth is 24 bit (no alpha, right?)
screenFill(0xFF0000); // my function, filling screen to red, works after updating screen
// a simple copy from the SDL API Reference:
/* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
as expected by OpenGL for textures */
SDL_Surface *sf;
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
sf = SDL_CreateRGBSurface(SDL_SWSURFACE, 64, 64, 24,
rmask, gmask, bmask, amask);
if(sf == NULL)
{
error(“Error!”); // I don’t get an error
exit(1);
}
// usually, because the surface (sf) is 24 bit (no alpha), it should have any color (e.g. black)
SDL_BlitSurface(sf, NULL, screen, NULL);
SDL_UpdateRect(screen, 0, 0, 0, 0);
// I now only see a red screen, I can nowhere find a 64x64 square colored different on the screen
waitForClose(); // my function, waits until the user closes the window
return 0;
}
I found out, that it would work, if I just use SDL_LoadBMP(), but why does this not work?
Can anybody help me out or suggest, where the mistake might be?