Recent posts

#1
Bug Reports / RFE / Tab key not working with ctrl ...
Last post by MGVizor - June 05, 2025, 12:44:19
The implementation of listener looks something like this:

private static final class GlfwKeyListener implements GLFWKeyCallbackI {
    private int key;

    @Override
    public void invoke(long window, int key, int scancode, int action, int mods) {
        KeyClass.key = key;
        //schedule to set key to 0 on next frame
    }
}

Then I log the inputs with something like this:

private void logUsedKeys() {
    int key = KeyClass.key;
    if (key != 0) {
        LOGGER.info("Key {}", key);
    }
}

However, when the ctrl is down it prints any pressed key, but tab.

Using macOS if it is important. In other apps everything works fine(e.g. switching tabs in browser/intellij idea)
lwjgl version: 3.3.1
#2
Hey ss123she,

The problem is that the UTF8 method encodes strings with a null-terminator by default. However, shaderc_compile_into_spv takes an explicit size_t source_text_size parameter and LWJGL passes sourceBuffer.remaining() there implicitly, which includes the null-terminator.

You can easily fix this with sourceBuffer = stack.UTF8(shaderSource.trim(), false), which will encode the source buffer without the null-terminator.
#3
Lightweight Java Gaming Library / Creating LWJGL 2.10?
Last post by kittylyst - May 11, 2025, 14:11:29
Hi folks,

tl;dr I have a working build of LWJGL v2 that I think would be a worthy basis for a v2.10.0 release. The purpose would simply be to support modern hardware (e.g. modern Linux, Apple M1 and Raspberry Pi 4) - no new features.

Full story:

I bought a game from GOG in Nov 2024 and found that, unfortunately, it doesn't run on my Macbook.

However, I noticed that the crash indicated JavaApplicationStub and I decided to have a go at seeing if I could fix it.

I spent a few hours hacking on this and by fixing LWJGL2 and JInput, I've got a working version that runs on both macOS 14/15 (Apple Silicon) and Fedora 39-41 (Intel) and Raspberry Pi 4.

Since then, I've continued to work on forward-porting LWJGL2 - the repo is here: https://github.com/kittylyst/lwjgl2 with my fixes.

I'm also talking with the JInput folks to add a few fixes there as well (including downgrading required Java version to 8 and introducing aarch64 support).

The Ask:

Is there interest in releasing a 2.10.0 if I take responsibility for producing the patches and looking after the v2 repo? Will someone with the appropriate rights do the release and publication to Maven Central under the existing co-ordinates?

I need my changes (especially RPi support) for one of my projects so if there isn't interest in doing this upstream then I'll fork instead, but that seems silly when the delta is relatively small.
#4
Lightweight Java Gaming Library / Shader compilation failed: sim...
Last post by ss123she - March 28, 2025, 13:54:17
Shader compilation failed: simpleDraw.vs:14: error: '' : unexpected token

While trying to compile:

#version 450
layout(location = 0) in vec3 a_position;
layout(location = 1) in vec2 a_texcoord0;

layout(location = 0) out vec2 v_texcoord0;

layout(binding = 0) uniform Uniforms {
    mat4 u_modelViewProj;
};

void main() {
    v_texcoord0 = a_texcoord0;
    gl_Position = u_modelViewProj * vec4(a_position, 1.0);
}

UTF-8, no BOM

here is my compiling code:
    public static ByteBuffer compileShader(Path shaderPath, int shaderType) {
        long compiler = Shaderc.shaderc_compiler_initialize();
        long options = Shaderc.shaderc_compile_options_initialize();

        try {
            String shaderSource = Files.readString(shaderPath, StandardCharsets.UTF_8);

            try (MemoryStack stack = MemoryStack.stackPush()) {
                ByteBuffer sourceBuffer = stack.UTF8(shaderSource.trim());
                ByteBuffer shaderName = stack.UTF8(shaderPath.getFileName().toString());
                ByteBuffer entryPoint = stack.UTF8("main");

                long result = Shaderc.shaderc_compile_into_spv(
                        compiler,
                        sourceBuffer,
                        shaderType,
                        shaderName,
                        entryPoint,
                        options
                );

                if (Shaderc.shaderc_result_get_compilation_status(result) != Shaderc.shaderc_compilation_status_success) {
                    System.err.println("Shader compilation failed: " + Shaderc.shaderc_result_get_error_message(result));
                    System.err.println("Shader compile log: " + Shaderc.shaderc_result_get_error_message(result));
                    Shaderc.shaderc_result_release(result);
                    return null;
                }

                int spirvSize = (int) Shaderc.shaderc_result_get_length(result);

                ByteBuffer spirv = ByteBuffer.allocateDirect(spirvSize);
                spirv.put(Shaderc.shaderc_result_get_bytes(result)).flip();

                Shaderc.shaderc_result_release(result);
                return spirv;
            }

        } catch (IOException e) {
            System.err.println("Failed to load shader: " + e.getMessage());
            return null;
        } finally {
            Shaderc.shaderc_compile_options_release(options);
            Shaderc.shaderc_compiler_release(compiler);
        }
    }
