0

I need to know how to draw transparent circle/ellipse using OpenTK in Xamarin.Forms.

I have tried with creating Vertex and Fragment shaders with reference of following link : How to draw circle on OpenGL ES 2.0 cross platform? But did not get anything on screen it is showing blank on screen.

Below is the Sample Code used to draw circle with OpenTK in Xamarin.Forms.

        GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        GL.Enable(EnableCap.DepthTest);


        GL.UseProgram(programID);
        // The locations where we pass in our color and vertex data
        positionInput = GL.GetAttribLocation(programID, "Position");
        colorInput = GL.GetAttribLocation(programID, "SourceColor");
        // The locations where we pass in unchanging data
        projectionInput = GL.GetUniformLocation(programID, "Projection");
        modelviewInput = GL.GetUniformLocation(programID, "Modelview");

        Matrix4 modelview = Matrix4.CreateRotationX(rotation) * Matrix4.CreateRotationY(rotation) * Matrix4.CreateRotationZ(rotation) * Matrix4.CreateTranslation(xTranslation, yTranslation, -7f);
        GL.UniformMatrix4(modelviewInput, false, ref modelview);

        float h = 4.0f * (height / width);
        Matrix4 projection = Matrix4.CreatePerspectiveOffCenter(-2, 2, -h / 2f, h / 2f, 4, 10);
        GL.Viewport(0, 0, (int)width, (int)height);
        GL.UniformMatrix4(projectionInput, false, ref projection);



        GL.BindBuffer(BufferTarget.ArrayBuffer, colorDataBuffer);
        GL.EnableVertexAttribArray(colorInput);
        GL.VertexAttribPointer(colorInput, 4, VertexAttribPointerType.Float, false, 0, 0);


       float DEGREE_TO_RAD = (float)( 3.14 / 180);
        int M_IN_DEGREE = 370;
        int N_IN_DEGREE = 100;
        int nCount = 1;
        int index = 0;
        int size = 2;
        float[] stVertexArray = new float[2*360];

        stVertexArray[0] = 0;
        stVertexArray[1] = 0;

        for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
        {
            float fX = (float) System.Math.Sin((float)nR * DEGREE_TO_RAD ) ;
            float fY = (float) System.Math.Cos((float)nR * DEGREE_TO_RAD );
            stVertexArray[nCount*2] = fX;
            stVertexArray[nCount*2 + 1] = fY;
            nCount++;
        }
        GL.BindBuffer(BufferTarget.ArrayBuffer, stVertexArray.Length);
        GL.EnableVertexAttribArray(0);


        GL.VertexAttribPointer (index,size, VertexAttribPointerType.Float, false, stVertexArray.Length, IntPtr.Zero);

        GL.DrawElements(BeginMode.LineLoop, stVertexArray.Length, DrawElementsType.UnsignedByte,stVertexArray);

        GL.Finish();
Community
  • 1
  • 1
Brijesh
  • 235
  • 3
  • 22
  • How are you hooking this up to XF? – Sten Petrov Sep 28 '15 at 16:37
  • I have used OpenGLView to hook this in Xamarin Forms. – Brijesh Sep 29 '15 at 10:14
  • If you're hoping for an answer you should post a sample project, this is an edge case, I wouldn't expect a lot of people have used it, just looking at a fragment doesn't mean anything. For all I know this code may be perfectly fine but not hooked up properly to the underlying framework. Are you able to draw *anything*? Is it just the circle that's causing you headaches or nothing shows up at all, whatever you've tried – Sten Petrov Sep 29 '15 at 17:02

0 Answers0