# High quality drawings?

**URL:** <https://discourse.libsdl.org/t/high-quality-drawings/12343>\
**Category:** SDL Development\
**Created:** [July 8, 2005, 4:59pm UTC](https://discourse.libsdl.org/t/high-quality-drawings/12343 "2005-07-08T16:59:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunnar\_G](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gunnar\_G](https://discourse.libsdl.org/u/Gunnar_G)\
**Post date:** [July 8, 2005, 4:59pm UTC](https://discourse.libsdl.org/t/high-quality-drawings/12343/1 "2005-07-08T16:59:19Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Tim\_Oertel](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@Tim\_Oertel](https://discourse.libsdl.org/u/Tim_Oertel)\
**Post date:** [July 8, 2005, 7:23pm UTC](https://discourse.libsdl.org/t/high-quality-drawings/12343/2 "2005-07-08T19:23:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gunnar\_G](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gunnar\_G](https://discourse.libsdl.org/u/Gunnar_G)\
**Post date:** [July 8, 2005, 9:39pm UTC](https://discourse.libsdl.org/t/high-quality-drawings/12343/3 "2005-07-08T21:39:32Z")

</div>

> 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…

---

<div class="post-metadata">

**Author:** ![Tim\_Oertel](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@Tim\_Oertel](https://discourse.libsdl.org/u/Tim_Oertel)\
**Post date:** [July 8, 2005, 10:31pm UTC](https://discourse.libsdl.org/t/high-quality-drawings/12343/4 "2005-07-08T22:31:13Z")

</div>

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.
