Guest User

Untitled

a guest
Jun 2nd, 2017
7
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void InitOpengl(int width, int height)
  2.     {
  3.       m_vpWidth  = width;
  4.       m_vpHeight = height;
  5.       float ratio = (float)width / height;
  6.      
  7.       m_projMatrix = Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, 1f, 100f);
  8.       m_viewMatrix = Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);
  9.       m_mvpMatrix  = m_projMatrix * m_viewMatrix;// Matrix4.Mult(m_viewMatrix, m_projMatrix);
  10.  
  11.       m_shaderPrograms = new ArrayList();
  12.  
  13.       string vertexLineShaderSrc =
  14.         @"attribute vec3 vertex_position;
  15.        uniform mat4 mvp;
  16.        void main()
  17.        {
  18.          gl_Position = mvp * vec4(vertex_position, 1.0);
  19.        }";
  20.       string fragLineShaderSrc =
  21.         @"void main()
  22.        {
  23.          gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
  24.        }";
  25.  
  26.       ShaderProgram lineShader = ShaderProgram.CreateShaderProgram(vertexLineShaderSrc, fragLineShaderSrc, () => { GL.DrawArrays(BeginMode.Lines, 0, verts.Length); });
  27.       if (lineShader != null)
  28.       {
  29.         lineShader.AddAttributeLocationData(new AttributeLocationData(lineShader.ShaderProgramId,
  30.           "vertex_position",
  31.           () =>
  32.           {
  33.             int vertexPosAttrib = GL.GetAttribLocation(lineShader.ShaderProgramId, "vertex_position");
  34.             GL.EnableVertexAttribArray(vertexPosAttrib);
  35.             GL.VertexAttribPointer(vertexPosAttrib, 3, VertexAttribPointerType.Float, false, 0, verts);
  36.           }));
  37.         lineShader.AddUniformLocationData(new UniformLocationData(lineShader.ShaderProgramId,
  38.           "mvp",
  39.           () =>
  40.           {
  41.             int mvpUniform = GL.GetUniformLocation(lineShader.ShaderProgramId, "mvp");
  42.             GL.UniformMatrix4(mvpUniform, false, ref m_mvpMatrix);
  43.           }));
  44.         m_shaderPrograms.Add(lineShader);
  45.       }
  46.     }
RAW Paste Data