/// <summary> /// Sets up the individual Direct3D Contstants and objects used for rendering. /// </summary> /// <param name="device"></param> private static unsafe void SetupRenderingConstants(Device device) { // Create our individual devices and fonts if necessary. // (Normally you would do this on initialization, not in the render function but this is just for clarity). if (!_initialized) { // Let's create a line for us to draw later. _sampleLine = new Line(device); _lineVertices = new[] { new RawVector2(100, 300), new RawVector2(150, 200), new RawVector2(250, 200) }; // Create a font for us to draw later (SharpDX D3D9 Font) _sampleFont = new Font(device, 20, 0, FontWeight.Normal, 1, false, FontCharacterSet.Ansi, FontPrecision.Default, FontQuality.ClearType, FontPitchAndFamily.Modern, "Times New Roman"); // Set position of text and colour of line + text. _semiTransparentGray = new RawColorBGRA(255, 255, 255, 128); _textRectangle = new RawRectangle(100, 100, 9999, 9999); // Create triangle vertices. // Fun fact: W acts as the blend factor here. _triangleVertices = new[] { new Vertex() { Color = Color.Red, Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) }, new Vertex() { Color = Color.Blue, Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) }, new Vertex() { Color = Color.Green, Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) } }; // Set vertex render mode for our vertices. _vertexRenderingModes = new[] { VertexRenderingMode.RedToGreen, VertexRenderingMode.BlueToRed, VertexRenderingMode.GreenToBlue }; // Create vertex buffer. _localVertexBuffer = new VertexBuffer(device, sizeof(Vertex) * 3, 0, VertexFormat.None, Pool.Default); _localVertexBuffer.Lock(0, 0, LockFlags.None).WriteRange(_triangleVertices); _localVertexBuffer.Unlock(); // Specifies the Vertex Format var vertexElems = new[] { new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0), new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), VertexElement.VertexDeclarationEnd }; _vertexDeclaration = new VertexDeclaration(device, vertexElems); // Wrap SetPixelShader for us to call later (otherwise our shape may not show) // This uses Reloaded's Virtual Function Table Utility Class if (_directX9Overlay != null) { VirtualFunctionTable.TableEntry vTableEntry = _directX9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.SetPixelShader]; _setPixelShaderFunction = vTableEntry.CreateWrapperFunction <SetPixelShaderDelegate>(); } // Never run this again. _initialized = true; } }