private static void NativeWindow_Render(object sender, NativeWindowEventArgs e) { NativeWindow nativeWindow = (NativeWindow)sender; Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height); Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.UseProgram(_CubeEdgeProgram); // Compute MVP PerspectiveProjectionMatrix proj = new PerspectiveProjectionMatrix(60.0f, (float)nativeWindow.Width / nativeWindow.Height, 0.5f, 1e6f); ModelMatrix view = new ModelMatrix(); ModelMatrix model = new ModelMatrix(); model.RotateY(_Angle); model.RotateZ(_Angle); view.LookAtTarget(Vertex3f.One * 7.0f, Vertex3f.Zero, Vertex3f.UnitY); Gl.BindVertexArray(_CubeVao); Gl.UniformMatrix4(_CubeEdgeProgram_Location_uMVP, false, (proj * view * model).ToArray()); foreach (float scale4d in new float[] { 64.0f, 32.0f, 16.0f, 8.0f, 4.0f, 2.0f, 1.0f, 0.5f, 0.25f, 0.125f }) { Gl.Uniform1(_CubeEdgeProgram_Location_uScale4D, scale4d * _Zooom); Gl.Uniform4(_CubeEdgeProgram_Location_uColor, 0.0f, 0.3f, 1.0f, Math.Min(1.0f, scale4d * _Zooom / 2.0f)); Gl.DrawElements(PrimitiveType.Lines, _CubeEdges.Length, DrawElementsType.UnsignedShort, IntPtr.Zero); } _Angle += 360.0f / (25.0f * 5); _Zooom -= 0.025f; if (_Zooom < 0.5f) { _Zooom = 1.0f; } // Save PNG frame if (_FrameNo < 125) { using (Bitmap bitmap = new Bitmap((int)nativeWindow.Width, (int)nativeWindow.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) { BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Gl.ReadPixels(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height, OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bitmapData.Scan0); bitmap.Save(String.Format("Frame_{0:D3}.png", _FrameNo++)); } } }