[SDL] Trying to display a colored surface

Hongli Lai h.lai at chello.nl
Sun Jul 14 16:52:00 PDT 2002


On Mon, 2002-07-15 at 00:37, Carlos wrote:
> I am a newbie with SDL and I wanted to do the simplest think we can do, but this doesn't work.. This thing is displaying a colored square.
> 
> So i do this
> 
> *****
> 
> SDL_Surface *screen;
> SDL_Surface *test;
> SDL_Rect r;
> /* window setup an screen setup */
> 
> test = SDL_CreateRGBSurface(SDL_SWSURFACE,100,100,16,rmask,gmask,bmask,amask); //square setup
> 
> r.x = 100; r.y = 100;
> while(1) //main loop
> {
>   SDL_FillRect(screen, NULL, 0x00000000); //I color my screen to black
>   SDL_FillRect(test, NULL, 0xFFFFFF00); //I want to color my square to white
>   SDL_BlitSurface(test,NULL,screen,&r); //then draw it, this doen't work
> 
>   SDL_Flip(screen);		
> }
> 
> what can I do to just display a little colored square if not what I writen ???
> 

To setup a window you must use SDL_SetVideoMode().
SDL_CreateRGBSurface() creates an offscreen surface. I suggest you to
read some tutorials.






More information about the SDL mailing list