Reputation: 157
Not sure how to create a Font Face using LWJGL Freetype binding. Couldn't find enough documentation or any examples around it.
I can load the library, but I get a SIGSEGV error when I try to load the font file (a woff file).
Here is what I tried to do:
package org.example;
import org.lwjgl.*;
import org.lwjgl.system.*;
import org.lwjgl.util.freetype.FT_Face;
import java.io.IOException;
import java.io.InputStream;
import java.nio.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.util.freetype.FreeType.*;
public class Main {
public static void main(String[] args) {
// For now just verify that the FreeType library loads correctly
try (MemoryStack stack = stackPush()) {
PointerBuffer pp = stack.mallocPointer(1);
int err = FT_Init_FreeType(pp);
if (err != FT_Err_Ok) {
throw new IllegalStateException("Failed to initialize FreeType: " + FT_Error_String(err));
}
long library = pp.get(0);
IntBuffer major = stack.mallocInt(1);
IntBuffer minor = stack.mallocInt(1);
IntBuffer patch = stack.mallocInt(1);
FT_Library_Version(library, major, minor, patch);
System.out.println("Loaded FreeType " + major.get(0) + "." + minor.get(0) + "." + patch.get(0));
FT_Done_FreeType(library);
// Load the WOFF file
String fontPath = "AdelleSans-ThinItalic.woff";
byte[] fontData;
try (InputStream fileStream = Main.class.getResourceAsStream(fontPath)) {
assert fileStream != null;
fontData = fileStream.readAllBytes();
}
ByteBuffer fontByteBuffer = MemoryUtil.memAlloc(1024 * 1024);
fontByteBuffer.put(fontData);
fontByteBuffer.flip();
PointerBuffer pointerBuffer = stack.mallocPointer(1); // not sure how to create the PointBuffer
int error = FT_New_Memory_Face(library, fontByteBuffer, fontByteBuffer.remaining(), pointerBuffer);
System.out.println(error);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Here is the error I get:
Task :org.example.Main.main() FAILED Loaded FreeType 2.13.3
A fatal error has been detected by the Java Runtime Environment:
SIGSEGV (0xb) at pc=0x000000012f240600, pid=44875, tid=259
JRE version: OpenJDK Runtime Environment Temurin-17.0.7+7 (17.0.7+7) (build 17.0.7+7) Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (17.0.7+7, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64) Problematic frame: C [libfreetype.dylib+0x8600]
Upvotes: 0
Views: 36