Esempio n. 1
0
        private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

            if (_AnimationBegin == DateTime.MinValue)
            {
                _AnimationBegin = DateTime.UtcNow;
            }

            PerspectiveProjectionMatrix matrixProjection = new PerspectiveProjectionMatrix();
            Matrix4x4 matrixView;

            // Set projection
            matrixProjection.SetPerspective(60.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, 1000.0f);
            // Set view
            ModelMatrix matrixViewModel = new ModelMatrix();

            matrixViewModel.RotateX(_ViewElevation);
            matrixViewModel.RotateY(_ViewAzimuth);
            matrixViewModel.Translate(0.0f, 0.0f, _ViewDistance);
            matrixView = matrixViewModel.GetInverseMatrix();

            _NewtonProgram.Bind(ctx);
            _NewtonProgram.SetUniform(ctx, "hal_ModelViewProjection", matrixProjection * matrixView);
            _NewtonProgram.SetUniform(ctx, "hal_FrameTimeInterval", (float)(DateTime.UtcNow - _AnimationBegin).TotalSeconds);

            _NewtonVertexArray.Draw(ctx, _NewtonProgram);

            SwapNewtonVertexArrays();

            // Issue another rendering
            SampleGraphicsControl.Invalidate();
        }
Esempio n. 2
0
        private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

#if DEBUG
            _GeometryClipmapObject = new GeometryClipmapObject(6, 7, _BlockUnit);
#else
            _GeometryClipmapObject = new GeometryClipmapObject(9, 11, _BlockUnit);
#endif

            string workingDir = Directory.GetCurrentDirectory();

            _GeometryClipmapObject.SetTerrainElevationFactory(Path.Combine(workingDir, @"..\..\..\Data\Terrain.vrt"), 45.5, 10.5);

            _GeometryClipmapScene = new SceneGraph();
            _GeometryClipmapScene.AddChild(new SceneGraphCameraObject());
            _GeometryClipmapScene.AddChild(_GeometryClipmapObject);
            _GeometryClipmapScene.Create(ctx);

            // Set projection
            _GeometryClipmapScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(
                _ViewFov / 16.0f * 9.0f,
                (float)ClientSize.Width / (float)ClientSize.Height,
                1.0f, _ViewDepth
                );;

            // Clear color
            framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f));
        }
Esempio n. 3
0
 private void GraphicsControl_GraphicsContextDestroying(object sender, GraphicsControlEventArgs e)
 {
     if (_Program != null)
     {
         _Program.Dispose();
     }
     if (_VertexArray != null)
     {
         _VertexArray.Dispose();
     }
 }
Esempio n. 4
0
        private void GraphicsControl_Draw(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext  ctx = e.Context;
            IGraphicsSurface fb  = e.Framebuffer;

            Gl.Viewport(0, 0, (int)fb.Width, (int)fb.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ctx.Bind(_Program);
            _Program.SetUniform(ctx, "hal_ModelViewProjection", new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f));
            _VertexArray.Draw(ctx, _Program);
        }
Esempio n. 5
0
        private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

            // Create Newton program
            _NewtonProgram = ShadersLibrary.Instance.CreateProgram("Newton");
            _NewtonProgram.AddFeedbackVarying("hal_VertexPosition");
            _NewtonProgram.AddFeedbackVarying("hal_VertexSpeed");
            _NewtonProgram.AddFeedbackVarying("hal_VertexAcceleration");
            _NewtonProgram.AddFeedbackVarying("hal_VertexMass");
            _NewtonProgram.Create(ctx);

            // Initialize first vertex array
            NewtonVertex[] newtonArray = new NewtonVertex[VertexCount];
            Random         random      = new Random();

            for (int i = 0; i < newtonArray.Length; i++)
            {
                NewtonVertex newtonVertex = new NewtonVertex();

                newtonVertex.Position     = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
                newtonVertex.Speed        = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
                newtonVertex.Acceleration = new Vertex3f();
                newtonVertex.Mass         = RandomNormalized();

                newtonArray[i] = newtonVertex;
            }

            // Create vertex arrays
            ArrayBufferObjectBase newtonVertexArrayBuffer1, newtonVertexArrayBuffer2;

            _NewtonVertexArray1 = CreateVertexArray(newtonArray, out newtonVertexArrayBuffer1);
            _NewtonVertexArray2 = CreateVertexArray(null, out newtonVertexArrayBuffer2);

            _NewtonVertexArray1.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer2));
            _NewtonVertexArray2.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer1));

            _NewtonVertexArray1.Create(ctx);
            _NewtonVertexArray2.Create(ctx);

            // Starts from initialized buffer
            _NewtonVertexArray = _NewtonVertexArray1;

            // Clear color
            framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f));
        }
Esempio n. 6
0
        private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

            // Update position
            KeyTimer_Tick();

            // Define view
            _GeometryClipmapScene.CurrentView.LocalModel.SetIdentity();
            _GeometryClipmapScene.CurrentView.LocalModel.Translate(_ViewPosition);
            _GeometryClipmapScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _GeometryClipmapScene.CurrentView.LocalModel.RotateX(_ViewElevation);

            // Draw geometry clipmap
            _GeometryClipmapScene.Draw(ctx);

            SampleGraphicsControl.Invalidate();
        }