#5
JOML / Different results when using M...
Last post by huuuubbbb - March 26, 2025, 13:06:31
When running this code
Matrix4f m = new Matrix4f();
Quaternionf q = new Quaternionf(0.0f, 0.965f, 0.2622f, 0.0f);
m.rotate(q);
AxisAngle4f a = new AxisAngle4f();
m.getRotation(a);
System.out.println(a);
m.getRotation(a);
System.out.println(a);
m.getRotation(a);
System.out.println(a);
m.getRotation(a);
System.out.println(a);

i get these results
( 0.000E+0  9.650E-1  2.530E-1 <|  3.142E+0)
( 0.000E+0  9.650E-1  1.000E+0 <|  3.142E+0)
( 0.000E+0  9.650E-1  2.530E-1 <|  3.142E+0)
( 0.000E+0  9.650E-1  1.000E+0 <|  3.142E+0)

This is an edge case where the rotation is around 180 degrees. But why does the result change if the DESTINATION variable has some values in it. Shouldnt the values just be overwritten? I dont understand this behavior. Is this a possible bug? Please explain it :P
#6
OpenGL / Noob failed to render a triang...
Last post by Potty_Jr - March 02, 2025, 07:37:05
Hi guys, I'm new to OpenGL & lwjgl. Today I was following the tutorial for lwjgl 3 on https://ahbejarano.gitbook.io/lwjglgamedev and trying to render a triangle in my window like in chapter 3, but even thought I copied the code given by the author, what I got was a blank window. I'm using Java 8 and the author is using a higher version, he used the record keyword in ShaderProgram which I replaced with an inner class, the rest should be exactly the same. My code is in the attachment, could anyone help?
#7
Lightweight Java Gaming Library / Re: Indie Fighting Game using ...
Last post by cpope9141 - February 20, 2025, 19:54:39
The February release of Area Zero (v0.22.0) is now available: https://ephemeraltechnicalarts.com/area-zero
#8
Lightweight Java Gaming Library / noob question
Last post by 456 - February 02, 2025, 00:36:46
hey guys, i asked AI about how to optimize my graphics and your software came up  :D

i have a real time plotter implemented in java swt, all it does is draw lines and some text and dots, this is done on the java swt canvas, it is already very fast and can update tens of thousands of lines/sec. Do you think your software would improve this?
#9
Bug Reports / RFE / Re: [BUG] Double free on Point...
Last post by spasi - January 09, 2025, 12:29:49
Hey KGAFT,

The name of this method is meant as a hint that it uses ByteBuffer.allocateDirect internally, which allocates a GC-managed ByteBuffer. The free method has this javadoc:

QuoteFrees the buffer allocation.

This method should not be used if the memory backing this buffer is not owned by the buffer.
All MemoryUtil methods that allocate explicitly-managed memory have the following note (or similar):

QuoteMemory allocated with this method must be freed with memFree.
ByteBuffer.allocateDirect, PointerBuffer.allocateDirect, BufferUtils methods and MemoryStack methods do not have such a note because, well, you don't have to do anything special to deallocate the returned buffer.

You may read Memory management in LWJGL for more details.
#10
Bug Reports / RFE / [BUG] Double free on PointerBu...
Last post by KGAFT - January 09, 2025, 10:26:18
During development of my vulkan app with lwjgl, i noticed there are a lot of glibc errors like: double free detected in tcache. After continuously investigation, i found out that all PointerBuffer object allocated through allocateDirect are garbage collected automatically, with no need to free it manually, despite there existing free method. There is need to do something with this, add notice to docs, or make this method private.

P.S: You can repeat it by running this code, and specify the memory limit for java vm:
while(true){
    PointerBuffer pb = PointerBuffer.allocateDirect(9999);
    pb.free();
}