#[Help] Integrating Rust + egui into Minecraft GUI (NeoForge)

9 messages · Page 1 of 1 (latest)

gritty kraken
#

Hi everyone,

I’m trying to set up a custom GUI panel in Minecraft that uses egui (Rust) for rendering buttons and other widgets. My setup is a hybrid:

Java side (Forge/Fabric) handles the mod lifecycle and passes the OpenGL context pointer down to Rust via JNI.

Rust side uses egui_glow with glow::Context::from_loader_function to render.

So far:

I can successfully get the GL context address from Java and pass it into Rust.

No errors are thrown on either side.

But nothing actually shows up on screen.

I’ve tried two approaches:

Custom Screen class – overriding render and calling into Rust.

Subscribing to RenderGuiEvent.Post (Forge) – lazy‑initializing egui and then calling renderEgui(dtSeconds) each frame.

In both cases, the Rust code runs, but the panel doesn’t appear. I suspect drawing at the wrong stage in the render pipeline, so Minecraft clears or overwrites my output., i tried simple clear color but nothings

#
package crater.mod;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryUtil;

public class Bridge {
    static {
        System.load("/home/gate0/Projects/mn/rusty/target/debug/librusty.so");
    }

    public static native void initEgui(int width, int height);
    public static native void renderEgui(double deltaSeconds);
    public static native void shutdownEgui();

    // Loader for OpenGL functions (used by Rust via JNI callback)
    public static long getProcAddress(String name) {
    //System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
    //System.out.println("glBindTexture address = " + name);
    //System.out.println("glBindTexture address = " +GL.getFunctionProvider().getFunctionAddress(name) );
        return GL.getFunctionProvider().getFunctionAddress(name);
    }

}
#
package crater.mod;

import org.lwjgl.opengl.GL;

import com.llamalad7.mixinextras.lib.antlr.runtime.atn.SemanticContext.AND;
import com.mojang.blaze3d.platform.Window;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.RenderGuiEvent;
import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent;

public class Events{

    private static boolean eguiInitialized = false;
    private static long lastFrameTime = System.nanoTime();
    @SubscribeEvent
    public void onLivingIncomingDamage(LivingIncomingDamageEvent event) {
        // your logic here
        LivingEntity entity = event.getEntity();
        LivingEntity player = event.getEntity().getLastAttacker();

        // Only care about mobs (skip players if you want)
        if (!(entity instanceof ServerPlayer) & (player != null)) {
            // Send a message to all players on the server
            entity.getServer().getPlayerList().broadcastSystemMessage(
                Component.literal(entity.getName().getString() + " took " +player.getUUID().toString()+ " damage!"),
                false
            );
        }
    }
    @SubscribeEvent
public void onRenderGui(RenderGuiEvent.Post event) {
           if (!eguiInitialized) {
        // Check if GL context is current
        if (GL.getCapabilities() != null) {
            Window window = Minecraft.getInstance().getWindow();
            Bridge.initEgui(window.getWidth(), window.getHeight());
            eguiInitialized = true;
        } else {
            // Skip until context is ready
            return;
        }
    }
    long now = System.nanoTime();
    double dtSeconds = (now - lastFrameTime) / 1_000_000_000.0;
    lastFrameTime = now;

    Bridge.renderEgui(dtSeconds); 
}



}




#

this is all the files

gritty kraken
#

i strongly thought egui draw but mincraft draw over it continuously

clever talon
#

Why are you asking minecraft OpenGL questions on a Vulkan discord server? The graphics programming discord server would be my best guess. Also, make sure you try out Renderdoc, which might show your draws somewhere

gritty kraken
#

owww sorry XD

#

i gonna delete it

#

sorry again