Sign in to follow this  
dEgle95

OpenGL Problem with creating SDL surfaces

Recommended Posts

Hello guys.
I'm developing a small game and I've bumped into problem with SDL surfaces.
I've written function for creating surfaces:
[source lang="cpp"]SDL_Surface *create_surface(int width, int height)
{
/* 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 *surface;
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;
}

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);
return surface;
}[/source]
But when i try to do something with it nothing happens:
[source lang="cpp"]Uint32 p_color;
p_color = SDL_MapRGB(screen->format,255,255,255);

SDL_Surface *srf = NULL;
srf = create_surface(16,16);

SDL_Rect temp;
temp.x = 0;
temp.y = 0;
temp.w = 16;
temp.h = 16;

SDL_FillRect(srf,&temp,p_color);

apply_surface(0,0, srf, screen, NULL); //simple function for blitting one surface to another.
[/source]

I definitely know that srf and screen are 32bits and function for creating surfaces was copied from SDL docs.
apply_surface function works perfectly for any loaded image.
Please, help me out with this simple problem [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
Oops....apparently generating format is not working, but if you take it from screen surface it'll do:)
Corrected function for creating surfaces, in case someone needs it:
[source lang="cpp"]SDL_Surface *create_surface(int width, int height, SDL_Surface *screen)
{
/* 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 *surface;
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
return surface;
}[/source]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this