Skip to content

Commit

Permalink
Added ImGui
Browse files Browse the repository at this point in the history
  • Loading branch information
nrebei2 committed Apr 11, 2023
1 parent 29e0994 commit 5cf4bea
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 21 deletions.
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ buildscript {


repositories {
maven { url 'https://s01.oss.sonatype.org' }
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
google()
}
dependencies {
Expand All @@ -16,6 +18,7 @@ buildscript {

allprojects {
apply plugin: "eclipse"
apply plugin: 'idea'

version = '1.0'
ext {
Expand Down Expand Up @@ -55,16 +58,23 @@ project(":desktop") {

project(":core") {
apply plugin: "java-library"
sourceCompatibility = 8
targetCompatibility = 8


dependencies {
api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
api "com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
api "com.badlogicgames.gdx:gdx-ai:$aiVersion"

}
}

api "io.github.spair:imgui-java-binding:$imguiVersion"
api "io.github.spair:imgui-java-lwjgl3:$imguiVersion"
api "io.github.spair:imgui-java-natives-linux:$imguiVersion"
api "io.github.spair:imgui-java-natives-macos:$imguiVersion"
api "io.github.spair:imgui-java-natives-windows:$imguiVersion"
}
}
35 changes: 35 additions & 0 deletions core/src/infinityx/lunarhaze/EditorMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
import infinityx.assets.AssetDirectory;
import infinityx.lunarhaze.graphics.GameCanvas;
import infinityx.util.ScreenObservable;
Expand Down Expand Up @@ -36,6 +41,26 @@ public class EditorMode extends ScreenObservable implements Screen, InputProcess
*/
public final static int GO_MENU = 0;

/** ImGui classes */
private ImGuiImplGlfw imGuiGlfw;
private ImGuiImplGl3 imGuiGl3;

public void setupImGui() {
// ImGui initialization
this.imGuiGlfw = new ImGuiImplGlfw();
this.imGuiGl3 = new ImGuiImplGl3();

long windowHandle = ((Lwjgl3Graphics) Gdx.graphics).getWindow().getWindowHandle();
ImGui.createContext();
ImGuiIO io = ImGui.getIO();
io.setIniFilename(null);
io.getFonts().addFontDefault();
io.getFonts().build();

imGuiGlfw.init(windowHandle, true);
imGuiGl3.init("#version 110");
}

/**
* type Selected :=
* | Tile of (String, Texture)
Expand Down Expand Up @@ -203,6 +228,16 @@ private void draw(float delta) {
canvas.begin(GameCanvas.DrawPass.SHAPE, level.getView().x, level.getView().y);
board.drawOutline(canvas);
canvas.end();

imGuiGlfw.newFrame();
ImGui.newFrame();

// --- ImGUI draw commands go here ---
ImGui.button("I'm a Button!");
// ---

ImGui.render();
imGuiGl3.renderDrawData(ImGui.getDrawData());
}

/**
Expand Down
9 changes: 9 additions & 0 deletions core/src/infinityx/lunarhaze/GDXRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.gl3.ImGuiImplGl3;
import infinityx.assets.AssetDirectory;
import infinityx.lunarhaze.graphics.GameCanvas;
import infinityx.util.ScreenObserver;
import imgui.glfw.ImGuiImplGlfw;


/**
* Owns and handles switching between Screens
Expand Down Expand Up @@ -89,6 +94,10 @@ public void create() {
editor.setObserver(this);

setScreen(loading);

editor.setupImGui();


}

/**
Expand Down
1 change: 0 additions & 1 deletion core/src/infinityx/lunarhaze/graphics/ShaderRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void end() {
*
* @param x x-position
* @param y y-position
* @param uniforms uniforms to be passed into shader
* @param height height of quad
* @param width width of quad
*/
Expand Down
5 changes: 5 additions & 0 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ task dist(type: Jar) {
with jar
}

dependencies {
implementation project(path: ':core')
implementation project(path: ':core')
}


dist.dependsOn classes

Expand Down
17 changes: 0 additions & 17 deletions gameplay 3.txt

This file was deleted.

Empty file removed gameplay.txt
Empty file.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms128m -Xmx1500m
org.gradle.configureondemand=false

imguiVersion=1.86.8

0 comments on commit 5cf4bea

Please sign in to comment.