Hello there!

I'm having problem with my drawing graphics programming, let's say I want to draw a circle.

This circle is made out of smaller pieces called pixels.

Okay I got a pixelclass containing three values x, y and color.
My circle contains a vector which contains all the pixels that the circle is made of.

If I make a circle with a radius of 100, I get to draw 31417 pixels. If I draw all these ones as often as my program allows, my program only max out ~97fps.

I wonder is it supposed to be this slow to loop 31 thousand times and drawing one pixel each time? Am I storing these pixels the wrong way? Is vector a bad choice, what other type of storing structure would I use instead?

Thanks for any help.
// ixuz

Oy! Please don't use a vector (or any other STL container) to hold individual pixel data -- Just draw directly to the target surface.

Also, you needn't directly calculate every pixel in the circle. One quarter of them is sufficient. (That is, calculate 1/4 of the circle, and draw four pixels each step.)

Good luck!

Okay thanks alot, I removed this vector holding pixels thing and I understand what you mean by doing more than one pixel each loop, the thought that came to my mind when you told me this was:

When I'm going to draw a line of pixels, shouldn't I use a for loop? Or is it faster by just repeating the drawPixel function 4 times in the source code?

thanks!
// ixuz

Edit: As soon as I started to program I realized what you ment by draw 4 pixels at the same time. I'm using pythagoras algorithm to calculate the distance to each pixel of the circle, to see if it's inside or outside the circles radius.

I'm drawing one circle with a radius of 150 using the graphic library SDL.
Your tips actually boosted up my drawing speed from 82circles per second to 119 circles per second thanks alot!

Is pythagoras a good or bad choice of algorithm? Is there any algorithms that are faster? Tips and tricks are welcome aswell!

// ixuz

Nice link! Any other recommendations per chance?