ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Help with displaying png image with SharpDX

Open MenuGamer opened this issue 6 months ago • 0 comments

For a long while I've now been stuck on rendering images on IMGUI overlay window. In my Overlay constructor I have the creation of Direct3D11 device and the loading of the texture using SharpDX. The TextureLoader is copied from a SharpDX example project.

var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None);
var bitmap = TextureLoader.LoadBitmap(assetsDirectory + "Icons\\warning.png");
var texture = TextureLoader.CreateTexture2DFromBitmap(device, bitmap);
var view = new SharpDX.Direct3D11.ShaderResourceView(device, texture);
test = view.NativePointer;

[!NOTE] I Have also tried to use the bitmap.NativePointer along with texture.NativePointer, but none of them have worked.

I assume the textures are loaded correctly, since the texture.Description contains the exact width and height as the original image.

I create the overlay with ImGUI windows on my Render method as followed.

ImGui.SetNextWindowSize(overlaySize);
ImGui.SetNextWindowPos(overlayOffset);
ImGui.Begin("overlay",  ImGuiWindowFlags.NoDecoration
    | ImGuiWindowFlags.NoBackground
    | ImGuiWindowFlags.NoBringToFrontOnFocus
    | ImGuiWindowFlags.NoMove
    | ImGuiWindowFlags.NoInputs
    | ImGuiWindowFlags.NoCollapse
    | ImGuiWindowFlags.NoScrollbar
    | ImGuiWindowFlags.NoScrollWithMouse
);

After the window creation I have a Drawing method which contains the following code to draw an image.

drawListPtr = ImGui.GetWindowDrawList();
var imageStart = new Vector2(500f, 200f);
drawListPtr.AddImage(test, imageStart, Vector2.Add(imageStart, new Vector2(820, 745))); // Hardcoded image size for testing

The result of this is an image of letters and symbols. image

Any help will be greatly appreciated!

MenuGamer avatar Jul 31 '24 10:07 MenuGamer