public Renderer(GLControl context, WindowsFormsHost host) { m_control = context; context.Width = (int)host.Width; context.Height = (int)host.Height; RenderableObjs = new List<IRenderable>(); Cam = new Camera(); SetUpViewport(); m_intervalTimer = new System.Windows.Forms.Timer(); m_intervalTimer.Interval = 16; // 60 FPS roughly m_intervalTimer.Enabled = true; m_intervalTimer.Tick += (args, o) => { Vector2 mousePosGlobal = new Vector2(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y); Vector2 glControlPosGlobal = new Vector2((float)host.PointToScreen(new Point(0, 0)).X, (float)host.PointToScreen(new Point(0, 0)).Y); Input.Internal_SetMousePos(new Vector2(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y)); Input.Internal_UpdateInputState(); if (host.IsFocused) { Cam.Update(); } Draw(); }; m_control.MouseUp += m_control_MouseUp; m_control.MouseDown += m_control_MouseDown; m_control.MouseMove += m_control_MouseMove; host.KeyUp += host_KeyUp; host.KeyDown += host_KeyDown; host.LayoutUpdated += host_LayoutUpdated; ProjectionMatrix = Matrix4.Identity; }
/// <summary> /// Creates a camera and sets up shaders for use in the viewport. /// </summary> private void SetUpViewport() { _programID = GL.CreateProgram(); Cam = new Camera(); int vertShaderId, fragShaderId; LoadShader("vs.glsl", ShaderType.VertexShader, _programID, out vertShaderId); LoadShader("fs.glsl", ShaderType.FragmentShader, _programID, out fragShaderId); GL.DeleteShader(vertShaderId); GL.DeleteShader(fragShaderId); GL.BindAttribLocation(_programID, (int)ShaderAttributeIds.Position, "vertexPos"); GL.LinkProgram(_programID); _uniformMVP = GL.GetUniformLocation(_programID, "modelview"); _uniformColor = GL.GetUniformLocation(_programID, "col"); if (GL.GetError() != ErrorCode.NoError) Console.WriteLine(GL.GetProgramInfoLog(_programID)); }