public bool Render(D3DX d3dx, Matrix worldMatrix, Matrix viewMatrix, Matrix orthoMatrix) { Matrix matrix; int stride, offset; stride = Utilities.SizeOf <VertexType>(); offset = 0; d3dx.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(sentence_.vertexBuffer, stride, offset)); d3dx.DeviceContext.InputAssembler.SetIndexBuffer(sentence_.indexBuffer, Format.R32_UInt, 0); d3dx.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; matrix = Matrix.Scaling(scale, scale, scale); worldMatrix = Matrix.Multiply(worldMatrix, matrix); //D3DXMatrixRotationYawPitchRoll(&matrix, rotY, rotX, rotZ); //D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &matrix); matrix = Matrix.Translation(position.X, position.Y, position.Z); worldMatrix = Matrix.Multiply(worldMatrix, matrix); return(FontShader_.Render(d3dx, sentence_.indexCount, worldMatrix, viewMatrix, orthoMatrix, Font_.GetTexture(), color)); }
public bool SetPoint(int index, Vector3 pos, D3DX d3dx) { if (index >= VerticesCount) { return(false); } Point_[index].position = pos; return(UpdateBuffer(d3dx)); }
public bool Initialize(D3DX direct, float lenght) { bool result = true; _Line = new VectorLine[3]; //0-X,1-Y,2-Z _Triangle = new Triangle[3]; _Line[0] = new VectorLine(); _Line[1] = new VectorLine(); _Line[2] = new VectorLine(); _Triangle[0] = new Triangle(); _Triangle[1] = new Triangle(); _Triangle[2] = new Triangle(); result &= _Line[0].Initialize(direct.Device); result &= _Line[1].Initialize(direct.Device); result &= _Line[2].Initialize(direct.Device); result &= _Triangle[0].Initialize(direct.Device); result &= _Triangle[1].Initialize(direct.Device); result &= _Triangle[2].Initialize(direct.Device); if (!result) { return(false); } _Line[0].SetPoints(new Vector3[] { new Vector3(0.0f, 0.0f, 0.0f), new Vector3(lenght, 0.0f, 0.0f) }, direct); _Line[0].Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); _Triangle[0].x = lenght; _Triangle[0].SetColor(direct.DeviceContext, new Vector4(1.0f, 0.0f, 0.0f, 1.0f)); _Triangle[0].twoWay = true; _Triangle[0].rotZ = (float)(-Math.PI / 2.0f); _Triangle[0].width = (int)(lenght / 10f); _Triangle[0].height = (int)(lenght / 10f); _Line[1].SetPoints(new Vector3[] { new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, lenght) }, direct); _Line[1].Color = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); _Triangle[1].z = lenght; _Triangle[1].SetColor(direct.DeviceContext, new Vector4(0.0f, 1.0f, 0.0f, 1.0f)); _Triangle[1].twoWay = true; _Triangle[1].rotZ = (float)(Math.PI / 2.0f); _Triangle[1].rotY = (float)(Math.PI / 2.0f); _Triangle[1].width = (int)(lenght / 10f); _Triangle[1].height = (int)(lenght / 10f); _Line[2].SetPoints(new Vector3[] { new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, lenght, 0.0f) }, direct); _Line[2].Color = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); _Triangle[2].y = lenght; _Triangle[2].SetColor(direct.DeviceContext, new Vector4(0.0f, 0.0f, 1.0f, 1.0f)); _Triangle[2].twoWay = true; _Triangle[2].width = (int)(lenght / 10f); _Triangle[2].height = (int)(lenght / 10f); return(true); }
public void Resize(IntPtr hwnd, int screenWidth, int screenHeight) { screenheight_ = screenHeight; screenwidth_ = screenWidth; SaveHeight = screenHeight; SaveWidth = screenWidth; _hwnd = hwnd; _Input.ScreenHeight = screenHeight; _Input.ScreenWidth = screenWidth; _Direct3D?.Shutdown(); _Direct3D = new D3DX(); if (!_Direct3D.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); } _ColorShader?.Shutdown(); _ColorShader = new ColorShader(); if (!_ColorShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); } _MonoShader?.Shutdown(); _MonoShader = new MonocolorShader(); if (!_MonoShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); } graph.terrain.ChangeDevice(_Direct3D); #region Axis graph.AxleX.ChangeDevice(_Direct3D.Device); graph.AxleY.ChangeDevice(_Direct3D.Device); graph.AxleZ.ChangeDevice(_Direct3D.Device); _AxisMini.ChangeDevice(_Direct3D.Device); #endregion #region Text CpuUsage_.ChangeDevice(_Direct3D.Device); FramesPerSecond_.ChangeDevice(_Direct3D.Device); IntersectionDebug_.ChangeDevice(_Direct3D.Device); SensivityZ_.ChangeDevice(_Direct3D.Device); GridDensity_.ChangeDevice(_Direct3D.Device); #endregion _DebugLine.ChangeDevice(_Direct3D.Device); foreach (var button in ButtonList) { button.ChangeDevice(_Direct3D.Device); } }
private bool RenderSceneToFile() { var direct3D = new D3DX(); if (!direct3D.Initialize(SaveWidth, SaveHeight, VSYNC_ENABLED, _hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); return(false); } var colorShader = new ColorShader(); if (!colorShader.Initialize(direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); return(false); } var monocolorShader = new MonocolorShader(); if (!monocolorShader.Initialize(direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); return(false); } var graph = new Graph(in this.graph, direct3D.Device); direct3D.SetBackBufferRenderTarget(); direct3D.BeginScene(BackgroundColour); #region Render _Camera.Render(); var worldMatrix = direct3D.WorldMatrix; var viewMatrix = _Camera._viewMatrix; var projectionMatrix = direct3D.ProjectionMatrix; var rotation = _Camera.Rotation; direct3D.TurnOnAlphaBlending(); if (!graph.Render(direct3D, colorShader, monocolorShader, worldMatrix, viewMatrix, projectionMatrix, rotation)) { return(false); } #endregion SaveToFile(direct3D, direct3D.BackBuffer, SharpDX.WIC.PixelFormat.Format32bppRGB); graph.Dispose(); colorShader.Shutdown(); monocolorShader.Shutdown(); direct3D.Shutdown(); return(true); }
public void Shutdown() { //_TextureShader?.Shutdown(); //_TextureShader = null; //_DebugWindow?.Shutdown(); //_DebugWindow = null; //_RenderTexture?.Shutdown(); //_RenderTexture = null; _Data = null; _Data = null; _DataHeader = null; _DataHeader = null; CpuUsage_?.Shutdown(); CpuUsage_ = null; _AxisMini?.Shutdown(); _AxisMini = null; FontShader_?.Shutdown(); FontShader_ = null; //_Cpu?.Shutdown(); //_Cpu = null; //_Fps = null; _Position = null; _Timer = null; _ColorShader?.Shutdown(); _ColorShader = null; _Camera = null; _Direct3D?.Shutdown(); _Direct3D = null; _Input?.Shutdown(); _Input = null; ShutdownButtons(); return; }
public bool Render(D3DX direct, MonocolorShader shader, Matrix worldMatrix, Matrix baseViewMatrix, Matrix orthoMatrix) { if (!draw) { return(true); } bool result; result = _Rectangle.Render(direct, shader, worldMatrix, baseViewMatrix, orthoMatrix); result &= Label.Render(direct, worldMatrix, baseViewMatrix, orthoMatrix); return(result); }
public Button(Button button, D3DX direct) { textColor = button.textColor; draw = button.draw; position_ = button.position_; _width = button._width; _height = button._height; Label = new Text(button.Label, direct); _Rectangle = new Shapes.Rectangle(button._Rectangle, direct); _Click = button._Click; _App = button._App; _App.Screen(out screenWidth_, out screenHeight_); }
public bool SetPoints(Vector3[] points, D3DX d3dx) { Point_ = null; indices_ = null; if (VerticesCount != points.Length) { isBufferBigEnough = false; VerticesCount = points.Length; } Point_ = new VertexType[VerticesCount]; indices_ = new int[VerticesCount]; for (int i = 0; i < VerticesCount; ++i) { Point_[i].position = points[i]; indices_[i] = i; } return(UpdateBuffer(d3dx)); }
private bool UpdateBuffer(D3DX d3dx) { if (isBufferBigEnough) { d3dx.DeviceContext.MapSubresource(_vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out DataStream mappedResource); mappedResource.WriteRange(Point_); d3dx.DeviceContext.UnmapSubresource(_vertexBuffer, 0); d3dx.DeviceContext.MapSubresource(_indexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource); mappedResource.WriteRange(indices_); d3dx.DeviceContext.UnmapSubresource(_indexBuffer, 0); } else { ShutdownBuffers(); InitializeBuffers(d3dx.Device);//todo: add error handling } return(true); }
public bool Initialize(D3DX direct) { _Rectangle = new TopoCS.Shapes.Rectangle(); if (!_Rectangle.Initialize(direct.Device)) { return(false); } _Rectangle.twoWay = true; Label = new Text(); if (!Label.Initialize(direct)) { return(false); } Label.SetText(direct, " "); Label.color = textColor; _Click = _App.fPTR; return(true); }
public bool Initialize(D3DX d3dx) { Font_ = new Font(); if (!Font_.Initialize(d3dx.Device, @"data\fontdata.txt", @"data\font.png")) { MessageBox.Show("Could not initialize the fontshader.", "Error", MessageBoxButtons.OK); return(false); } FontShader_ = new FontShader(); if (!FontShader_.Initialize(d3dx.Device)) { MessageBox.Show("Could not initialize font font object.", "Error", MessageBoxButtons.OK); return(false); } if (!InitializeSentence(d3dx.Device, _default_length)) { return(false); } UpdateSentence(d3dx, " "); return(true); }
public bool Initialize(IntPtr hwnd, int screenWidth, int screenHeight, string path) { float cameraX, cameraY, cameraZ, rotX, rotY, rotZ; screenheight_ = screenHeight; screenwidth_ = screenWidth; SaveHeight = screenHeight; SaveWidth = screenWidth; _hwnd = hwnd; _Input = new Input(); if (!_Input.Initialize(screenWidth, screenHeight)) { MessageBox.Show("Could not initialize the input object.", "Error", MessageBoxButtons.OK); return(false); } _Direct3D = new D3DX(); if (!_Direct3D.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); return(false); } _ColorShader = new ColorShader(); if (!_ColorShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); return(false); } _MonoShader = new MonocolorShader(); if (!_MonoShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); return(false); } graph = new Graph(); if (!graph.Initialize(_Direct3D, _DataHeader, _Data, path)) { MessageBox.Show("Could not initialize the graph object.", "Error", MessageBoxButtons.OK); return(false); } _AxisMini = new AxisRosette(); if (!_AxisMini.Initialize(_Direct3D, 30.0f)) { MessageBox.Show("Could not initialize the axis object.", "Error", MessageBoxButtons.OK); return(false); } #region Camera _Camera = new Camera { Position = new Vector3(0.0f, 0.0f, -1.0f) }; _Camera.Render(); _baseViewMatrix = _Camera._viewMatrix; cameraX = 0; cameraY = 0; cameraZ = 0; rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; _Camera.Position = new Vector3(cameraX, cameraY, cameraZ); _Camera.Rotation = new Vector3(rotX, rotY, rotZ); _Position = new Position(); _Position.SetPosition(cameraX, cameraY, cameraZ); _Position.SetRotation(rotX, rotY, rotZ); _Position.SetOffSet(graph.terrain.Width / 2.0f, 0, graph.terrain.Height / 2.0f); _Position.SetRadious(graph.terrain.Width / 2.0f); _Position.orbit = true; #endregion _Timer = new Timer(); if (!_Timer.Initialize()) { MessageBox.Show("Could not initialize the timer object.", "Error", MessageBoxButtons.OK); return(false); } //// Create the fps object. //_Fps = new FpsClass; //if (!_Fps) return false; //_Fps.Initialize(); //_Cpu = new CpuClass; //if (!_Cpu) return false; //_Cpu.Initialize(); if (!InitializeText()) { return(false); } _DebugLine = new VectorLine(); if (!_DebugLine.Initialize(_Direct3D.Device)) { return(false); } _DebugLine.Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); if (!InitializeButtons()) { return(false); } //_RenderTexture = new RenderTexture(); //if (!_RenderTexture.Initialize(_Direct3D.Device, screenWidth, screenHeight)) return false; //_DebugWindow = new DebugWindowClass; //if (!_DebugWindow) return false; //result = _DebugWindow.Initialize(_Direct3D.GetDevice(), screenWidth, screenHeight, 100, 100); //if (!result) //{ // MessageBox.Show("Could not initialize the debug window object.", L"Error", MessageBoxButtons.OK); // return false; //} //_TextureShader = new TextureShaderClass; //if (!_TextureShader) return false; //result = _TextureShader.Initialize(_Direct3D.GetDevice(), hwnd); //if (!result) //{ // MessageBox.Show("Could not initialize the texture shader object.", L"Error", MessageBoxButtons.OK); // return false; //} return(true); }
private void SaveToFile(D3DX direct3D, Texture2D texture, Guid format) { var stream = new System.IO.FileStream("Output.png", System.IO.FileMode.Create); var textureTarget = texture; var textureCopy = new Texture2D(direct3D.Device, new Texture2DDescription { Width = (int)textureTarget.Description.Width, Height = (int)textureTarget.Description.Height, MipLevels = 1, ArraySize = 1, Format = textureTarget.Description.Format, Usage = ResourceUsage.Staging, SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, OptionFlags = ResourceOptionFlags.None }); direct3D.DeviceContext.CopyResource(textureTarget, textureCopy); var dataBox = direct3D.DeviceContext.MapSubresource( textureCopy, 0, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out DataStream dataStream); var dataRectangle = new DataRectangle { DataPointer = dataStream.DataPointer, Pitch = dataBox.RowPitch }; var imagingFactory = new ImagingFactory2(); var bitmap = new SharpDX.WIC.Bitmap( imagingFactory, textureCopy.Description.Width, textureCopy.Description.Height, format, dataRectangle); using (var s = stream) { s.Position = 0; using (var bitmapEncoder = new PngBitmapEncoder(imagingFactory, s)) { using (var bitmapFrameEncode = new BitmapFrameEncode(bitmapEncoder)) { bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(bitmap.Size.Width, bitmap.Size.Height); var pixelFormat = SharpDX.WIC.PixelFormat.FormatDontCare; bitmapFrameEncode.SetPixelFormat(ref pixelFormat); bitmapFrameEncode.WriteSource(bitmap); bitmapFrameEncode.Commit(); bitmapEncoder.Commit(); bitmapFrameEncode.Dispose(); bitmapEncoder.Dispose(); } } } direct3D.DeviceContext.UnmapSubresource(textureCopy, 0); textureCopy.Dispose(); bitmap.Dispose(); imagingFactory.Dispose(); dataStream.Dispose(); stream.Dispose(); }
public bool SetPoint(int index, float x, float y, float z, D3DX d3dx) { return(SetPoint(index, new Vector3(x, y, z), d3dx)); }