Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

OpenGLView - Coordinate System Problem w/ GL.Viewport, Ortho & View Matrices

m11hutm11hut USMember
edited June 2017 in Xamarin.Forms

Hello, I've been trying to get my Xamarin.Forms.OpenGLView, OpenGL context setup to display simple lines by utilizing an Orthographic & View matrix that I pass over to my shader as a uniform. The shader works and I am able to get lines to draw if I disregard these matrices and the GL.Viewport functionality.

I've been basing my code on this example:

The main problem I've encountered when I get something that kind of works is my (0,0) origin always appears to be the bottom center of the emulated device. I'm wanting to be able to maintain the standard device coordinates (-1,-1) -> (1,1) that my coordinates will transform into.

Here is my render code for what I am trying to do:
This is the InitOpengl functionality :

My verts array is defined as: float[] verts = { 0, 0, 0, 100, 100, 0};

Something is wrong with my matrices and I'm not sure what, my shader functionality is working great. Thank you for any insight and information.


  • m11hutm11hut USMember

    When I change my render code to be just:

    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
    //GL.Viewport(0, 0, m_vpWidth, m_vpHeight);

    float ratio = (float)m_vpWidth / m_vpHeight;
    m_projMatrix = Matrix4.CreateOrthographicOffCenter(-ratio, ratio, -1f, 1f, -1f, 1f);
    m_viewMatrix = Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);
    m_mvpMatrix = m_projMatrix * m_viewMatrix;

    I do get lines to draw, but the coordinate system makes absolutely no sense. (0,0) appears to be the middle center of the device. I also changed my verts[] to be: (0, 0, 0) and (1,1, 0). Where the (1, 1) seems to go off somewhere to the top right. I don't have any idea why this is not working as expected, and it doesn't make any sense.

    The only thing I can think of is the Xamarin.Forms.OpenGLView is doing something behind the scenes.

Sign In or Register to comment.