Closed wrymn closed 6 years ago
Could you please try replacing JImTextureID.fromFile(resource)
with JImTextureID.fromFile(resource.getFile().substring(1))
?
This doesn't happen on Linux. Maybe I should re-impl the API.
You can see the path is converted to /D:/Development/Projects/Java/GradleEditor/out/production/resources/img.png
, and the leading /
is unexpected.
@ice1000 thank you very much for the reply
Sadly, still the same problem
code is now
URL resource = this.getClass().getResource("img.png");
String path = resource.getPath().substring(1);
System.err.println(path);
JImTextureID texture = JImTextureID.fromFile(path);
but the issue persists
D:/Development/Projects/Java/GradleEditor/out/production/resources/img.png
Exception in thread "main" java.lang.IllegalStateException: cannot load D:/Development/Projects/Java/GradleEditor/out/production/resources/img.png
at org.ice1000.jimgui.JImTextureID.fromFile(JImTextureID.java:41)
at Application.init(Application.java:29)
at Application.run(Application.java:22)
at Application.main(Application.java:14)
That should be a bug, or your image cannot be loaded by DirectX.
Could you plz upload your image here? You can just drag-and-drop the image to the comment and wait for a while.
Could you please try loading this image?
that was the test image. Your image did not load either.
Here is full java code, just to be safe: https://pastebin.com/e6zD5amk
Tested on my friend's laptop, it works..
Your image...
Which operating system are you using? Do you have DirectX9 installed?
@ice1000 now I see the issue. I have not created new JImGui() instance.
There should be some tutorial snippet code in github main page.
This is finally working
JniLoader.load();
JImGui gui = new JImGui();
URL resource = this.getClass().getResource("/img.png");
String path = resource.getPath().substring(1);
System.err.println(path);
JImTextureID texture = JImTextureID.fromFile(path);
while(!gui.windowShouldClose()){
gui.initNewFrame();
gui.text("Hello JImGui");
gui.image(texture, 100, 100);
gui.render();
}
I see. It's due to a design problem of the API.
You should create the texture after the JImGui
instance is created.
Try this code, I promise this will work! (flag
public class Main {
@SuppressWarnings("AccessStaticViaInstance")
public static void main(String[] args) throws URISyntaxException {
JniLoader.load();
try (JImGui gui = new JImGui()) {
JImTextureID imTextureID = JImTextureID
.fromFile(Paths.get(Main.class.getResource([path to your image]).toURI()));
while (!gui.windowShouldClose()) {
gui.initNewFrame();
gui.image(imTextureID, imTextureID.width, imTextureID.height);
gui.render();
}
}
}
}
My API is badly designed -- I've put the rendering framework (dx9 on win and ogl on *nix) initialization code inside the constructor of JImGui
, while the creation of the textures should be done after the initialization of the rendering framework.
My initial goal is to prevent the user from worrying about the rendering framework, this is why I've mixed the initialization together. AFAIK a small tutorial should be written, the API is somewhat misleading.
A new idea: make createFromFile
a method of JImGui
!
@wrymn Create a new issue first, this issue should be closed.
@wrymn Short answer: it's production ready if you just want to use the imgui api only.
To interact with the low-level API of the rendering framework, you need some hacking, but let's first move to another issue.
I am trying to draw an image. The only parameter I can pass is an JImTextureID.
This is my code, resource is loaded correctly.
Would you point me to a problem?
Error: