private void SetManagedDevice(IntPtr unmanagedDevice) { // Start by freeing everything FreeResources(); // Create a managed Device from the unmanaged pointer // The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release // Direct3D seem to be happier with that according to the DirectX log Marshal.AddRef(unmanagedDevice); this.unmanagedDevice = unmanagedDevice; device = Device.FromPointer(unmanagedDevice); //text sprite = new Sprite(device); _gdiMouseFixtionFont = new System.Drawing.Font("Tahoma", 30); _d3dMouseFixtionFont = new Direct3D.Font(device, _gdiMouseFixtionFont); _gdiGazeFixtionFont = new System.Drawing.Font("Tahoma", 30); _d3dGazeFixtionFont = new Direct3D.Font(device, _gdiGazeFixtionFont); //mouse _d3dMouseTrackLine = new Direct3D.Line(device); _d3dMouseTrackLine.Width = _mouseTrackLineWidth; _d3dMouseCursorCircleLine = new Direct3D.Line(device); _d3dMouseCursorCircleLine.Width = _mouseCursorCircleLineWidth; _d3dMouseFixationLine = new Direct3D.Line(device); _d3dMouseFixationLine.Width = _mouseFixationLineWidth; _d3dMouseScanpathLine = new Direct3D.Line(device); _d3dMouseScanpathLine.Width = _mouseScanpathLineWidth; //gaze _d3dGazeTrackLine = new Direct3D.Line(device); _d3dGazeTrackLine.Width = _gazeTrackLineWidth; _d3dGazeCursorCircleLine = new Direct3D.Line(device); _d3dGazeCursorCircleLine.Width = _gazeCursorCircleLineWidth; _d3dGazeFixationLine = new Direct3D.Line(device); _d3dGazeFixationLine.Width = _gazeFixationLineWidth; _d3dGazeScanpathLine = new Direct3D.Line(device); _d3dGazeScanpathLine.Width = _gazeScanpathLineWidth; // Load a png file to the teature _mouseCursorTex = Texture.FromFile(device, @"..\..\..\Resource\Picture\cursor1.png"); SurfaceDescription spiderDesc = _mouseCursorTex.GetLevelDescription(0); _mouseCursorSize = new Size(spiderDesc.Width, spiderDesc.Height); _gazeCursorTex = Texture.FromFile(device, @"..\..\..\Resource\Picture\eyecursor.png"); spiderDesc = _gazeCursorTex.GetLevelDescription(0); _gazeCursorSize = new Size(spiderDesc.Width, spiderDesc.Height); }
public Render(D3D.Device device, int shiftX = 0, int shiftY = 0) { this.device = device; this.shiftX = shiftX; this.shiftY = shiftY; line = new D3D.Line(device); fonts = new D3D.Font[3]; fonts[0] = new D3D.Font(device, new Font("Dotum", 8, FontStyle.Regular)); fonts[1] = new D3D.Font(device, new Font("Calibri", 8, FontStyle.Regular)); fonts[2] = new D3D.Font(device, new Font("Tahoma", 9, FontStyle.Regular)); }
// DrawControl2D internal void DrawControl2D(string Title, int SizeX, int SizeY, int PosX, int PosY, System.Drawing.Color TitleTextColor, System.Drawing.Color TitleColor, System.Drawing.Color BackgroundColor, System.Drawing.Color BorderColor) { int num = 18; int num2 = PosY + 1; if (SizeY >= 18) { // Draw Header SlimDX.Direct3D9.Line line = new SlimDX.Direct3D9.Line(D3D.Device); List <SlimDX.Vector2> list = new List <SlimDX.Vector2>(); for (int i = 0; i < num; i++) { list.Add(new SlimDX.Vector2((float)PosX, (float)num2)); list.Add(new SlimDX.Vector2((float)(PosX + SizeX), (float)num2)); num2++; } line.Draw(list.ToArray(), TitleColor); // Draw Title DrawString2D(Title, PosX + 4, PosY + 1, TitleTextColor); // Draw Background List <SlimDX.Vector2> list2 = new List <SlimDX.Vector2>(); for (int j = num; j < SizeY; j++) { list2.Add(new SlimDX.Vector2((float)PosX, (float)num2)); list2.Add(new SlimDX.Vector2((float)(PosX + SizeX), (float)num2)); num2++; } line.Draw(list2.ToArray(), BackgroundColor); // Draw top border SlimDX.Vector2[] vertexList = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)PosY), new SlimDX.Vector2((float)(PosX + SizeX), (float)PosY) }; line.Draw(vertexList, BorderColor); // Draw bottom border SlimDX.Vector2[] vectorArray2 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)(PosY + SizeY)), new SlimDX.Vector2((float)((PosX + SizeX) + 1), (float)(PosY + SizeY)) }; line.Draw(vectorArray2, BorderColor); // Draw right border SlimDX.Vector2[] vectorArray3 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)(PosX + SizeX), (float)PosY), new SlimDX.Vector2((float)(PosX + SizeX), (float)(PosY + SizeY)) }; line.Draw(vectorArray3, BorderColor); // Draw left border SlimDX.Vector2[] vectorArray4 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)PosY), new SlimDX.Vector2((float)PosX, (float)(PosY + SizeY)) }; line.Draw(vectorArray4, BorderColor); // Dispose line.Dispose(); } }
void ReloadGraphicResources() { resourceManager.EmptyTexture = new Texture(device, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); SlimDX.DataRectangle dr = resourceManager.EmptyTexture.LockRectangle(0, LockFlags.Discard); dr.Data.Write <uint>(0x00000000); resourceManager.EmptyTexture.UnlockRectangle(0); emptyTexture = new Texture(device, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); dr = emptyTexture.LockRectangle(0, LockFlags.Discard); dr.Data.Write <uint>(0xffffffff); emptyTexture.UnlockRectangle(0); spriteRenderer = new SlimDX.Direct3D9.Sprite(device); lineRenderer = new Line(device); loadingOverlay.Load(device); blendOverlay.Load(device); errorOverlay.Load(device); renderToSurface = new RenderToSurface(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, Format.X8R8G8B8); renderToTexture = new Texture(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); deviceReadyForRender = true; }
private void Main_Load(object sender, EventArgs e) { HotKey = new Hotkey(); HotKey.enable(this.Handle, Hotkey.Modifiers.None, Keys.Insert); // Delete //Insert HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F1); HotKey.enable(this.Handle, Hotkey.Modifiers.None, Keys.N); HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F3); HotKey.enable(this.Handle, Hotkey.Modifiers.Alt, Keys.F5); //HotKey.enable(base.Handle, Hotkey.Modifiers.None, Keys.CapsLock); //HotKey.enable(base.Handle, Hotkey.Modifiers.None, Keys.Q); Native.SetWindowLong(this.Handle, -20, (IntPtr)((Native.GetWindowLong(this.Handle, -20) ^ 0x80000) ^ 0x20)); Native.SetLayeredWindowAttributes(this.Handle, 0, 0xff, 2); PresentParameters parameters = new SlimDX.Direct3D9.PresentParameters(); parameters.Windowed = true; parameters.SwapEffect = SwapEffect.Discard; parameters.BackBufferFormat = Format.A8R8G8B8; parameters.BackBufferHeight = this.Height; parameters.BackBufferWidth = this.Width; parameters.PresentationInterval = PresentInterval.One; DXDevice = new SlimDX.Direct3D9.Device(new Direct3D(), 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters[] { parameters }); if (System.IO.File.Exists("map_large.png")) DXTextrureMapLarge = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "map_large.png"); if (System.IO.File.Exists("map.png")) DXTextrureMap = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "map.png"); if (System.IO.File.Exists("LagerMap.jpg")) DXTextureGameMap = SlimDX.Direct3D9.Texture.FromFile(DXDevice, "LagerMap.jpg"); CircleVertices = new VertexBuffer(DXDevice, (circleComplexity + 2) * TexVertex.SizeBytes, Usage.WriteOnly, VertexFormat.None, Pool.Managed); DXSprite = new SlimDX.Direct3D9.Sprite(DXDevice); DXLine = new SlimDX.Direct3D9.Line(DXDevice); DXFont = new SlimDX.Direct3D9.Font(DXDevice, new System.Drawing.Font("NewRoman", 9f)); //NewRoman DXFontB = new SlimDX.Direct3D9.Font(DXDevice, new System.Drawing.Font("Tahoma", 12f)); //NewRoman if (this.GameMemory.Attach("H1Z1 PlayClient (Live)") == false) { Application.Exit(); return; } Thread dxThread = new Thread(new ThreadStart(DoProcess)); dxThread.IsBackground = true; dxThread.Start(); //Thread aimThread = new Thread(new ThreadStart(DoAiming)); //aimThread.IsBackground = true; //aimThread.Start(); }
public bool DirectX_Init(string background_image) { PresentParameters presentParms = new PresentParameters(); presentParms.Windowed = true; presentParms.SwapEffect = SwapEffect.Discard; presentParms.Multisample = MultisampleType.None; presentParms.EnableAutoDepthStencil = true; presentParms.AutoDepthStencilFormat = Format.D16; presentParms.PresentFlags = PresentFlags.DiscardDepthStencil; presentParms.PresentationInterval = PresentInterval.Default; presentParms.BackBufferFormat = Format.X8R8G8B8; presentParms.BackBufferHeight = gauge_target.Height; presentParms.BackBufferWidth = gauge_target.Width; presentParms.Windowed = true; presentParms.BackBufferCount = 1; switch (directx_render_type) { case RenderType.HARDWARE: try { DX9device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception ex) { MessageBox.Show("Problem u inicijalizaciji DirectX-a greska 1\n" + ex.ToString()); } break; case RenderType.SOFTWARE: { try { DX9device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception exe) { MessageBox.Show("Problem u inicijalizaciji DirectX-a greska 2\n" + exe.ToString()); return false; } } break; } 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 }; var vertexDecl = new VertexDeclaration(DX9device, vertexElems); DX9device.VertexDeclaration = vertexDecl; if (File.Exists(background_image)) { BackgroundTexture = Texture.FromFile(DX9device, background_image, this.Width, this.Height, 1, Usage.None, Format.Unknown, Pool.Default, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); } texture_size.Width = gauge_target.Width; texture_size.Height = gauge_target.Height; sprite = new Sprite(DX9device); if (render_event == null) render_event = new AutoResetEvent(true); line = new Line(DX9device); line.Antialias = true; line.Width = 3; line.GLLines = true; DX9device.SetRenderState(RenderState.AntialiasedLineEnable, true); return true; }
private void FreeResources() { #region Text Dispose if (_d3dMouseFixtionFont != null) { _d3dMouseFixtionFont.Dispose(); _d3dMouseFixtionFont = null; } if (_d3dGazeFixtionFont != null) { _d3dGazeFixtionFont.Dispose(); _d3dGazeFixtionFont = null; } if (_gdiMouseFixtionFont != null) { _gdiMouseFixtionFont.Dispose(); _gdiMouseFixtionFont = null; } if (_gdiGazeFixtionFont != null) { _gdiGazeFixtionFont.Dispose(); _gdiGazeFixtionFont = null; } #endregion #region Texture Dispose if (_mouseCursorTex != null) { _mouseCursorTex.Dispose(); _mouseCursorTex = null; } if (_gazeCursorTex != null) { _gazeCursorTex.Dispose(); _gazeCursorTex = null; } #endregion #region Line Dispose if (_d3dMouseTrackLine != null) { _d3dMouseTrackLine.Dispose(); _d3dMouseTrackLine = null; } if (_d3dMouseCursorCircleLine != null) { _d3dMouseCursorCircleLine.Dispose(); _d3dMouseCursorCircleLine = null; } if (_d3dMouseFixationLine != null) { _d3dMouseFixationLine.Dispose(); _d3dMouseFixationLine = null; } if (_d3dMouseScanpathLine != null) { _d3dMouseScanpathLine.Dispose(); _d3dMouseScanpathLine = null; } if (_d3dGazeTrackLine != null) { _d3dGazeTrackLine.Dispose(); _d3dGazeTrackLine = null; } if (_d3dGazeCursorCircleLine != null) { _d3dGazeCursorCircleLine.Dispose(); _d3dGazeCursorCircleLine = null; } if (_d3dGazeFixationLine != null) { _d3dGazeFixationLine.Dispose(); _d3dGazeFixationLine = null; } if (_d3dGazeScanpathLine != null) { _d3dGazeScanpathLine.Dispose(); _d3dGazeScanpathLine = null; } #endregion if (sprite != null) { sprite.Dispose(); sprite = null; } if (device != null) { device.Dispose(); device = null; } }
public VectorShape(Device device) { this.d3dLine = new D3D.Line(device.RawDevice); }
public static bool DirectXInit() { if (!booting && !DX_reinit) { try { try { DX_reinit = true; switch (current_display_mode) { case DisplayMode.PANADAPTER: case DisplayMode.PANAFALL: case DisplayMode.PANAFALL_INV: case DisplayMode.PANASCOPE: panadapter_target = (Control)console.picDisplay; panadapter_W = panadapter_target.Width; panadapter_H = panadapter_target.Height; WaterfallTarget = (Control)console.picWaterfall; waterfallX_data = new float[waterfall_W]; panadapterX_scope_data = new float[waterfall_W * 2]; break; case DisplayMode.WATERFALL: WaterfallTarget = (Control)console.picWaterfall; panadapterX_scope_data = new float[waterfall_W * 2]; break; default: panadapter_H = panadapter_target.Height; panadapter_W = panadapter_target.Width; panadapterX_scope_data = new float[panadapter_W * 2]; panadapter_target = (Control)console.picDisplay; break; } panadapterX_data = new float[panadapter_W]; refresh_panadapter_grid = true; histogram_data = new int[panadapter_W]; histogram_verts = new HistogramData[panadapter_W * 4]; scope_min = new float[waterfall_target.Width]; scope_max = new float[waterfall_target.Width]; histogram_history = new int[panadapter_W]; for (int i = 0; i < panadapter_W; i++) { histogram_data[i] = Int32.MaxValue; histogram_history[i] = 0; histogram_verts[i].X = i; histogram_verts[i].Y = panadapter_H; histogram_verts[i].color = Color.Green; } average_buffer = new float[BUFFER_SIZE]; // initialize averaging buffer array average_buffer[0] = CLEAR_FLAG; // set the clear flag average_waterfall_buffer = new float[BUFFER_SIZE]; // initialize averaging buffer array average_waterfall_buffer[0] = CLEAR_FLAG; // set the clear flag peak_buffer = new float[BUFFER_SIZE]; peak_buffer[0] = CLEAR_FLAG; new_display_data = new float[BUFFER_SIZE]; new_scope_data = new float[BUFFER_SIZE]; new_waterfall_data = new float[BUFFER_SIZE]; current_display_data = new float[BUFFER_SIZE]; current_scope_data = new float[BUFFER_SIZE]; current_waterfall_data = new float[BUFFER_SIZE]; waterfall_display_data = new float[BUFFER_SIZE]; for (int i = 0; i < BUFFER_SIZE; i++) { new_display_data[i] = -200.0f; new_scope_data[i] = -200.0f; new_waterfall_data[i] = -200.0f; current_display_data[i] = -200.0f; current_scope_data[i] = -200.0f; current_waterfall_data[i] = -200.0f; waterfall_display_data[i] = -200.0f; } presentParms = new PresentParameters(); presentParms.Windowed = true; presentParms.SwapEffect = SwapEffect.Discard; presentParms.Multisample = MultisampleType.None; presentParms.EnableAutoDepthStencil = true; presentParms.AutoDepthStencilFormat = Format.D24X8; presentParms.PresentFlags = PresentFlags.DiscardDepthStencil; presentParms.PresentationInterval = PresentInterval.Default; presentParms.BackBufferFormat = Format.X8R8G8B8; presentParms.BackBufferHeight = panadapter_target.Height; presentParms.BackBufferWidth = panadapter_target.Width; presentParms.Windowed = true; presentParms.BackBufferCount = 1; switch (directx_render_type) { case RenderType.HARDWARE: try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, panadapter_target.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); waterfall_dx_device = new Device(new Direct3D(), 0, DeviceType.Hardware, waterfall_target.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception ex) { if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX hardware init error!" + ex.ToString()); } break; case RenderType.SOFTWARE: try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, panadapter_target.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); waterfall_dx_device = new Device(new Direct3D(), 0, DeviceType.Hardware, waterfall_target.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception exe) { if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX software init error!" + exe.ToString()); return false; } break; } 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 }; var vertexDecl = new VertexDeclaration(device, vertexElems); device.VertexDeclaration = vertexDecl; var vertexDecl1 = new VertexDeclaration(waterfall_dx_device, vertexElems); waterfall_dx_device.VertexDeclaration = vertexDecl1; waterfall_bmp = new System.Drawing.Bitmap(waterfall_target.Width, waterfall_target.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); BitmapData bitmapData = waterfall_bmp.LockBits( new Rectangle(0, 0, waterfall_bmp.Width, waterfall_bmp.Height), ImageLockMode.ReadWrite, waterfall_bmp.PixelFormat); waterfall_bmp_size = bitmapData.Stride * waterfall_bmp.Height; waterfall_bmp_stride = bitmapData.Stride; waterfall_memory = new byte[waterfall_bmp_size]; waterfall_bmp.UnlockBits(bitmapData); waterfall_rect = new Rectangle(0, 0, waterfall_target.Width, waterfall_target.Height); //backbuf = waterfall_dx_device.GetBackBuffer(0, 0); panadapter_font = new SlimDX.Direct3D9.Font(device, pan_font); if (background_image != null && File.Exists(background_image)) { PanadapterTexture = Texture.FromFile(device, background_image, panadapter_target.Width, panadapter_target.Height, 1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); Panadapter_texture_size.Width = panadapter_target.Width; Panadapter_texture_size.Height = panadapter_target.Height; Panadapter_Sprite = new Sprite(device); WaterfallTexture = Texture.FromFile(waterfall_dx_device, background_image, waterfall_target.Width, waterfall_target.Height, 1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); Waterfall_texture_size.Width = waterfall_target.Width; Waterfall_texture_size.Height = waterfall_target.Height; WaterfallBackgroundTexture = Texture.FromFile(waterfall_dx_device, background_image, waterfall_target.Width, waterfall_target.Height, 1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); Waterfall_Sprite = new Sprite(waterfall_dx_device); } else { Panadapter_Sprite = null; WaterfallTexture = new Texture(waterfall_dx_device, waterfall_target.Width, waterfall_target.Height, 0, Usage.None, Format.X8R8G8B8, Pool.Managed); WaterfallBackgroundTexture = new Texture(waterfall_dx_device, waterfall_target.Width, waterfall_target.Height, 0, Usage.None, Format.X8R8G8B8, Pool.Managed); Waterfall_texture_size.Width = waterfall_target.Width; Waterfall_texture_size.Height = waterfall_target.Height; Waterfall_Sprite = new Sprite(waterfall_dx_device); } if (directx_render_type == RenderType.HARDWARE) { Waterfall_vb = new VertexBuffer(waterfall_dx_device, panadapterX_data.Length * 2 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); Waterfall_verts = new Vertex[waterfall_W * 2]; Panadapter_vb = new VertexBuffer(device, panadapterX_data.Length * 2 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); PanLine_vb_fill = new VertexBuffer(device, panadapter_W * 2 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); Panadapter_verts = new Vertex[panadapter_W * 2]; Panadapter_verts_fill = new Vertex[panadapter_W * 2]; HistogramLine_verts = new Vertex[panadapter_W * 6]; Histogram_vb = new VertexBuffer(device, panadapter_W * 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); } else if (directx_render_type == RenderType.SOFTWARE) { Waterfall_vb = new VertexBuffer(waterfall_dx_device, panadapterX_data.Length * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default); Waterfall_verts = new Vertex[waterfall_W]; Panadapter_vb = new VertexBuffer(device, panadapterX_data.Length * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default); PanLine_vb_fill = new VertexBuffer(device, panadapter_W * 2 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default); Panadapter_verts = new Vertex[panadapter_W]; Panadapter_verts_fill = new Vertex[panadapter_W * 2]; HistogramLine_verts = new Vertex[panadapter_W * 6]; Histogram_vb = new VertexBuffer(device, panadapter_W * 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default); } panadapter_verts = new Vector2[panadapter_W]; panadapter_line = new Line(device); panadapter_line.Antialias = smooth_line; panadapter_line.Width = display_line_width; panadapter_line.GLLines = true; panadapter_fill_verts = new Vector2[panadapter_W * 2]; panadapter_fill_line = new Line(device); panadapter_fill_line.Antialias = smooth_line; panadapter_fill_line.Width = 1; panadapter_fill_line.GLLines = true; high_swr_font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Arial", 14.0f, FontStyle.Bold)); DX_reinit = false; return true; } catch (Direct3D9Exception ex) { //MessageBox.Show("DirectX init general fault!\n" + ex.ToString()); DX_reinit = false; if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX init general fault!\n" + ex.ToString()); return false; } } catch (Exception ex) { Debug.Write(ex.ToString()); DX_reinit = false; return false; } } return true; }
public static void DirectXRelease() { try { if (!booting && !DX_reinit) { DX_reinit = true; //backbuf = null; waterfallX_data = null; panadapterX_data = null; scope_min = null; scope_max = null; new_display_data = null; new_scope_data = null; new_waterfall_data = null; current_display_data = null; current_scope_data = null; current_waterfall_data = null; waterfall_display_data = null; histogram_data = null; histogram_history = null; average_buffer = null; average_waterfall_buffer = null; peak_buffer = null; if (waterfall_bmp != null) waterfall_bmp.Dispose(); waterfall_bmp = null; /*if (Panadapter_Sprite != null) { Panadapter_Sprite.OnLostDevice(); Panadapter_Sprite.Dispose(); } Panadapter_Sprite = null; if (Waterfall_Sprite != null) { Waterfall_Sprite.Dispose(); } Waterfall_Sprite = null; if (PanadapterTexture != null) { PanadapterTexture.Dispose(); PanadapterTexture = null; } if (WaterfallTexture != null) { WaterfallTexture.Dispose(); WaterfallTexture = null; }*/ if (VerLine_vb != null) { VerLine_vb.Dispose(); VerLine_vb = null; } if (VerLines_vb != null) { VerLines_vb.Dispose(); VerLines_vb = null; } if (HorLine_vb != null) { HorLine_vb.Dispose(); HorLine_vb = null; } if (HorLines_vb != null) { HorLines_vb.Dispose(); HorLines_vb = null; } if (Panadapter_vb != null) { Panadapter_vb.Dispose(); Panadapter_vb.Dispose(); } /*if (ScopeLine_vb != null) { ScopeLine_vb.Dispose(); ScopeLine_vb.Dispose(); }*/ if (PanLine_vb_fill != null) { PanLine_vb_fill.Dispose(); PanLine_vb_fill.Dispose(); } if (vertical_label != null) vertical_label = null; if (horizontal_label != null) horizontal_label = null; /*if (Phase_vb != null) { Phase_vb.Dispose(); Phase_vb.Dispose(); }*/ if (device != null) { device.Dispose(); device = null; } if (waterfall_dx_device != null) { waterfall_dx_device.Dispose(); waterfall_dx_device = null; } if(high_swr_font != null) high_swr_font.Dispose(); panadapter_fill_verts = null; panadapter_line = null; panadapter_fill_verts = null; panadapter_verts = null; DX_reinit = false; } } catch (Exception ex) { Debug.Write("DX release error!" + ex.ToString()); if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX release fault!\n" + ex.ToString()); DX_reinit = false; } }
public bool DirectX_Init(string background_image) { if (!booting && !DX_reinit) { try { DX_reinit = true; PresentParameters presentParms = new PresentParameters(); presentParms.Windowed = true; presentParms.SwapEffect = SwapEffect.Discard; presentParms.Multisample = MultisampleType.None; presentParms.EnableAutoDepthStencil = true; presentParms.AutoDepthStencilFormat = Format.D24X8; presentParms.PresentFlags = PresentFlags.DiscardDepthStencil; presentParms.PresentationInterval = PresentInterval.Default; presentParms.BackBufferFormat = Format.X8R8G8B8; presentParms.BackBufferHeight = gauge_target.Height; presentParms.BackBufferWidth = gauge_target.Width; presentParms.Windowed = true; presentParms.BackBufferCount = 1; switch (directx_render_type) { case RenderType.HARDWARE: { try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception ex) { if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX hardware init error(AGauge)!\n" + ex.ToString()); } } } break; case RenderType.SOFTWARE: { try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception exe) { if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX software init error(AGauge)!\n" + exe.ToString()); } return(false); } } break; } 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 }; var vertexDecl = new VertexDeclaration(device, vertexElems); device.VertexDeclaration = vertexDecl; if (background_image != null && File.Exists(background_image)) { BackgroundTexture = Texture.FromFile(device, background_image, gauge_target.Width, gauge_target.Height, 1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); } texture_size.Width = gauge_target.Width; texture_size.Height = gauge_target.Height; sprite = new Sprite(device); verts1 = new Vector2[2]; line = new Line(device); line.Antialias = true; line.Width = 3; line.GLLines = true; device.SetRenderState(RenderState.AntialiasedLineEnable, true); DX_reinit = false; return(true); } catch (Exception ex) { Debug.Write(ex.ToString()); DX_reinit = false; if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "Init AGauge error!\n" + ex.ToString()); } return(false); } } return(true); }
public bool DirectX_Init(string background_image) { if (!booting && !DX_reinit) { try { DX_reinit = true; PresentParameters presentParms = new PresentParameters(); presentParms.Windowed = true; presentParms.SwapEffect = SwapEffect.Discard; presentParms.Multisample = MultisampleType.None; presentParms.EnableAutoDepthStencil = true; presentParms.AutoDepthStencilFormat = Format.D24X8; presentParms.PresentFlags = PresentFlags.DiscardDepthStencil; presentParms.PresentationInterval = PresentInterval.Default; presentParms.BackBufferFormat = Format.X8R8G8B8; presentParms.BackBufferHeight = gauge_target.Height; presentParms.BackBufferWidth = gauge_target.Width; presentParms.Windowed = true; presentParms.BackBufferCount = 1; switch (directx_render_type) { case RenderType.HARDWARE: { try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception ex) { if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX hardware init error(AGauge)!\n" + ex.ToString()); } } break; case RenderType.SOFTWARE: { try { device = new Device(new Direct3D(), 0, DeviceType.Hardware, gauge_target.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms); } catch (Direct3D9Exception exe) { if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "DirectX software init error(AGauge)!\n" + exe.ToString()); return false; } } break; } 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 }; var vertexDecl = new VertexDeclaration(device, vertexElems); device.VertexDeclaration = vertexDecl; if (background_image != null && File.Exists(background_image)) { BackgroundTexture = Texture.FromFile(device, background_image, gauge_target.Width, gauge_target.Height, 1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0); } texture_size.Width = gauge_target.Width; texture_size.Height = gauge_target.Height; sprite = new Sprite(device); verts1 = new Vector2[2]; line = new Line(device); line.Antialias = true; line.Width = 3; line.GLLines = true; device.SetRenderState(RenderState.AntialiasedLineEnable, true); DX_reinit = false; return true; } catch (Exception ex) { Debug.Write(ex.ToString()); DX_reinit = false; if (debug && !console.ConsoleClosing) console.Invoke(new DebugCallbackFunction(console.DebugCallback), "Init AGauge error!\n" + ex.ToString()); return false; } } return true; }