SDL beginner: create Rectangle surface filled with color

Posted by user3689 on Game Development See other posts from Game Development or by user3689
Published on 2011-08-25T04:56:57Z Indexed on 2012/03/21 17:39 UTC
Read the original article Hit count: 180

Filed under:
|

im learning SDL , i like to create Rectangle surface with color
that is not image . here is my code that compiles fine but dosnt work :
im passing the function this params:

SDL_Surface*  m_screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);
SDL_FillRect(m_screen,&m_screen->clip_rect,SDL_MapRGB(m_screen->format,0xFF, 0xFF, 0xFF));
...
Button button(m_screen,0,0,50,50,255,0,0)
...
...
Button::Button(SDL_Surface* screen,int x,int y,int w,int h,int R, int G, int B)
      {
      SDL_Rect box;
      SDL_Surface * ButtonSurface;
      ButtonSurface = NULL ;
      Uint32 rmask, gmask, bmask, amask;
      #if SDL_BYTEORDER == SDL_BIG_ENDIAN
         rmask = 0xff000000;
         gmask = 0x00ff0000;
         bmask = 0x0000ff00;
         amask = 0x000000ff;
      #else
         rmask = 0x000000ff;
         gmask = 0x0000ff00;
         bmask = 0x00ff0000;
         amask = 0xff000000;
      #endif




      box.x = x;
      box.y = y;
      box.w = w;
      box.h = h;

      ButtonSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, box.w,box.h, 32,
                                    rmask, gmask, bmask, amask);

      if(ButtonSurface == NULL)
      {
         LOG_MSG("Button::Button Button failed");

      }


      SDL_FillRect(screen,&box,SDL_MapRGB ( ButtonSurface->format, R, G, B ));


      //ut.ApplySurface(0,0,ButtonSurface,screen);
      SDL_BlitSurface(ButtonSurface,NULL,screen,&box);
   }

what im doing here wrong ?

© Game Development or respective owner

Related posts about c++

Related posts about sdl