Skip to content

Commit b1a1457

Browse files
committed
Enable ImGui
1 parent 99f928d commit b1a1457

16 files changed

Lines changed: 293 additions & 266 deletions

File tree

examples/graphics/gdx-gl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies {
66
api(project(":examples:graphics:gdx-shared"))
77

88
implementation("com.badlogicgames.gdx:gdx:${LibExt.gdxVersion}")
9+
api("com.github.xpenatan.xImGui:gdx-gl-impl:${LibExt.gdxImGuiVersion}")
910
api(project(":extensions:gdx:gdx-gl"))
1011
}
1112

examples/graphics/gdx-gl/src/main/java/jolt/example/graphics/GdxGraphicApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer;
77
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20;
88
import com.badlogic.gdx.utils.ScreenUtils;
9+
import imgui.gdx.ImGuiGdxGLImpl;
10+
import imgui.gdx.ImGuiGdxImpl;
911
import jolt.gdx.JoltDebugRenderer;
1012
import jolt.gdx.gl.GdxDebugRenderer;
1113

@@ -39,4 +41,9 @@ public BitmapFont createBitmapFont() {
3941
public GraphicType getGraphicType() {
4042
return GraphicType.OpenGL;
4143
}
44+
45+
@Override
46+
public ImGuiGdxImpl getImGuiImpl() {
47+
return new ImGuiGdxGLImpl();
48+
}
4249
}

examples/graphics/gdx-shared/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
dependencies {
66
implementation("com.badlogicgames.gdx:gdx:${LibExt.gdxVersion}")
77
api(project(":jolt:jolt-core"))
8+
api("com.github.xpenatan.xImGui:gdx-shared-impl:${LibExt.gdxImGuiVersion}")
89
implementation(project(":extensions:gdx:gdx-utils"))
910
}
1011

examples/graphics/gdx-shared/src/main/java/jolt/example/graphics/GraphicApi.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.badlogic.gdx.graphics.g2d.Batch;
44
import com.badlogic.gdx.graphics.g2d.BitmapFont;
55
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer;
6+
import imgui.gdx.ImGuiGdxImpl;
67
import jolt.gdx.JoltDebugRenderer;
78

