Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem with creating SDL surfaces


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 dEgle   Members   -  Reputation: 131

Like
0Likes
Like

Posted 01 August 2012 - 07:42 AM

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 Posted Image

Sponsor:

#2 dEgle   Members   -  Reputation: 131

Like
0Likes
Like

Posted 01 August 2012 - 07:56 AM

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]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS