Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with displaying png image with SharpDX #489

Open
MenuGamer opened this issue Jul 31, 2024 · 0 comments
Open

Help with displaying png image with SharpDX #489

MenuGamer opened this issue Jul 31, 2024 · 0 comments

Comments

@MenuGamer
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant