Jump to content
  • Advertisement
Sign in to follow this  
dEgle95

OpenGL Problem with creating SDL surfaces

This topic is 2178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 smile.png

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!