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); } }
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(); }
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(); }
public bool Render( Configuration config, TextWriter writer, AST <Node> ast, out List <Flag> flags) { Cnst settingValue; bool useLineDir = false; if (config.TryGetSetting(CollectionName, InstanceName, LineDirectivesSetting, out settingValue)) { if (settingValue.CnstKind == CnstKind.String) { if (settingValue.GetStringValue() == "TRUE") { useLineDir = true; } else if (settingValue.GetStringValue() != "FALSE") { flags = new List <Flag>(); var flag = new Flag( SeverityKind.Error, settingValue, Constants.BadSetting.ToString( SyntaxKindSetting, settingValue.GetStringValue(), string.Format("Expected setting {0} to be TRUE or FALSE", LineDirectivesSetting)), Constants.BadSetting.Code); flags.Add(flag); return(false); } } else { flags = new List <Flag>(); var flag = new Flag( SeverityKind.Error, settingValue, Constants.BadSetting.ToString( SyntaxKindSetting, settingValue.GetNumericValue(), string.Format("Expected setting {0} to be TRUE or FALSE", LineDirectivesSetting)), Constants.BadSetting.Code); flags.Add(flag); return(false); } } var cwriter = new CTextWriter(writer, useLineDir); return(CRenderer.Render(ast, cwriter, out flags)); }
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); } }
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); }
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); }
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); } }
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); }