Drawing a GUI circle with a specific radius

Hi,
Short and straight question, can I somehow draw a circle with a specific radius on screen without using a texture? :slight_smile:

Bump. Is there really no way to draw a simple circle in such a powerful engine? :face_with_spiral_eyes:

1 Like

i think in pro we can do using gl class

Well, GL class can be used in free version too.
After a quick research on the internet, I found some circle drawing formulas and applied one of them:

private Material lineMaterial;
void Awake()
{
	lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
        "SubShader { Pass {" +
        "   BindChannels { Bind \"Color\",color }" +
        "   Blend SrcAlpha OneMinusSrcAlpha" +
        "   ZWrite Off Cull Off Fog { Mode Off }" +
        "} } }");
	lineMaterial.hideFlags = HideFlags.HideAndDontSave;
	lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
void OnPostRender()
{
	const float DEG2RAD = 3.14159f/180;
	float radius = 50;
    GL.Begin(GL.LINES);
	lineMaterial.SetPass(0);
	GL.Color(Color.red);
	float x = 50;
	float y = 50;
	for (int i=0; i< 360; i++)
	{
		float degInRad = i*DEG2RAD;
		GL.Vertex(camera.ScreenToWorldPoint(new Vector3(x, y, camera.nearClipPlane)));
		GL.Vertex(camera.ScreenToWorldPoint(new Vector3(x + Mathf.Cos(degInRad)*radius, y + Mathf.Sin(degInRad)*radius, camera.nearClipPlane + 0.00001f)));
	}
	GL.End();
}

This is what I get:
1289517--58919--$NGnevj6.png

How can I make the circle smoother?
EDIT: nevermind, I’ll just use a texture for this… Few kilobytes more in memory probably won’t change anything. :).

:slight_smile:

Unity isn’t meant to be a 2D Vector renderer.

I’ve also been experimenting with drawing the circle using the texture routines (SetPixel etc.) which turned out to be so slooow. Also stuck with anti-aliasing.

i dont know why you want to do it without a texture. but if i were you i would have a look into vectrosity. this can draw your circle with a mesh with a texture on it in 2d and 3d space. but i think the circle is not filled then. you may ask eric5h5 how to achieve this if required.
and with vectrosity you get anti-aliasing out of the box.

Well, I thought it would be more optimised not to use a texture for something that “doesn’t require texture”. But it’s not worth, so I did it with a circle texture :).

1 Like