Comments (1)
UPDATE: I was able to replicate the bug by creating a new project with the default ImGui pom.xml for Maven and use the following code.
`import static org.lwjgl.glfw.GLFW.glfwPollEvents;
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
import java.awt.Color;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.IntBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import imgui.ImFont;
import imgui.ImFontAtlas;
import imgui.ImFontConfig;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.flag.ImGuiConfigFlags;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
public class Main {
/*
* VARIABLES
*/
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
private String GLSLversion = "#version 150";
private Color colorBg = new Color(.2f, 0f, .4f, 1);
public long windowHandle;
private GLCapabilities capabilities;
private ImFont defaultFont = new ImFont();
/*
* METHODS - MAIN
*/
public static void main(String[] args) {
Main main = new Main();
main.init();
while(!glfwWindowShouldClose(main.windowHandle)) {
main.processFrame();
}
}
/*
* METHODS - INIT
*/
public void init() {
initWindow();
ImGui.createContext();
imGuiGlfw.init(windowHandle, true);
imGuiGl3.init(GLSLversion);
setupDefaultFont();
}
private void initWindow() {
GLFWErrorCallback.createPrint(System.err).set();
if (!GLFW.glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW!");
}
//Set GLSL Version
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE); //Required for Mac Support
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
final GLFWVidMode vidmode = Objects.requireNonNull(GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()));
windowHandle = GLFW.glfwCreateWindow(vidmode.width(), vidmode.height(), "Font Test", MemoryUtil.NULL, MemoryUtil.NULL);
if (windowHandle == MemoryUtil.NULL) {
throw new RuntimeException("Failed to create GUI GLFW window!");
}
try (MemoryStack stack = MemoryStack.stackPush()) {
final IntBuffer pWidth = stack.mallocInt(1); // int*
final IntBuffer pHeight = stack.mallocInt(1); // int*
GLFW.glfwGetWindowSize(windowHandle, pWidth, pHeight);
GLFW.glfwSetWindowPos(windowHandle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
}
GLFW.glfwMakeContextCurrent(windowHandle);
GLFW.glfwSwapInterval(GLFW.GLFW_TRUE);
GLFW.glfwShowWindow(windowHandle);
GLFW.glfwMaximizeWindow(windowHandle);
capabilities = GL.createCapabilities();
}
public static byte[] loadBytesFromResources(String name) {
try {
return Files.readAllBytes(Paths.get(Main.class.getResource(name).toURI()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
return null;
}
private void setupDefaultFont() {
final ImGuiIO io = ImGui.getIO();
ImFontAtlas fontAtlas = ImGui.getIO().getFonts();
fontAtlas.setLocked(false);
defaultFont = io.getFonts().addFontDefault();
final ImFontConfig fontConfig = new ImFontConfig();
fontConfig.setMergeMode(true);
fontConfig.setFontDataOwnedByAtlas(false);
fontConfig.setGlyphRanges(fontAtlas.getGlyphRangesDefault());
defaultFont = fontAtlas.addFontFromMemoryTTF(loadBytesFromResources("/fonts/Roboto-Medium.ttf"), 5, fontConfig);
fontAtlas.build();
fontConfig.destroy();
}
/*
* METHODS - RUNNING
*/
public void processFrame() {
startFrame();
drawWindow();
endFrame();
}
private void startFrame() {
GLFW.glfwMakeContextCurrent(windowHandle);
GL.setCapabilities(capabilities);
GL32.glClearColor(colorBg.getRed(), colorBg.getGreen(), colorBg.getBlue(), colorBg.getAlpha());
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
imGuiGlfw.newFrame();
ImGui.newFrame();
ImGui.pushFont(defaultFont);
}
private void endFrame() {
ImGui.popFont();
ImGui.render();
imGuiGl3.renderDrawData(ImGui.getDrawData());
if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
final long backupWindowPtr = GLFW.glfwGetCurrentContext();
ImGui.updatePlatformWindows();
ImGui.renderPlatformWindowsDefault();
GLFW.glfwMakeContextCurrent(backupWindowPtr);
}
glfwPollEvents();
glfwSwapBuffers(windowHandle);
}
private void drawWindow() {
if(ImGui.begin("Window")) {
if(ImGui.button("hello")) {
}
ImGui.end();
}
}
/*
* CONSTRUCTOR
*/
public Main() {
}
}
`
from imgui-java.
Related Issues (20)
- Bug: every launch copies the binary DLL into Windows Temp dir
- Binding wrong type: PlotShaded yref parameter should be double
- ImGui.image() should expect long instead of int for textureId. HOT 10
- Bug: setFullScreen does not work HOT 1
- Mobile Support
- Update ImNodes to latest version
- Unable to assign / use custom ImGuiStyle HOT 1
- Bug: Maven fat jar not working on windows HOT 1
- Calls to getCmdListVtxBufferData() and getCmdListIdxBufferData() overwrite eachother HOT 8
- Bug: Clone Issue
- Bug: OpenGL Rendering in Imgui HOT 2
- Bug: crash when debugging with JDK 21 HOT 1
- [Question] Is it supports lwjgl legacy? (2.7.3) HOT 2
- Bug: ImGuiInputTextCallbackData#insertChars handles UTF-8 characters incorrectly
- Git Clone HOT 1
- Bug: imgui UI is missing in the Gizmo example HOT 1
- Porting of ShowDemo_RealtimePlots over Java
- Missing Bindings: ImGui::ImageButton(ImGuiID id, ImTextureID texture_id, ...etc) HOT 1
- improve string handling performance HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui-java.