protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); var sz = new Size((int)Frame.Width, (int)Frame.Height); if (sz.Width != Size.Width) { Size = sz; } MakeCurrent(); // // Initialize drawables // foreach (var d in _drawablesNeedingLoad) { d.LoadContent(); } _drawablesNeedingLoad.Clear(); // // Determine the current sim time // var t = new NSDate().SecondsSinceReferenceDate; var wallNow = DateTime.UtcNow; var time = new SimTime() { Time = wallNow, WallTime = wallNow, TimeElapsed = t - _lastT, WallTimeElapsed = t - _lastT }; _lastT = t; //Console.WriteLine ("FPS {0:0}", 1.0 / time.WallTimeElapsed); GL.Viewport(0, 0, Size.Width, Size.Height); GL.ClearColor(158 / 255.0f, 207 / 255.0f, 237 / 255.0f, 1.0f); GL.Clear((int)(All.DepthBufferBit | All.ColorBufferBit)); // // Set the common OpenGL state // GL.Enable(All.Blend); GL.BlendFunc(All.SrcAlpha, All.OneMinusSrcAlpha); GL.Enable(All.DepthTest); GL.EnableClientState(All.VertexArray); // // Render the background // _background.Render(); // // Setup the 3D camera // Camera.SetViewport(Size.Width, Size.Height); CameraMan.Update(time); Camera.Execute(CameraMan); // // Enable the sun // if (ShowSun) { GL.Enable(All.Lighting); GL.Enable(All.ColorMaterial); GL.Enable(All.Light0); var sp = _sunLoc.ToPositionAboveSeaLevel(150000000); GL.Light(All.Light0, All.Position, new float[] { sp.X, sp.Y, sp.Z, 1 }); } // // Draw all the layers // foreach (var d in _drawables) { d.Draw(Camera, time); } if (ShowSun) { GL.Disable(All.Lighting); GL.Disable(All.ColorMaterial); } SwapBuffers(); frameCount++; }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); var sz = new Size((int)Frame.Width, (int)Frame.Height); if (sz.Width != Size.Width) { Size = sz; } MakeCurrent(); GL.Viewport(0, 0, Size.Width, Size.Height); var t = new NSDate().SecondsSinceReferenceDate; var wallNow = DateTime.UtcNow; var time = new SimTime() { Time = wallNow, WallTime = wallNow, TimeElapsed = t - _lastT, WallTimeElapsed = t - _lastT }; _lastT = t; //Console.WriteLine ("FPS {0:0}", 1.0 / time.WallTimeElapsed); GL.ClearColor(158 / 255.0f, 207 / 255.0f, 237 / 255.0f, 1.0f); GL.Clear((int)(All.DepthBufferBit | All.ColorBufferBit)); // // Set the common OpenGL state // GL.Enable(All.Blend); GL.BlendFunc(All.SrcAlpha, All.OneMinusSrcAlpha); GL.Enable(All.DepthTest); GL.EnableClientState(All.VertexArray); // // Render the background // _background.Render(); // // Setup the 3D camera // Camera.SetViewport(Size.Width, Size.Height); CameraMan.Update(time); Camera.Execute(CameraMan); // // Enable the sun // if (ShowSun) { GL.Enable(All.Lighting); GL.Enable(All.ColorMaterial); GL.Enable(All.Light0); var sp = _sunLoc.ToPositionAboveSeaLevel(150000000); GL.Light(All.Light0, All.Position, new float[] { sp.X, sp.Y, sp.Z, 1 }); } // // Draw all the layers // foreach (var d in _draws) { d.Draw(Camera, time); } if (ShowSun) { GL.Disable(All.Lighting); GL.Disable(All.ColorMaterial); // if (_gesture == WorldView3d.GestureType.Rotating) { // var verts = new Vector3[2]; // var ppp = Location.SunLocation(DateTime.UtcNow.AddHours(-12)); // verts[0] = ppp.ToPositionAboveSeaLevel(0); // verts[1] = ppp.ToPositionAboveSeaLevel(1000); // GL.Color4(0, 1.0f, 0, 1.0f); // GL.VertexPointer(3, All.Float, 0, verts); // GL.DrawArrays(All.Lines, 0, 2); // Console.WriteLine (Camera.LookAt); // Console.WriteLine (ppp); // } } SwapBuffers(); }