89
public interface GraphicApi {
@@ -12,4 +13,5 @@ public interface GraphicApi {
1213
Batch createSpriteBatch();
1314
BitmapFont createBitmapFont();
1415
GraphicType getGraphicType();
16+
ImGuiGdxImpl getImGuiImpl();
1517
}

examples/graphics/gdx-wgpu/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies {
77

88
implementation("com.badlogicgames.gdx:gdx:${LibExt.gdxVersion}")
99
api("io.github.monstroussoftware.gdx-webgpu:gdx-webgpu:${LibExt.gdxWebGPUVersion}")
10+
api("com.github.xpenatan.xImGui:gdx-wgpu-impl:${LibExt.gdxImGuiVersion}")
1011

1112
api(project(":extensions:gdx:gdx-wgpu"))
1213
}

examples/graphics/gdx-wgpu/src/main/java/jolt/example/graphics/WGPUGraphicApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.monstrous.gdx.webgpu.graphics.g2d.WgSpriteBatch;
88
import com.monstrous.gdx.webgpu.graphics.utils.WgImmediateModeRenderer;
99
import com.monstrous.gdx.webgpu.graphics.utils.WgScreenUtils;
10+
import imgui.gdx.ImGuiGdxImpl;
11+
import imgui.gdx.ImGuiGdxWGPUImpl;
1012
import jolt.gdx.JoltDebugRenderer;
1113
import jolt.gdx.wgpu.WGPUDebugRenderer;
1214

@@ -40,4 +42,9 @@ public BitmapFont createBitmapFont() {
4042
public GraphicType getGraphicType() {
4143
return GraphicType.WGPU;
4244
}
45+
46+
@Override
47+
public ImGuiGdxImpl getImGuiImpl() {
48+
return new ImGuiGdxWGPUImpl();
49+
}
4350
}

examples/samples/core/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ dependencies {
1616

1717
implementation(project(":examples:graphics:gdx-shared"))
1818
api("com.badlogicgames.gdx:gdx:${LibExt.gdxVersion}")
19-
// implementation("com.github.xpenatan.gdx-imgui:gdx-impl:${LibExt.gdxImGuiVersion}")
20-
// implementation("com.github.xpenatan.gdx-imgui:imgui-ext-core:${LibExt.gdxImGuiVersion}")
19+
implementation("com.github.xpenatan.xImGui:imgui-core:${LibExt.gdxImGuiVersion}")
2120
}
2221

2322
java {
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package jolt.example.samples.app;
22

3+
import com.badlogic.gdx.Gdx;
34
import com.badlogic.gdx.InputMultiplexer;
45
import com.badlogic.gdx.ScreenAdapter;
56
import com.badlogic.gdx.graphics.FPSLogger;
6-
//import imgui.ImDrawData;
7-
//import imgui.ImGui;
8-
//import imgui.ImGuiCol;
9-
//import imgui.ImGuiConfigFlags;
10-
//import imgui.ImGuiIO;
11-
//import imgui.ImGuiStyle;
12-
//import imgui.gdx.ImGuiGdxImpl;
13-
//import imgui.gdx.ImGuiGdxInput;
7+
import imgui.ImDrawData;
8+
import imgui.ImGui;
9+
import imgui.ImGuiIO;
10+
import imgui.ImGuiStyle;
11+
import imgui.ImTemp;
12+
import imgui.enums.ImGuiCol;
13+
import imgui.enums.ImGuiConfigFlags;
14+
import imgui.gdx.ImGuiGdxImpl;
15+
import imgui.gdx.ImGuiGdxInput;
16+
import imgui.gdx.ImGuiGdxInputMultiplexer;
1417
import jolt.example.graphics.GraphicManagerApi;
1518
import jolt.example.samples.app.tests.vehicle.TankTest;
1619
import static com.badlogic.gdx.Gdx.input;
@@ -20,8 +23,8 @@ public class GameScreen extends ScreenAdapter {
2023
private SamplesApp samplesApp;
2124
private FPSLogger fpsLogger;
2225

23-
// private ImGuiGdxImpl impl;
24-
// private ImGuiGdxInput input;
26+
private ImGuiGdxImpl impl;
27+
private ImGuiGdxInput input;
2528
private InputMultiplexer inputMultiplexer;
2629

2730
@Override
@@ -30,33 +33,33 @@ public void show() {
3033
samplesApp = new SamplesApp();
3134
fpsLogger = new FPSLogger();
3235

33-
// ImGui.CreateContext();
34-
// ImGuiIO io = ImGui.GetIO();
35-
// io.set_ConfigFlags(ImGuiConfigFlags.DockingEnable);
36-
// input = new ImGuiGdxInput();
37-
// impl = new ImGuiGdxImpl();
38-
input.setInputProcessor(inputMultiplexer);
39-
// inputMultiplexer.addProcessor(input);
36+
ImGui.CreateContext();
37+
ImGuiIO io = ImGui.GetIO();
38+
io.set_ConfigFlags(ImGuiConfigFlags.DockingEnable);
39+
input = new ImGuiGdxInput();
40+
impl = GraphicManagerApi.graphicApi.getImGuiImpl();
41+
Gdx.input.setInputProcessor(inputMultiplexer);
42+
inputMultiplexer.addProcessor(input);
4043
samplesApp.setup(inputMultiplexer);
4144
// samplesApp.startTest(NarrowPhaseQueryCastRayTest.class);
4245
// samplesApp.startTest(BoxShapeTest.class);
4346
samplesApp.startTest(TankTest.class);
4447
// samplesApp.startTest(CharacterSpaceShipTest.class);
4548

46-
// ImGuiStyle imGuiStyle = ImGui.GetStyle();
47-
// imGuiStyle.Colors(ImGuiCol.WindowBg, 0.00f, 0.00f, 0.00f, 0.6f);
49+
ImGuiStyle imGuiStyle = ImGui.GetStyle();
50+
imGuiStyle.set_Colors(ImGuiCol.WindowBg.getValue(), ImTemp.ImVec4_1(0.00f, 0.00f, 0.00f, 0.6f));
4851
}
4952

5053
@Override
5154
public void render(float delta) {
5255
GraphicManagerApi.graphicApi.clearScreen(0.1f, 0.1f, 0.8f, 1, true);
5356
samplesApp.render(delta);
5457
fpsLogger.log();
55-
// impl.newFrame();
58+
impl.newFrame();
5659
samplesApp.renderUI();
57-
// ImGui.Render();
58-
// ImDrawData drawData = ImGui.GetDrawData();
59-
// impl.render(drawData);
60+
ImGui.Render();
61+
ImDrawData drawData = ImGui.GetDrawData();
62+
impl.render(drawData);
6063
}
6164

6265
@Override
@@ -66,7 +69,7 @@ public void resize(int width, int height) {
6669

6770
@Override
6871
public void hide() {
69-
// impl.dispose();
72+
impl.dispose();
7073
samplesApp.dispose();
7174
}
7275
}

examples/samples/core/src/main/java/jolt/example/samples/app/InitScreen.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.badlogic.gdx.ScreenAdapter;
44
//import imgui.ImGuiLoader;
5+
import imgui.ImGuiLoader;
56
import jolt.JoltLoader;
67

78
public class InitScreen extends ScreenAdapter {
@@ -16,11 +17,11 @@ public InitScreen(JoltGame game) {
1617

1718
@Override
1819
public void show() {
19-
// ImGuiLoader.init((isSuccess, e) -> {
20-
// if(isSuccess) {
20+
ImGuiLoader.init((isSuccess, e) -> {
21+
if(isSuccess) {
2122
JoltLoader.init((joltSuccess, e2) -> init = joltSuccess);
22-
// }
23-
// });
23+
}
24+
});
2425
}
2526

2627
@Override

examples/samples/core/src/main/java/jolt/example/samples/app/SamplesApp.java

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
//import imgui.ImGuiCond;
1515
//import imgui.ImGuiTabBarFlags;
1616
//import imgui.ImVec2;
17+
import imgui.ImGui;
18+
import imgui.ImTemp;
19+
import imgui.enums.ImGuiCond;
20+
import imgui.enums.ImGuiTabBarFlags;
1721
import jolt.example.graphics.GraphicManagerApi;
1822
import jolt.example.samples.app.imgui.FPSRenderer;
1923
import jolt.example.samples.app.imgui.ImGuiSettingsRenderer;
@@ -97,44 +101,44 @@ public void render(float delta) {
97101
}
98102

99103
public void renderUI() {
100-
// Class<Test> newTest = null;
101-
// ImGui.SetNextWindowSize(ImVec2.TMP_1.set(250, 400), ImGuiCond.FirstUseEver);
102-
// ImGui.Begin("Settings");
103-
//
104-
// fpsRenderer.render();
105-
//
106-
// newTest = settingsRenderer.render(allTests);
107-
//
108-
// settingsRenderer.idlBool.set(isPaused);
109-
// if(ImGui.Checkbox("IsPaused", settingsRenderer.idlBool)) {
110-
// isPaused = settingsRenderer.idlBool.getValue();
111-
// }
112-
//
113-
// settingsRenderer.idlBool.set(debugRenderer.isEnable());
114-
// if(ImGui.Checkbox("DebugRenderer", settingsRenderer.idlBool)) {
115-
// debugRenderer.setEnable(settingsRenderer.idlBool.getValue());
116-
// }
117-
//
118-
// if(ImGui.BeginTabBar("##Settings", ImGuiTabBarFlags.FittingPolicyScroll.or(ImGuiTabBarFlags.Reorderable))) {
119-
// if(ImGui.BeginTabItem("Physics")) {
120-
// settingsRenderer.render(joltInstance);
121-
// ImGui.EndTabItem();
122-
// }
123-
// if(ImGui.BeginTabItem("DebugRenderer")) {
124-
// settingsRenderer.render(debugSettings);
125-
// ImGui.EndTabItem();
126-
// }
127-
// if(ImGui.BeginTabItem("Test")) {
104+
Class<Test> newTest = null;
105+
ImGui.SetNextWindowSize(ImTemp.ImVec2_1(250, 400), ImGuiCond.FirstUseEver);
106+
ImGui.Begin("Settings");
107+
108+
fpsRenderer.render();
109+
110+
newTest = settingsRenderer.render(allTests);
111+
112+
settingsRenderer.idlBool.set(isPaused);
113+
if(ImGui.Checkbox("IsPaused", settingsRenderer.idlBool)) {
114+
isPaused = settingsRenderer.idlBool.getValue();
115+
}
116+
117+
settingsRenderer.idlBool.set(debugRenderer.isEnable());
118+
if(ImGui.Checkbox("DebugRenderer", settingsRenderer.idlBool)) {
119+
debugRenderer.setEnable(settingsRenderer.idlBool.getValue());
120+
}
121+
122+
if(ImGui.BeginTabBar("##Settings", ImGuiTabBarFlags.FittingPolicyScroll.or(ImGuiTabBarFlags.Reorderable))) {
123+
if(ImGui.BeginTabItem("Physics")) {
124+
settingsRenderer.render(joltInstance);
125+
ImGui.EndTabItem();
126+
}
127+
if(ImGui.BeginTabItem("DebugRenderer")) {
128+
settingsRenderer.render(debugSettings);
129+
ImGui.EndTabItem();
130+
}
131+
if(ImGui.BeginTabItem("Test")) {
128132
renderTestUI();
129-
// ImGui.EndTabItem();
130-
// }
131-
// ImGui.EndTabBar();
132-
// }
133-
// ImGui.End();
134-
//
135-
// if(newTest != null) {
136-
// startTest(newTest);
137-
// }
133+
ImGui.EndTabItem();
134+
}
135+
ImGui.EndTabBar();
136+
}
137+
ImGui.End();
138+
139+
if(newTest != null) {
140+
startTest(newTest);
141+
}
138142
}
139143

140144
private void renderTestUI() {

0 commit comments

Comments
 (0)