示例#1
0
        public static void TestRenderFrames()
        {
            RenderBuffer <float>     buffer     = new RenderBuffer <float>(CRenderSettings.RenderWidth, CRenderSettings.RenderHeight, 3);
            CharRenderBuffer <float> charBuffer = new CharRenderBuffer <float>(buffer);

            float framerate             = 25f;
            float time                  = 10f;
            int   totalFrame            = (int)(framerate * time);
            int   frameInterval         = (int)(1000f / framerate);
            GenericVector <float> white = new GenericVector <float>(3)
            {
                1, 1, 1
            };
            GenericVector <float> black = new GenericVector <float>(3)
            {
                0, 0, 0
            };
            int lastU = 0;
            int step  = totalFrame / buffer.Width + 1;

            for (int i = 0; i < totalFrame; i++)
            {
                if (i / step > lastU)
                {
                    buffer.WritePixel(lastU, 0, black);
                    buffer.WritePixel(++lastU, 0, white);
                }
                Thread.Sleep(frameInterval);
                CRenderer.Render(charBuffer);
            }
        }
示例#2
0
        public static void Render(CharRenderBuffer <float> buffer)
        {
            _lastRenderTick    = _currentRenderTick;
            _currentRenderTick = System.DateTime.Now.Ticks;

            LastFrameElapsed = (_currentRenderTick - _lastRenderTick) * 1e-7f;
            CurrentSecond    = (_currentRenderTick - _beginRenderTick) * 1e-7f;

            char[] outputChars = buffer.GetRenderBuffer();
            _renderingBufferWidth = buffer.Width;

            int cursorPos = _renderingBufferWidth - 1;

            if (CRenderSettings.IsCountFrames)
            {
                cursorPos = DisplayString(outputChars, DisplayNumber(outputChars, cursorPos, _frameCounts) - 1, "Frame:") - 1;
            }
            if (CRenderSettings.IsShowFPS)
            {
                cursorPos = DisplayString(outputChars, DisplayNumber(outputChars, cursorPos, (int)(1f / LastFrameElapsed)) - 1, "FPS:") - 1;
            }

            _frameCounts++;
            ConsoleExt.Output(outputChars);
        }
示例#3
0
        public static unsafe void TestRasterize()
        {
            Rasterizer.StartRasterize(CRenderSettings.ResolutionF);
            RenderBuffer <float>     tex0    = new RenderBuffer <float>(CRenderSettings.Resolution, 3);
            CharRenderBuffer <float> texChar = new CharRenderBuffer <float>(tex0);
            Vector2 *points = stackalloc Vector2[4];

            for (float i = 0; i < JMath.PI_TWO; i += .02f)
            {
                Vector2 dir      = new Vector2(MathF.Cos(i) * .3f, MathF.Sin(i) * .3f);
                Vector2 orthoDir = new Vector2(-dir.Y, dir.X);
                points[0] = new Vector2(.5f, .5f) + dir;
                points[1] = new Vector2(.5f, .5f) - dir;
                points[2] = new Vector2(.5f, .5f) + orthoDir;
                points[3] = new Vector2(.5f, .5f) - orthoDir;
                LinePrimitive *line = stackalloc LinePrimitive[1] {
                    new LinePrimitive(points, null, 0)
                };
                Rasterizer.Rasterize <Line, LinePrimitive>(line);
                tex0.WritePixel(Rasterizer.ContriveResult(), new GenericVector <float>(3)
                {
                    1f, 1f, 1f
                });
                CRenderer.Render(texChar);
                tex0.Clear();
                Thread.Sleep(16);
            }

            Rasterizer.EndRasterize();
        }
