LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Waffles on August 02, 2015, 22:46:48

Title: STBTrueType fails with new driver
Post by: Waffles on August 02, 2015, 22:46:48
So a few days ago I finally managed to get STBTrueType working. Then yesterday, I updated my NVIDIA drivers, and everything started failing again. After trying just about everything short of a goat sacrifice, on a whim I decided to fiddle around with my window hints. I removed the hints that explicitly assign an OpenGL profile and, like magic, my font rendering worked again.

Using this line, the font rendering doesn't work:
Code: [Select]
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
Using this line, it does:
Code: [Select]
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_COMPAT_PROFILE);
I'm not quite sure what's going on here, does STBTrueType depend on some deprecated functions or something? Although I suppose that doesn't make any sense, since it worked just a few days ago? To be fair, my NVIDIA drivers were supposed to be updated a few months ago, but I'm not sure that should make any difference, should it?
Title: Re: STBTrueType fails with new driver
Post by: Cornix on August 03, 2015, 00:01:52
Drivers can have bugs too. It might be that either the new ones are too strict, or the old ones were not strict enough.
However, I dont know what is causing the problem with STBTrueType; I have not worked with it yet.
Title: Re: STBTrueType fails with new driver
Post by: spasi on August 03, 2015, 05:54:29
STB does not call any OpenGL functions internally. It sounds like you're using deprecated functionality to render the font texture, which is not available under the core profile. What error are you getting exactly? Try a debug context with a debug message callback and also use "-Dorg.lwjgl.util.Debug=true" when launching the JVM.
Title: Re: STBTrueType fails with new driver
Post by: Waffles on August 03, 2015, 23:14:23
When using the core profile I get all the quads rendered in the right place, but with a completely black texture. I also tried simply rendering the entire texture created by STB on screen and it shows up completely black. I've been rendering it with a very basic vertex & fragment shader; multiply vertex by matrix, output texture. I can't imagine using deprecated functionality, since I'm using the same shader program for my regular textures and those still seem to work under the core profile..

Anyways, when I enable the debug I get the following output:

Code: [Select]
[LWJGL] Version 3.0.0a | Windows 8.1 | amd64
[LWJGL] MemoryUtil MemoryAccessor: MemoryAccessorUnsafe
[LWJGL] Failed to locate address for GL function glNamedBufferPageCommitmentARB
[LWJGL] [GL] GL_ARB_sparse_buffer was reported as available but an entry point is missing.
[LWJGL] Failed to locate address for GL function wglCopyImageSubDataNV
[LWJGL] [GL] WGL_NV_copy_image was reported as available but an entry point is missing.

By debug message callback do you mean the thing set by GLWF.glwfSetErrorCallback? That's not throwing any errors at any rate.
Title: Re: STBTrueType fails with new driver
Post by: spasi on August 04, 2015, 05:32:36
By debug message callback do you mean the thing set by GLWF.glwfSetErrorCallback? That's not throwing any errors at any rate.

I meant the OpenGL debug functionality. It is provided by a few different extensions, but LWJGL provides a shortcut that makes it easy to setup:

Code: [Select]
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
// ..create window..
glfwMakeContextCurrent(window);
Closure debugProc = GLContext.createFromCurrent().setupDebugMessageCallback();

Make sure to store the debugProc closure so that it doesn't get GCed, just like GLFW callbacks.

(also note that the above code is for 3.0.0a and is slightly different in the latest LWJGL 3.0.0b build)
Title: Re: STBTrueType fails with new driver
Post by: Waffles on August 04, 2015, 10:50:40
Yes, that did give some more information on the problem.

During this call buffering the font data an error is thrown:
Code: [Select]
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA, tsize, tsize, 0, GL11.GL_ALPHA, GL11.GL_UNSIGNED_BYTE, data)

GL_ALPHA is apparently invalid as an internalformat. A bit of snooping around revealed that GL_ALPHA is no longer useable in the core profile. I got these values from the demo at GitHub (https://github.com/LWJGL/lwjgl3/blob/master/modules/core/src/test/java/org/lwjgl/demo/stb/Truetype.java), which doesn't use the core profile to begin with, so that explains a lot.

I didn't give this a second thought before this issue, but am I right in thinking this means STB's font data uses a single float value per pixel? So I need to use GL_RED instead, and swap it around to the alpha channel in my fragment shader?
Title: Re: STBTrueType fails with new driver
Post by: spasi on August 04, 2015, 10:54:05
I didn't give this a second thought before this issue, but am I right in thinking this means STB's font data uses a single float value per pixel?

It's an unsigned byte per pixel, not a float.
Title: Re: STBTrueType fails with new driver
Post by: Cornix on August 04, 2015, 11:44:03
To answer your question: Yes, you need to use GL_RED.
Title: Re: STBTrueType fails with new driver
Post by: Waffles on August 04, 2015, 13:33:12
Ok great, I imagine I should get it to work now, thank you very much.