High quality drawings?

Hi.
I’m a SDL beginner and I’ve just managed to draw some rectangles, ellipses
on the screen: Here is basically the code:
I use 640x480 display.

while(1){
SDL_FillRect(screen,0,0x0000000); //clear screen
draw a lot of filledEllipseColor(…) and boxColor(…) at position (x,y)
x++; y++; // move the figures
usleep(19232); //pause

check for SDL_Event with SDL_PollEvent to see if we should quit drawing.

}

The result is awfully dark. If I remove the SDL_FillRect part I get much
brighter colours, but also I get a trail of all the drawings. I just want
to see my figures travel across the screen.

So, how do you do these line, polygon, circle drawings and get good result?
I guess I’m missing something essential here…

Gunnar G wrote, on or about 7/8/2005 12:59 PM:

Hi.
I’m a SDL beginner and I’ve just managed to draw some rectangles, ellipses
on the screen:

[code deleted]

The result is awfully dark. If I remove the SDL_FillRect part I get much
brighter colours, but also I get a trail of all the drawings. I just want
to see my figures travel across the screen.

So, how do you do these line, polygon, circle drawings and get good result?
I guess I’m missing something essential here…

Odds are good you are doing alpha blending, which you probably
don’t want at this point. Check the color/function you are using
to draw the shapes. You probably want the alpha to be 0 (or is
it 255, I forget…), if it is something like 0x80, it’ll give
the results you are seeing.

  • Tim

Odds are good you are doing alpha blending, which you probably
don’t want at this point.
Check the color/function you are using
to draw the shapes. You probably want the alpha to be 0 (or is
it 255, I forget…), if it is something like 0x80, it’ll give
the results you are seeing.

If I just want to use RGB colours, i.e. three unsigned 8-bit values, what
should I do?
In the SDL_gfxprimitives.h it says: Uint32 as the datatype for the
colour.

I guess I should instead ask the question: what is the absolutly best thing
to read to learn about SDL? One feel a little resistant to order a book
that is 2-3 years old. Things are developing so fast…

Gunnar G wrote:

Tim Oertel wrote:

Odds are good you are doing alpha blending, which you probably
don’t want at this point.
Check the color/function you are using
to draw the shapes. You probably want the alpha to be 0 (or is
it 255, I forget…), if it is something like 0x80, it’ll give
the results you are seeing.

If I just want to use RGB colours, i.e. three unsigned 8-bit values, what
should I do?
In the SDL_gfxprimitives.h it says: Uint32 as the datatype for the
colour.

Yes, for the *Color() primitives, it is a 32 bit value. It is RRGGBBAA, so for
red, you’d use 0xFF0000FF, or black you’d use 0x000000FF. For a somewhat
transparent blue, you could use 0x0000FF7F.

If you aren’t familiar with alpha blending, draw a few overlapping boxes,
with a given alpha value, a little playing should give you a decent feel
for it.

For instance:
boxColor(surf, 0, 0, 200, 200, 0xFF000020);
boxColor(surf, 20, 20, 220, 220, 0xFF000020);
boxColor(surf, 40, 40, 240, 240, 0xFF000020);

boxColor(surf, 0, 300, 200, 500, 0x00FF0080);
boxColor(surf, 20, 320, 220, 520, 0x00FF0080);
boxColor(surf, 40, 340, 240, 540, 0x00FF0080);

I guess I should instead ask the question: what is the absolutly best thing
to read to learn about SDL? One feel a little resistant to order a book
that is 2-3 years old. Things are developing so fast…

SDL is pretty nice in that the API is pretty straight forward, and there
is a goodly amount of documentation out there. I used the API reference,
and that took me most of the way. There is also a LARGE amount of source
code that uses SDL, including quite a few example programs. That’s what
I’d recommend.