2D GL circle Render problem

Howdy, I am currently working on a system for visualizing datapoints in unity (based on an imported excel file). Long story short, I am now on the final leg where i am trying to draw the points as circles. The center coordinates are coming in as Screen coordinates (pixel width/height) and I have tried converting them to both world points and viewport points, but i am not managing to make the circles draw in any.

The class is called by one attribute class I’ve made and the DrawCircle method is being called from void OnPostRender(). Additionally to this everything is being called and is most probably drawing somewhere off screen. I am currently at a loss for ideas, so I was wondering if anyone could take a look.

    using UnityEngine;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    public class Circle 
    {
    	private Vector3 center;
    	private float radius;
    	private Camera cam;
    	private Material mat;
    	
    	public Circle(Vector2 center, float radius)
    	{
    		this.cam = Camera.main;
    		this.center = new Vector3(center.x, center.y, cam.nearClipPlane + 1.00001f);
    		this.radius = radius;
    		Debug.Log(this.center);
    		this.mat = new Material( "Shader \"Lines/Colored Blended\" {" +
    		                            "SubShader { Pass {" +
    		                            "   BindChannels { Bind \"Color\",color }" +
    		                            "   Blend SrcAlpha OneMinusSrcAlpha" +
    		                            "   ZWrite Off Cull Off Fog { Mode Off }" +
    		                            "} } }");
    	}
    	public void DrawCircle(Color color)
    	{
    		GL.PushMatrix();
    		mat.SetPass(0);
    		GL.MultMatrix(cam.transform.localToWorldMatrix);
    		GL.Begin(GL.LINES);
    		GL.Color(Color.red);
    		float degRad = Mathf.PI / 180;
    		Vector3 ci = new Vector3(Mathf.Cos(degRad) * radius + center.x, Mathf.Sin(degRad) * radius + center.y, center.z);
    		Debug.Log(ci);
    		for(float i = 0.0f; i < 360; i++)
    		{
    			GL.Vertex3(ci.x, ci.y, ci.z);
    			degRad*=i;
    			ci = new Vector3(Mathf.Cos(degRad) * radius + center.x, Mathf.Sin(degRad) * radius + center.y, center.z);
    			GL.Vertex3(ci.x, ci.y, ci.z);
    		}
    		GL.End();
    		GL.PopMatrix();
    	}
    }

So, as it turns out my circle calculations we’rent updating. So I decided to rewrite and modify it. It now works. :slight_smile:

        GL.PushMatrix();
		mat.SetPass(0);
		GL.Begin(GL.LINES);
		GL.Color(color);
		float degRad = Mathf.PI / 180;
		for(float theta = 0.0f; theta < (2*Mathf.PI); theta += 0.01f)
		{
			Vector3 ci = (new Vector3(Mathf.Cos(theta) * radius + center.x, Mathf.Sin(theta) * radius + center.y, center.z));
			GL.Vertex3(ci.x, ci.y, ci.z);
		}
		GL.End();
		GL.PopMatrix();