Function for circle

I wrote a function in C++ visual for circle. Was wondering is it legit. Im total newbie so please be gentle :)

If you have better one please post it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  void D3DGraphics::DrawCircle( int cordX,int cordY, int r, int red, int green, int blue )
{
		for( int x = 0 ; x < r ; x++ )
	{
	int y = sqrt( float( r * r - x * x ) ) + 0.5f;
	PutPixel( cordX + x,cordY + y,red,green,blue );
	PutPixel( cordX - x,cordY - y,red,green,blue );
	PutPixel( cordX - x,cordY + y,red,green,blue );
	PutPixel( cordX + x,cordY - y,red,green,blue );
	if( y < x )
		break;
	}
		for( int y = 0 ; y < r ; y++ )
	{
	int x = sqrt( float( r * r - y * y ) ) + 0.5f;
	PutPixel( cordX + x,cordY + y,red,green,blue );
	PutPixel( cordX - x,cordY - y,red,green,blue );
	PutPixel( cordX - x,cordY + y,red,green,blue );
	PutPixel( cordX + x,cordY - y,red,green,blue );
	if( x < y )
		break;
	} 
}
Plotting individual pixels on the CPU side is going to be slow. Stuff like this is often best done by rendering a dummy polygon and doing the actual pixel plotting in the shader.

An example of how it can be done in OpenGL is here. I'm not familiar with D3D shaders, but the concept is probably similar:

http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2013.html
Topic archived. No new replies allowed.