Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/net/irisshaders/imgui/ImGuiMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ImGuiMC {
private ImGuiImplGl3 glAccessor;
private ImGuiImplGlfw glWindow;
private boolean drawing;
private boolean usesSharpFontTexture;

public static ImGuiMC getInstance() {
return INSTANCE;
Expand All @@ -53,6 +54,24 @@ public static boolean startDrawing() {
return getInstance().drawing;
}

public boolean usesSharpFont() {
return this.usesSharpFontTexture;
}

/**
* Enables sharp (nearest) font rendering. Useful for Minecraft-like fonts.
*/
public static void enableSharpFont() {
getInstance().usesSharpFontTexture = true;
}

/**
* Disables sharp (nearest) font rendering, and uses linear font rendering instead.
*/
public static void disableSharpFont() {
getInstance().usesSharpFontTexture = false;
}

private String tryLoadFromClasspath(final String fullLibName) {
if (DEBUG) {
System.out.println("Loading " + fullLibName);
Expand Down Expand Up @@ -145,6 +164,7 @@ public void draw() {
ImGui.updatePlatformWindows();
ImGui.renderPlatformWindowsDefault();
GLFW.glfwMakeContextCurrent(Minecraft.getInstance().getWindow().getWindow());
disableSharpFont();
}

private static boolean isGone;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/irisshaders/imgui/window/ImGuiImplGl3.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import imgui.flag.ImGuiConfigFlags;
import imgui.flag.ImGuiViewportFlags;
import imgui.type.ImInt;
import net.irisshaders.imgui.ImGuiMC;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;

Expand Down Expand Up @@ -56,6 +57,7 @@
import static org.lwjgl.opengl.GL32.GL_LINK_STATUS;
import static org.lwjgl.opengl.GL32.GL_MAJOR_VERSION;
import static org.lwjgl.opengl.GL32.GL_MINOR_VERSION;
import static org.lwjgl.opengl.GL32.GL_NEAREST;
import static org.lwjgl.opengl.GL32.GL_ONE;
import static org.lwjgl.opengl.GL32.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL32.GL_POLYGON_MODE;
Expand Down Expand Up @@ -592,12 +594,14 @@ public boolean createFontsTexture() {
final ImInt height = new ImInt();
final ByteBuffer pixels = fontAtlas.getTexDataAsRGBA32(width, height);

final int texFilter = ImGuiMC.getInstance().usesSharpFont() ? GL_NEAREST : GL_LINEAR;

final int[] lastTexture = new int[1];
glGetIntegerv(GL_TEXTURE_BINDING_2D, lastTexture);
data.fontTexture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, data.fontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // Not on WebGL/ES
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); // Not on WebGL/ES
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); // Not on WebGL/ES
Expand Down
Loading