Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. public MainPage()
  2.     {
  3.       InitializeComponent();
  4.  
  5.       m_timeCounter = new Timer(16);
  6.       m_timeCounter.Elapsed += FrameTimeElapsed;
  7.       m_timeCounter.Start();
  8.  
  9.       m_ogl = new OpenGLView();
  10.       m_ogl.HeightRequest = Forms.Context.Resources.DisplayMetrics.HeightPixels;
  11.       m_ogl.WidthRequest  = Forms.Context.Resources.DisplayMetrics.WidthPixels;
  12.       m_ogl.HasRenderLoop = true;
  13.  
  14.       m_ogl.OnDisplay = (r) =>
  15.       {
  16.         if (!m_init)
  17.         {
  18.           InitOpengl((int)m_ogl.HeightRequest, (int)m_ogl.WidthRequest);
  19.           m_init = true;
  20.         }
  21.  
  22.         GL.ClearColor(System.Drawing.Color.CornflowerBlue);
  23.         GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  24.         GL.Viewport(0, 0, m_vpWidth, m_vpHeight);
  25.  
  26.         float ratio = (float)m_vpWidth / m_vpHeight;
  27.         m_projMatrix = Matrix4.CreateOrthographic(-ratio, ratio, -1, 1);
  28.         m_viewMatrix = Matrix4.LookAt(-Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);
  29.         m_mvpMatrix  = m_projMatrix * m_viewMatrix;
  30.         Vector4 value = Vector4.Transform(new Vector4(0, 0, 0, 1), m_mvpMatrix);
  31.  
  32.         foreach (ShaderProgram shader in m_shaderPrograms)
  33.         {
  34.           GL.UseProgram(shader.ShaderProgramId);
  35.           shader.CallAttributeLocationDataFuncs();
  36.           shader.CallUniformLocationDataFuncs();
  37.           shader.ShaderUseFunc();
  38.           GL.Finish();
  39.         }
  40.       };
  41.  
  42.       StackLayout stackLayout = Content as StackLayout;
  43.       stackLayout.Children.Add(m_ogl);
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement