#Nuklear LWJGL

1 messages · Page 1 of 1 (latest)

sharp star
#

Hi ! Can someone help me to create a simple window context using Nuklear in LWJGL ?
I did some researches again and again on it, I even found the LWJGL demo but none of that were a simple template like an ImGui in C++...
please help !!!

rough novaBOT
#

<@&987246452180930620> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hi ! Can someone help me to create a simple window context using Nuklear in LWJGL ? I did some researches again and again on it, I even found the LWJGL demo but none of that were a simple template like an ImGui in C++... please help !!!

e step-by-step guide on how to create a window context using Nuklear in LWJGL. Could someone please provide me with a clear and concise explanation or code example to help me get started?

Nuklear is a minimalistic GUI library that can be integrated with LWJGL, which is a Java binding for the OpenGL, OpenAL, and Vulkan graphics libraries.

To create a simple window context using Nuklear in LWJGL, you will need to follow these steps:

  1. Set up your LWJGL project with the necessary dependencies for Nuklear.
  2. Initialize GLFW (the OpenGL windowing library used by LWJGL) and create a new window.
  3. Set up Nuklear by creating a new NkContext object and initializing it.
  4. Create a loop to handle input events and update the Nuklear context.
  5. Render the Nuklear GUI within your GLFW window.

Here is an example code snippet to help you get started:

// Initialize GLFW
if (!glfwInit()) {
    throw new IllegalStateException("Unable to initialize GLFW");
}

// Create a new window
long window = glfwCreateWindow(800, 600, "Nuklear Window", NULL, NULL);
if (window == NULL) {
    glfwTerminate();
    throw new RuntimeException("Failed to create GLFW window");
}

// Set up Nuklear
NkContext ctx = Nk.nk_glfw3_init(window, ALLOCATOR);

// Main loop
while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();

    // Update Nuklear context

    // Render Nuklear GUI

    glfwSwapBuffers(window);
}

// Cleanup
nk_free(ctx);
glfwTerminate();

Remember to replace any placeholder values with your actual code and configurations as needed. Good luck with your project!

sharp star
#

Doesn't seem to work out

#

NkContext ctx = Nk.nk_glfw3_init(window, ALLOCATOR);is not working since there's no interface nor classes called like that

weak garden
#

What have you written, and where are you stuck? Please keep in mind that this isn't a code writing service.
If you're looking for people to collaborate with you can try #1150852739467849829 .

sharp star
#
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.nuklear.*;
import static org.lwjgl.nuklear.Nuklear.*;

public class NuklearExample {
    private long window;
    private NkContext ctx;
    private NkUserFont default_font;

    public void run() {
        init();
        loop();
        cleanup();
    }

    private void init() {
        GLFWErrorCallback.createPrint(System.err).set();
        
        if (!GLFW.glfwInit()) {
            throw new IllegalStateException("Unable to initialize GLFW");
        }
        
        window = GLFW.glfwCreateWindow(800, 600, "Nuklear LWJGL Example", MemoryUtil.NULL, MemoryUtil.NULL);
        if (window == MemoryUtil.NULL) {
            throw new RuntimeException("Failed to create GLFW window");
        }
        
        GLFW.glfwMakeContextCurrent(window);
        GL.createCapabilities();
        
        ctx = NkContext.create();
        default_font = NkUserFont.create();
        nk_init(ctx, default_font);
    }

    private void loop() {
        while (!GLFW.glfwWindowShouldClose(window)) {
            try (MemoryStack stack = MemoryStack.stackPush()) {
                nk_input_begin(ctx);
                nk_input_end(ctx);
            }
            
            render();
            GLFW.glfwSwapBuffers(window);
            GLFW.glfwPollEvents();
        }
    }

    private void render() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        
        if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 100, NkRect.malloc()), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE)) {
            nk_layout_row_dynamic(ctx, 30, 1);
            nk_label(ctx, "Hello Nuklear", NK_TEXT_CENTERED);
        }
        nk_end(ctx);
    }

    private void cleanup() {
        nk_free(ctx);
        GLFW.glfwDestroyWindow(window);
        GLFW.glfwTerminate();
    }
    
    public static void main(String[] args) {
        new NuklearExample().run();
    }
}
rough novaBOT
sharp star
#

And I ended up with a log

sharp star
#

I just try to fix what's seems like a memory issue

vast zenith
#

Where did you get this code from?

#

As far as i know nuklear is a C lib and preferably used with C

#

You need to make sure everything is created and destroyed in the exact order, if its not you will have null pointer errors. From what i remember nuklear has very nice examples if you git clone the repo there is a folder full of examples that you can just copy. Im not 100% sure that the java wrapper has it also

#

Nuklear has specific ways that it runs with each seperate version of glfw, and it also works with vulkan but from what i remember its buggy. You need to make sure that the example you use is for the specific version of glfw and glew that you are using