| | |
Iteration through my vector of pixels.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 4
Reputation:
Solved Threads: 0
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
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!
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!
•
•
Join Date: Apr 2009
Posts: 4
Reputation:
Solved Threads: 0
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!
Thanks in advance.
// ixuz
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!
Thanks in advance.
// ixuz
Last edited by ixuz; Apr 1st, 2009 at 7:42 pm.
Alas, I just googled it.
Try searching for things like "bresenham line circle ellipse algorithm".
Speed comes from doing the least to draw individual pixels. Hence, a lot of optimization comes from low-level accesses. In modern GUI architectures, often the case is for pixel access to occur in memory (in-memory bitmaps/pixmaps and the like), and then have the WM/OS/whatever copy the image to the graphics hardware. When you move to more direct accesses (like DirectX, etc.) then you must minimize accesses to the hardware yourself -- since it is slower than normal memory accesses.
Hope this helps.
Try searching for things like "bresenham line circle ellipse algorithm".
Speed comes from doing the least to draw individual pixels. Hence, a lot of optimization comes from low-level accesses. In modern GUI architectures, often the case is for pixel access to occur in memory (in-memory bitmaps/pixmaps and the like), and then have the WM/OS/whatever copy the image to the graphics hardware. When you move to more direct accesses (like DirectX, etc.) then you must minimize accesses to the hardware yourself -- since it is slower than normal memory accesses.
Hope this helps.
![]() |
Other Threads in the C++ Forum
- Previous Thread: void pointer problem
- Next Thread: Basic C++ program assitance
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






