How do I create a curved line or filled circle or generally a circle using C++/SDL?

Posted by NoobScratcher on Game Development See other posts from Game Development or by NoobScratcher
Published on 2012-11-17T17:28:27Z Indexed on 2012/11/17 23:23 UTC
Read the original article Hit count: 273

Filed under:
|

Hello I've been trying for ages to make a pixel circle using the putpixel function provided by SDL main website here is that function :

void putpixel(int x,int y , int color , SDL_Surface* surface)
{
    unsigned int *ptr = static_cast <unsigned int *> (surface->pixels);

    int offset = y * (surface->pitch/sizeof(unsigned int));

    ptr[offset + x] = color;
}

and my question is how do I curve a line or create an circle arc of pixels or any other curved shape then a rectangle or singular pixel or line.

for example here are some pictures

filled pixel circle below enter link description here

now my idea was too

change the x and y value of the pixel position using + and - to create the curves but in practice didn't provide the correct results

what my results are in this is to be able to create a circle that is made out of pixels only nothing else.

thank you for anyone who takes the time to read this question

thanks! :D

© Game Development or respective owner

Related posts about c++

Related posts about pixel