示例#4
0
 /// <param name="camera">It orients the origin</param>
 private static void EstablishTestScene(out Pipeline pipeline, out CharRenderBuffer <float> charBuffer, out ICamera camera)
 {
     pipeline   = new Pipeline();
     charBuffer = new CharRenderBuffer <float>(pipeline.RenderTarget);
     camera     = new Camera_Orthographic(width: 3.5f, height: 3.5f, near: -2.5f, far: 2.5f,
                                          new Transform(
                                              pos: Vector3.Zero,
                                              rotation: new Vector3(0, JMath.PI_HALF * .35f, -JMath.PI_HALF * 1.5f)));
 }
示例#5
0
 public static void Render(CharRenderBuffer <float> buffer)
 {
     char[] outputChars = buffer.GetRenderBuffer();
     if (CRenderSettings.IsCountFrames)
     {
         _frameCounts++;
         for (int i = buffer.Width - 1, j = _frameCounts; j > 0; i--, j /= 10)
         {
             outputChars[i] = (char)(0x30 + (j % 10));
         }
     }
     ConsoleExt.Output(outputChars);
 }
示例#6
0
        public static void Render(CharRenderBuffer <float> buffer)
        {
            char[] outputChars = buffer.GetRenderBuffer();
            int    cursorPos   = buffer.Width - 1;

            if (CRenderSettings.IsCountFrames)
            {
                cursorPos = DisplayString(outputChars, DisplayNumber(outputChars, cursorPos, _frameCounts) - 1, "Frame:") - 1;
            }
            if (CRenderSettings.IsShowFPS)
            {
                cursorPos = DisplayString(outputChars, DisplayNumber(outputChars, cursorPos, JMath.RoundToInt(1000f / DeltaMS)) - 1, "FPS:") - 1;
            }

            _frameCounts++;
            ConsoleExtension.Output(outputChars);
        }
示例#7
0
        public static void TestDrawBuffer()
        {
            RenderBuffer <float>     buffer     = new RenderBuffer <float>(CRenderSettings.RenderWidth, CRenderSettings.RenderHeight, channelCount: 3);
            CharRenderBuffer <float> charBuffer = new CharRenderBuffer <float>(buffer);

            GenericVector <float> white = new GenericVector <float>(3)
            {
                1, 1, 1
            };

            buffer.WritePixel(0, 0, white);
            buffer.WritePixel(8, 2, white);
            buffer.WritePixel(16, 4, white);
            buffer.WritePixel(24, 6, white);
            buffer.WritePixel(32, 8, white);
            CRenderer.Render(charBuffer);
        }
示例#8
0
        public static void TestDrawColor()
        {
            RenderBuffer <float>     buffer     = new RenderBuffer <float>(CRenderSettings.RenderWidth, CRenderSettings.RenderHeight, channelCount: 3);
            CharRenderBuffer <float> charBuffer = new CharRenderBuffer <float>(buffer);

            GenericVector <float> color = new GenericVector <float>(3)
            {
                0, 0, 0
            };

            for (int i = 0; i < buffer.Width; i++)
            {
                for (int j = 0; j < buffer.Height; j++)
                {
                    buffer.WritePixel(i, j, color);
                }
                color.Write((float)i / buffer.Width);
            }
            CRenderer.Render(charBuffer);
        }
