//Filter FBO2 and Write result in FBO1[0] private void ProcessFilterPass(ITexture2D sourceTexture, IRenderSurface fbo) { int halfKernelX = kernelSizeX / 2; int halfKernelY = kernelSizeY / 2; fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderSATFilter.Activate(); int SATSampler = GL.GetUniformLocation(shaderSATFilter.ProgramID, "sourceSampler"); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); //sourceTexture.Activate(); shaderSATFilter.Uniform("width", sourceTexture.Width); shaderSATFilter.Uniform("height", sourceTexture.Height); shaderSATFilter.Uniform("halfKernelX", halfKernelX); shaderSATFilter.Uniform("halfKernelY", halfKernelY); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //sourceTexture.Deactivate(); shaderSATFilter.Deactivate(); fbo.Deactivate(); }
private void SumValues(ITexture2D sourceTexture, IShaderProgram program, IRenderSurface fbo) { int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "sourceSampler"); fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); program.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); program.Uniform("blockLengthX", blockSizeX); program.Uniform("blockLengthY", blockSizeX); program.Uniform("amountBlockX", amountBlocksX); program.Uniform("amountBlockY", amountBlocksX); //satFilter.GetFilterTexture().Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //satFilter.GetFilterTexture().Deactivate(); program.Deactivate(); fbo.Deactivate(); }
static void InitializeGradient(IRenderSurface display) { if (PreviousClientSize != display.Stride + display.Height) { PreviousClientSize = display.Stride + display.Height; PixelBuffer = new int[display.Height * display.Width]; Color[] gradient = ColorUtility.CreateGradient(display.Width, ColorSet); int[] initialLine = new int[display.Stride]; for (int index = 0; index < display.Stride; index++) { Color current = gradient[index]; initialLine[index] = BitConverter.ToInt32 ( new byte[] { current.B, current.G, current.R, 0 }, 0 ); } unsafe { for (int line = 0; line < display.Height; line++) { fixed(int *ptr = &PixelBuffer[display.Stride * line]) { Marshal.Copy(initialLine, 0, ( IntPtr )ptr, initialLine.Length); } } } } }
/// <summary> /// Configures the present parameters /// </summary> /// <param name="renderSurface">Surface where the scene is going to be renedered to</param> private void SetupPresentParameters(IRenderSurface renderSurface) { System.Windows.Forms.Control view = (System.Windows.Forms.Control)renderSurface; // reset Present Parameters for the new swap presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Copy; // setup the backbuffer presentParams.DeviceWindow = view; // setup back buffer //presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format; presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format; presentParams.BackBufferHeight = view.ClientSize.Height; presentParams.BackBufferWidth = view.ClientSize.Width; // make sure graphics card can support 16-bit depth stenciling if (Manager.CheckDepthStencilMatch(0, DeviceType.Hardware, presentParams.BackBufferFormat, presentParams.BackBufferFormat, DepthFormat.D16)) { // enabling automatic depth stencilling presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; } else { throw new Exception("Graphics card does not support 16 bit depth stenciling"); } }
static void DrawFire(IRenderSurface display) { int height = display.Height >= FireBufferHeight ? FireBufferHeight : FireBufferHeight - display.Height, start = display.Height - height, position = 0; byte *dest; int offset; Color pixel; for (int row = start; row < (display.Height - CoalHeight); row++) { offset = display.YValues[row + CoalHeight]; dest = ( byte * )(display.Surface) + (offset << 2); for (int x = 0; x < display.Stride; x++) { pixel = Palette[FireBuffer[display.YValues[position] + x]]; dest[0] = pixel.B; dest[1] = pixel.G; dest[2] = pixel.R; dest += 4; } position++; } }
static void Flame(IRenderSurface display) { byte p1, p2, p3, p4, p5, p6, p7; int u, d, l, r; for (int x = 0; x < FireBufferWidth; x++) { l = x == 0 ? 0 : x - 1; r = x == FireBufferWidth - 1 ? FireBufferWidth - 1 : x + 1; for (int y = 0; y < FireBufferHeight - 1; y++) { u = y == 0 ? 0 : y - 1; d = y == FireBufferHeight - 1 ? FireBufferHeight : y + 1; p1 = FireBuffer[display.YValues[u] + l]; p2 = FireBuffer[display.YValues[y] + l]; p3 = FireBuffer[display.YValues[d] + l]; p4 = FireBuffer[display.YValues[d] + x]; p5 = FireBuffer[display.YValues[u] + r]; p6 = FireBuffer[display.YValues[y] + r]; p7 = FireBuffer[display.YValues[d] + r]; FireBuffer[display.YValues[u] + x] = ( byte )((p1 + p2 + +p3 + p4 + p5 + p6 + p7) / 7); } } }
public void UpdateResolution(int width, int height) { ((FBO)PassOneSurface)?.Dispose(); PassOneSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat)); ((FBO)PassTwoSurface)?.Dispose(); PassTwoSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat)); }
public void EditorThread_CreateScene(IRenderSurface renderSurface, EInputClass cameraInputClass) { IsCreated = true; OnEngineThread(() => { Input.RegisterListener(EngineThread_OnInputEvent, cameraInputClass); // Create a new renderer scene with our viewport SSceneViewInfo viewInfo = new SSceneViewInfo(); viewInfo.Fov = FieldOfView; viewInfo.ScreenFar = ScreenFar; viewInfo.ScreenNear = ScreenNear; viewInfo.FitProjectionToScene = true; viewInfo.ViewMatrix = Matrix.Invert(m_cameraTransform.WorldMatrix); viewInfo.ViewLocation = m_cameraTransform.Position; viewInfo.CreateBoundingFrustum(); m_renderScene = CRenderer.Instance.CreateRenderScene(renderSurface); if (m_renderScene != null) { m_renderScene.OnDoFrame += EngineThread_Update; m_renderScene.UpdateViewInfo(in viewInfo); m_ambientLight = new CAmbientLight(); m_ambientLight.LightColor = Vector4.One * 0.2f; m_directionalLight = new CDirectionalLight(); m_directionalLight.LightDirection = new Vector3(0.3f, -0.7f, 0.0f); m_directionalLight.LightColor = Vector4.One * 0.8f; m_renderScene.LightManager.AddLight(m_ambientLight); m_renderScene.LightManager.AddLight(m_directionalLight); } }); }
/// <summary> /// Initialize the device (hardware support, Z-buffer, blending, etc) /// </summary> /// <param name="renderSurface">Surface where the scene is going to be renedered to</param> private void InitializeDevice(IRenderSurface renderSurface) { // setup the present parameters before the device is created SetupPresentParameters(renderSurface); // get the capabilities of the graphics card Caps gfxCapabilities = Manager.GetDeviceCaps(0, DeviceType.Hardware); // if the device supports hardware Vertex processing use it if (gfxCapabilities.DeviceCaps.SupportsHardwareTransformAndLight) { device = new Device(0, DeviceType.Hardware, (System.Windows.Forms.Control)renderSurface, CreateFlags.HardwareVertexProcessing | CreateFlags.MultiThreaded, presentParams); } else { device = new Device(0, DeviceType.Hardware, (System.Windows.Forms.Control)renderSurface, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams); } // enabled z-buffering so objects don't have to be drawn in correct order (back-to-front) device.RenderState.ZBufferEnable = true; // allow transparent textures device.RenderState.SourceBlend = Blend.SourceAlpha; device.RenderState.DestinationBlend = Blend.InvSourceAlpha; }
public void InitScene(Device device, DeviceContext deviceContext, IRenderSurface renderSurface) { SceneRenderer.Init(renderSurface, device); m_cameraBuffer.Init(device); m_cubeCameraBuffer.Init(device); LightManager.Init(device, deviceContext); }
public void UpdateResolution(int width, int height) { _ssao.UpdateResolution(width, height); _blur.UpdateResolution(width, height); ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBO(Texture2dGL.Create(width, height)); }
public void LockMouseCursor() { IRenderSurface renderSurface = m_hostControl.GetRenderSurface(); Rectangle clipRect = new Rectangle(renderSurface.GetLeft(), renderSurface.GetTop(), renderSurface.GetWidth(), renderSurface.GetHeight()); System.Windows.Forms.Cursor.Clip = clipRect; Input.SetCursorVisibility(false); }
public void UpdateResolution(int width, int height) { ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height)); _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true)); _outputSurface.Attach(Texture2dGL.Create(width, height, 1, true)); _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true)); }
public void UpdateResolution(int width, int height) { ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBO(Texture2dGL.Create(width, height, _fboTexComponentCount, _fboTexFloat)); _postProcessShader.Activate(); _postProcessShader.Uniform("iResolution", new Vector2(width, height)); _postProcessShader.Deactivate(); }
public void UpdateResolution(int width, int height) { ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBO(Texture2dGL.Create(width, height)); _sphereCutProgram.Activate(); _sphereCutProgram.Uniform("iResolution", new Vector2(width, height)); _sphereCutProgram.Deactivate(); }
private void OnViewPortLoaded(object sender, RoutedEventArgs e) { if (m_bWorldLoaded && !PreviewScene.IsCreated) { IRenderSurface renderSurface = m_viewPortControl.GetRenderSurface(); PreviewScene.EditorThread_CreateScene(renderSurface, EInputClass.AssetPreview); Input.SetInputClassActive(EInputClass.AssetPreview, IsActive); } }
public static IObject3D Pick(int X, int Y, Midget.Cameras.MidgetCamera camera, IRenderSurface renderSurface) { Vector3 pickRayDirection = new Vector3(); Vector3 pickRayOrigin = new Vector3(); camera.UnProjectCoordinates(X,Y, renderSurface.ClientWidth, renderSurface.ClientHeight, ref pickRayOrigin, ref pickRayDirection); // // compute the vector of the pick ray in screen space // Vector3 v = new Vector3(); // v.X = ( ( ( 2.0f * X ) / renderSurface.ClientWidth ) - 1 ) / camera.ProjectionMatrix.M11; // v.Y = -( ( ( 2.0f * Y ) / renderSurface.ClientHeight ) - 1 ) / camera.ProjectionMatrix.M22; // v.Z = 1.0f; // // // Get the inverse view matrix // Matrix m = Matrix.Invert(camera.ViewMatrix); // // // Transform the screen space pick ray into 3D space // pickRayDirection.X = v.X*m.M11 + v.Y*m.M21 + v.Z*m.M31; // pickRayDirection.Y = v.X*m.M12 + v.Y*m.M22 + v.Z*m.M32; // pickRayDirection.Z = v.X*m.M13 + v.Y*m.M23 + v.Z*m.M33; // // pickRayDirection.Normalize(); // // pickRayOrigin.X = m.M41; // pickRayOrigin.Y = m.M42; // pickRayOrigin.Z = m.M43; // // // calc origin as intersection with near frustum // // pickRayOrigin += pickRayDirection * 1.0f; // int zDistance = -1; // IObject3D closestObj = null; // foreach (IObject3D obj in DeviceManager.Instance.ObjectList) // { // // // transform world space to object space // Vector3 pickRayOriginTemp = new Vector3(pickRayOrigin.X, pickRayOrigin.Y, pickRayOrigin.Z); // Vector3 pickRayDirectionTemp = new Vector3(pickRayDirection.X,pickRayDirection.Y,pickRayDirection.Z); // // // convert ray from 3d space to model space // pickRayOriginTemp.TransformCoordinate(Matrix.Invert(obj.WorldSpace)); //Matrix.Invert(Matrix.Identity)); // pickRayDirectionTemp.TransformNormal(Matrix.Invert(obj.WorldSpace)); //inverse); // // // if (obj.Intersect(pickRayOriginTemp, pickRayDirectionTemp) > zDistance) // { // closestObj = obj; // } // } return SceneManager.Instance.Scene.Intersect(pickRayOrigin, pickRayDirection, camera.WorldMatrix); //return closestObj; }
public void Init(IRenderSurface surface, Device device) { Width = surface.GetWidth(); Height = surface.GetHeight(); Top = surface.GetTop(); Left = surface.GetLeft(); m_renderSurface = surface; InitializeDeviceResources(device); }
static void Render(IRenderSurface display) { EnsureCorrectBufferSize(display); GenerateCoalBed(display); Flame(display); DrawFire(display); }
public void UpdateResolution(int width, int height) { ((FBO)_depthSurface)?.Dispose(); _depthSurface = new FBOwithDepth(Texture2dGL.Create(width * 4, height * 4, 1, true)); ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height, 1)); _depthShader.Uniform("iResolution", new Vector2(width, height)); _shadowShader.Uniform("iResolution", new Vector2(width, height)); }
public Visual(IRenderState renderState, IContentLoader contentLoader) { fbo = new FBO(Texture2dGL.Create(70, 70)); fbo.Texture.Filter = TextureFilterMode.Nearest; copyToFrameBuffer = new PostProcessing(contentLoader.LoadPixelShader("copy.frag")); renderState.Set(BlendStates.AlphaBlend); renderState.Set(new LineSmoothing(true)); renderState.Set(new LineWidth(5f)); GL.Enable(EnableCap.PointSmooth); }
static void EnsureCorrectBufferSize(IRenderSurface display) { int clientSize = display.Stride + display.Height; if (PreviousClientSize != clientSize) { CreateBuffer(display.Stride, display.Height); PreviousClientSize = clientSize; } }
public void Init(IRenderSurface surface) { m_owningThread = Thread.CurrentThread; m_d3dRenderer.Init(); // Create the default scene CreateRenderScene(surface); ActiveScene = m_renderScenes[0]; Init(); }
private void SetUpBlocksAndTextures(int amountBlocksX, int amountBlocksY, int resX, int resY) { this.amountBlocksX = amountBlocksX; this.amountBlocksY = amountBlocksY; this.blockSizeX = resX / amountBlocksX; this.blockSizeY = resY / amountBlocksY; FBO1 = new FBO(Texture2dGL.Create(resX, resY, 4, true)); FBO1.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat; FBO2 = new FBO(Texture2dGL.Create(resX, resY, 4, true)); FBO2.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat; }
public void Begin(Environment environment, IRenderSurface renderSurface, bool showTitleText) { _environment = environment; _surface = renderSurface; _environment.CurrentRoomId = _environment.GetPlayer().RoomId ?? ID_DEFAULT; if (showTitleText) { this.StartNarrating(_environment.Title); } }
public override void PostWorldLoad() { base.PostWorldLoad(); m_bWorldLoaded = true; if (m_viewPortControl.IsLoaded && !PreviewScene.IsCreated) { IRenderSurface renderSurface = m_viewPortControl.GetRenderSurface(); PreviewScene.EditorThread_CreateScene(renderSurface, EInputClass.AssetPreview); Input.SetInputClassActive(EInputClass.AssetPreview, IsActive); } }
public Water(IContentLoader contentLoader) { waterMapShader = contentLoader.Load <IShaderProgram>("WaterMap.*"); mapFBO = new FBO(Texture2dGL.Create(256, 256, 4, true)); mapFBO.Attach(Texture2dGL.Create(256, 256, 4, true)); mapFBO.Textures[0].WrapFunction = TextureWrapFunction.MirroredRepeat; waveLayers = GetWaveLayer(); List <Wave> waveList = GetWaves(); numberOfWaves = waveList.Count; waveBuffer.Set(waveList.ToArray(), BufferUsageHint.StaticCopy); }
/// <summary> /// Renders the current scene in a single viewport /// </summary> /// <param name="renderSurface">The view that is to be rendered too</param> public void RenderSingleView(IRenderSurface renderSurface) { // make sure the device is initialised and that the view is initialised if ((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed)) { // get the backbuffer of the surface that is to be rendered to Surface surface = renderSurface.SwapChain.GetBackBuffer(0, BackBufferType.Mono); // set the device so it renders to the back buffer device.SetRenderTarget(0, surface); surface.ReleaseGraphics(); device.DepthStencilSurface = renderSurface.DepthStencil; // get the camera that current render surface is using MidgetCameras.MidgetCamera camera = renderSurface.Camera; // adjust the device camera device.Transform.View = camera.ViewMatrix; device.Transform.Projection = camera.ProjectionMatrix; //device.PresentationParameters.DeviceWindow. // clear the backbuffer device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0); // setup the render quality for the viewport SetupDrawMode(renderSurface.DrawMode); // start drawing the scene device.BeginScene(); // render the scene //device.Transform.World = Matrix.Identity; SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex); // display viewport description text Microsoft.DirectX.Direct3D.Font viewportD3DFont = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold)); viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30), DrawTextFormat.Left, Color.Black); // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30), DrawTextFormat.Left, Color.White); viewportD3DFont.Dispose(); // end the scene and display it device.EndScene(); renderSurface.SwapChain.Present(); } }
public void UpdateResolution(int width, int height) { ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBO(Texture2dGL.Create(width, height)); for (int i = 0; i < _bloom.Length; i++) { _bloom[i].UpdateResolution(width, height); } _environmentMapProgram.Activate(); _environmentMapProgram.Uniform("iResolution", new Vector2(width, height)); _environmentMapProgram.Deactivate(); }
public static void FillArea(this IRenderSurface surface, BitsyGame.Color c, int x, int y, int width, int height) { if (surface == null) { return; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { surface.SetPixel(c, x + i, y + j); } } }
public void FillTile(BitsyGame.Color color, int x, int y, IRenderSurface context) { if (context == null) { return; } for (int i = 0; i < BitsyGame.TILESIZE * BitsyGame.PIXEL_SCALE; i++) { for (int j = 0; j < BitsyGame.TILESIZE * BitsyGame.PIXEL_SCALE; j++) { context.SetPixel(color, x + i, y + j); } } }
public override void Render(IRenderSurface surface) { if (!Visible) return; // Render shadow and car itself surface.RenderBitmap(ShadowBitmap, Location.X + 1, Location.Y + 1); base.Render(surface); // Calculate and render smoke int smokeScale = 0; if (smokeRotation > 5) smokeScale = 1; else if (smokeRotation < -5) smokeScale = 0; surface.BackGraphics.TranslateTransform(Location.X, Location.Y + 16); surface.BackGraphics.RotateTransform((float)smokeRotation); surface.BackGraphics.DrawImage(SmokeBitmap, new Rectangle(0, 0, SmokeBitmap.Width + smokeScale, SmokeBitmap.Height + smokeScale)); surface.BackGraphics.ResetTransform(); }
public void SetSwapChain(IRenderSurface renderTarget) { if(renderTarget.SwapChain != null) { renderTarget.SwapChain.Dispose(); renderTarget.SwapChain = null; SetupPresentParameters(renderTarget); // create new swap chain renderTarget.SwapChain = new SwapChain(device,presentParams); } if(renderTarget.DepthStencil != null) { renderTarget.DepthStencil.Dispose(); renderTarget.DepthStencil = null; renderTarget.DepthStencil = device.CreateDepthStencilSurface(renderTarget.ClientWidth,renderTarget.ClientHeight,DepthFormat.D16, MultiSampleType.None,0,true); } }
/// <summary> /// Initialize the device (hardware support, Z-buffer, blending, etc) /// </summary> /// <param name="renderSurface">Surface where the scene is going to be renedered to</param> private void InitializeDevice(IRenderSurface renderSurface) { // setup the present parameters before the device is created SetupPresentParameters(renderSurface); // get the capabilities of the graphics card Caps gfxCapabilities = Manager.GetDeviceCaps(0,DeviceType.Hardware); // if the device supports hardware Vertex processing use it if(gfxCapabilities.DeviceCaps.SupportsHardwareTransformAndLight) device = new Device(0,DeviceType.Hardware,(System.Windows.Forms.Control)renderSurface, CreateFlags.HardwareVertexProcessing | CreateFlags.MultiThreaded, presentParams); else device = new Device(0,DeviceType.Hardware,(System.Windows.Forms.Control)renderSurface, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams); // enabled z-buffering so objects don't have to be drawn in correct order (back-to-front) device.RenderState.ZBufferEnable = true; // allow transparent textures device.RenderState.SourceBlend = Blend.SourceAlpha; device.RenderState.DestinationBlend = Blend.InvSourceAlpha; }
/// <summary> /// Configures the present parameters /// </summary> /// <param name="renderSurface">Surface where the scene is going to be renedered to</param> private void SetupPresentParameters(IRenderSurface renderSurface) { System.Windows.Forms.Control view = (System.Windows.Forms.Control)renderSurface; // reset Present Parameters for the new swap presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Copy; // setup the backbuffer presentParams.DeviceWindow = view; // setup back buffer //presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format; presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format; presentParams.BackBufferHeight = view.ClientSize.Height; presentParams.BackBufferWidth = view.ClientSize.Width; // make sure graphics card can support 16-bit depth stenciling if(Manager.CheckDepthStencilMatch(0, DeviceType.Hardware, presentParams.BackBufferFormat, presentParams.BackBufferFormat, DepthFormat.D16)) { // enabling automatic depth stencilling presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; } else throw new Exception("Graphics card does not support 16 bit depth stenciling"); }
public void SetRenderSurface(IRenderSurface surface) { this.surface = surface; surface.SetNumbersBitmap(ResourceManager.GetBitmapResource("Numbers"), 5); }
/// <summary> /// Renders the current scene in a single viewport /// </summary> /// <param name="renderSurface">The view that is to be rendered too</param> public void RenderSingleView(IRenderSurface renderSurface) { // make sure the device is initialised and that the view is initialised if((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed)) { // get the backbuffer of the surface that is to be rendered to Surface surface = renderSurface.SwapChain.GetBackBuffer(0,BackBufferType.Mono); // set the device so it renders to the back buffer device.SetRenderTarget(0,surface); surface.ReleaseGraphics(); device.DepthStencilSurface = renderSurface.DepthStencil; // get the camera that current render surface is using MidgetCameras.MidgetCamera camera = renderSurface.Camera; // adjust the device camera device.Transform.View = camera.ViewMatrix; device.Transform.Projection = camera.ProjectionMatrix; //device.PresentationParameters.DeviceWindow. // clear the backbuffer device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0); // setup the render quality for the viewport SetupDrawMode(renderSurface.DrawMode); // start drawing the scene device.BeginScene(); // render the scene //device.Transform.World = Matrix.Identity; SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex); // display viewport description text Microsoft.DirectX.Direct3D.Font viewportD3DFont = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold)); viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30), DrawTextFormat.Left, Color.Black); // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30), DrawTextFormat.Left, Color.White); viewportD3DFont.Dispose(); // end the scene and display it device.EndScene(); renderSurface.SwapChain.Present(); } }
public virtual void Render(IRenderSurface surface) { if (Visible) surface.RenderBitmap(Bitmap, Location); }
/// <summary> /// Add a viewport (based on its display surface), and set up its swap chain /// </summary> /// <param name="renderTarget">the display surface to be drawn to</param> /// <returns>true if successful, false if an error occurs</returns> public bool AddViewport(IRenderSurface renderTarget) { try { // check for device existence, create if needed if (device == null) { InitializeDevice(renderTarget); // get Device SwapChain renderTarget.SwapChain = device.GetSwapChain(0); // add renderSurface to the list renderSurfaceList.Add(renderTarget); } // this is an additional view else { SetupPresentParameters(renderTarget); // create new swap chain renderTarget.SwapChain = new SwapChain(device,presentParams); // add renderSurface to the list renderSurfaceList.Add(renderTarget); } } catch // an error occurred somewhere { return false; } renderTarget.DepthStencil = device.CreateDepthStencilSurface(renderTarget.ClientWidth,renderTarget.ClientHeight,DepthFormat.D16, MultiSampleType.None,0,true); device.RenderState.ZBufferEnable = true; return true; }
public void SetRenderSurface(IRenderSurface surface) { this.surface = surface; }