[SDL] Trying to display a colored surface

carlos citrouille at wanadoo.fr
Mon Jul 15 06:01:00 PDT 2002


And I made a mistake at the begining of my test declaration you must
understant "SDL_Surface *test", and not "SDL_Surface test"

:)

----- Original Message -----
From: "Carlos" <citrouille at wanadoo.fr>
To: <sdl at libsdl.org>
Cc: <jason at cerebral-bicycle.co.uk>
Sent: Monday, July 15, 2002 12:57 PM
Subject: Re: [SDL] Trying to display a colored surface


> I will explain better my problem...
> I have no error but I still get a black screen
>
> I do :
>
> ***
> SDL_Surface test;
> test =
SDL_CreateRGBSurface(SDL_SWSURFACE,100,100,16,rmask,gmask,bmask,amask);
//mask are already setup
> //this creates for me a 100x100 square, right ?
> ***
>
> So I thought that my memory surface would be fully size and create.
> then I create just one rectangle to give position into the screen
>
> ***
> SDL_Rect r;
> r.x = 150; r.y=150; //this mean that I want to place "test" at position
150,150 in the screen, right ?
> ***
>
> and I fill my rectangles to be sure I see somethink
> (here starts the main loop)
>
> ***
> SDL_FillRect(screen, NULL, 0x00000000); //screen set to black, screen is a
1024x768x16 window
> SDL_FillRect(test, NULL, 0xFFFFFF00); //test to white
> ***
>
> finally I blit
>
> ***
> SDL_BlitSurface(test,NULL,screen,&d); //In the official documentation, it
is written that passing NULL to second argument takes entire source surface,
so won't be my "test" surface entirely blitted ???
>
> SDL_Flip(screen)
> ***
> The result is that I still get a black screen... :/ no white square at
position (150,150)
>
>
>
> Mon, 15 Jul 2002 08:42:21 +0000
> Jason Farmer <jason at cerebral-bicycle.co.uk> a écrit:
>
> > Hi Carlos,
> >
> > If you don't include all of the code in your example, other people can't
> > compile it on their systems. This makes finding bugs difficult.
> > You have omitted the screen setup code, the bug may be in there and we
> > wouldn't know. Also, you haven't said what he actual problem is or what
you
> > see on the screen. Does the screen go black or do you get an error of
some
> > kind?
> >
> > I think you may be getting your rects confused.
> > You haven't defined a width or height for the rect r so they will be
random
> > values.
> >
> > Also, you are passing nil to the SDL_BlitSurface function for your
destination
> > rect. You would only ever do this if your surface that you are blitting
> > covers the whole of the screen.
> >
> > May I suggest that you create a destination rect. (the destination rect
tells
> > SDL where to draw the image, but you have left yours blank)
> >
> > SDL_Rect d;
> >
> > d.x = 100;
> > d.y = 100;
> > d.w = 20;
> > d.h = 20;
> >
> > then alter your source rect (the source rect tells SDL where to get the
data
> > from to draw to the screen)
> >
> > r.x = 0;
> > r.y = 0;
> > r.w = 20;
> > r.h = 20;
> >
> > SDL_BlitSurface(test,&d,screen,&r);
> >
> > All this aside, If you just want to display a coloured square, why not
take a
> > look at SDL_FillRect
> >
> > Hope this helps
> >
> > Jason
> >
> > > I already know how to setup a screen window, that's why I don't
specify the
> > > code for the screen variable. Below the comments " /* window  ... */
",
> > > just after le SDL_Rect declaration, you must understand that I put a
window
> > > setup for "screen" (which uses le SDL_SetVideoMode)
> > >
> > > Just the think I want to do, is drawing a little square into the
screen
> > > WITH the "test" variable...
> > >
> > > > > 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.
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > SDL mailing list
> > > > SDL at libsdl.org
> > > > http://www.libsdl.org/mailman/listinfo/sdl
> > >
> > > _______________________________________________
> > > SDL mailing list
> > > SDL at libsdl.org
> > > http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>






More information about the SDL mailing list