示例#9
0
        public static void TestDrawLine()
        {
            PipelineBase <AppdataBasic, V2FBasic> pipeline = new PipelineBase <AppdataBasic, V2FBasic>();
            CharRenderBuffer <float> charBuffer            = new CharRenderBuffer <float>(pipeline.RenderTarget);

            RenderEntity entity = new RenderEntity(new Transform(Vector3.Zero),
                                                   new Model(
                                                       vertices: new Vector3[] { new Vector3(-.5f, .5f, -.5f), new Vector3(-.5f, -.5f, -.5f), new Vector3(.5f, -.5f, -.5f), new Vector3(.5f, .5f, -.5f),
                                                                                 new Vector3(-.5f, .5f, .5f), new Vector3(-.5f, -.5f, .5f), new Vector3(.5f, -.5f, .5f), new Vector3(.5f, .5f, .5f) },
                                                       primitives: new IPrimitive[] { new LinePrimitive(0, 1), new LinePrimitive(1, 2), new LinePrimitive(2, 3), new LinePrimitive(3, 0),
                                                                                      new LinePrimitive(4, 5), new LinePrimitive(5, 6), new LinePrimitive(6, 7), new LinePrimitive(7, 4),
                                                                                      new LinePrimitive(0, 4), new LinePrimitive(1, 5), new LinePrimitive(2, 6), new LinePrimitive(3, 7) },
                                                       uvs: null,
                                                       normals: null
                                                       ), null);
            ICamera camera = new Camera_Orthographic(width: 3.5f, height: 3.5f, near: -2.5f, far: 2.5f,
                                                     new Transform(
                                                         pos: Vector3.Zero,
                                                         rotation: new Vector3(0, JMath.PI_HALF * .35f, -JMath.PI_HALF * 1.5f)));

            RenderEntity[] entitiesApply = new RenderEntity[] { entity };

            float framerate     = 25f;
            float time          = 10f;
            int   totalFrame    = (int)(framerate * time);
            float angleStep     = JMath.PI_TWO / totalFrame;
            int   frameInterval = (int)(1000f / framerate);

            for (int i = 0; i < totalFrame; i++)
            {
                pipeline.Draw(entitiesApply, camera);
                CRenderer.Render(charBuffer);
                entity.Transform.Rotation.X += angleStep;
                entity.Transform.Rotation.Z += angleStep;
                Thread.Sleep(frameInterval);
            }
        }
示例#10
0
        private static void DrawRotatingObject(IPipeline pipeline, RenderEntity[] entitiesApply, ICamera camera, CharRenderBuffer <float> charBuffer)
        {
            float framerate     = 25f;
            float time          = 10f;
            int   totalFrame    = (int)(framerate * time);
            float angleStep     = JMath.PI_TWO / totalFrame;
            int   frameInterval = (int)(1000f / framerate);

            for (int i = 0; i < totalFrame; i++)
            {
                pipeline.Draw(entitiesApply, camera);
                CRenderer.Render(charBuffer);
                entitiesApply[0].Transform.Rotation.X += angleStep;
                entitiesApply[0].Transform.Rotation.Z += angleStep;
                Thread.Sleep(frameInterval);
            }
        }
示例#11
0
 public static void DrawOneFrame <TPipeline, TCamera>(TPipeline pipeline, RenderEntity[] entitiesApply, TCamera camera, CharRenderBuffer <float> charBuffer) where TPipeline : IPipeline where TCamera : ICamera
 {
     CRenderer.UpdateRenderInfo();
     pipeline.Draw(entitiesApply, camera);
     CRenderer.Render(charBuffer);
 }
示例#12
0
        public static void DrawRotatingObject <TPipeline, TCamera>(TPipeline pipeline, RenderEntity[] entitiesApply, TCamera camera, CharRenderBuffer <float> charBuffer) where TPipeline : IPipeline where TCamera : ICamera
        {
            float framerate     = 60f;
            float time          = 6f;
            int   totalFrame    = (int)(framerate * time);
            float angleStep     = JMath.PI_TWO / totalFrame;
            int   frameInterval = (int)(1000f / framerate);
            int   elapsed;

            JTimer timer = new JTimer();

            timer.Start();
            for (int i = 0; i < totalFrame; i++)
            {
                CRenderer.UpdateRenderInfo();
                pipeline.Draw(entitiesApply, camera);
                entitiesApply[0].Transform.Rotation.X += angleStep;
                entitiesApply[0].Transform.Rotation.Z += angleStep;

                elapsed = (int)timer.DeltaMS;
                if (elapsed < frameInterval)
                {
                    Thread.Sleep(frameInterval - elapsed);
                }
                CRenderer.Render(charBuffer);
            }
            timer.Stop();
        }