Add freetype support
This commit is contained in:
1 parent
407d1b9cc4
commit
7f152431fa
7 files changed
+90
-1
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -24,6 +24,7 @@ class GenerateLibs extends DefaultTask {
|
|||||||
// Copy ImGui h/cpp files
|
// Copy ImGui h/cpp files
|
||||||
project.copy { CopySpec spec ->
|
project.copy { CopySpec spec ->
|
||||||
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
|
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
|
||||||
|
spec.from(project.rootProject.file('imgui/misc/freetype')) { CopySpec it -> it.include('*.h', '*.cpp') }
|
||||||
spec.from(project.rootProject.file('imgui-binding/src/main/native'))
|
spec.from(project.rootProject.file('imgui-binding/src/main/native'))
|
||||||
spec.into(jniDir)
|
spec.into(jniDir)
|
||||||
}
|
}
|
||||||
@@ -37,6 +38,17 @@ class GenerateLibs extends DefaultTask {
|
|||||||
def linux32 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, false)
|
def linux32 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, false)
|
||||||
def linux64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, true)
|
def linux64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Linux, true)
|
||||||
|
|
||||||
|
// Freetype Deps Config
|
||||||
|
win32.cppFlags += " -fstack-protector -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
|
||||||
|
win32.libraries += "-lfreetype -lbz2 -lssp"
|
||||||
|
win64.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
|
||||||
|
win64.libraries += "-lfreetype -lbz2 -lssp"
|
||||||
|
linux32.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
|
||||||
|
linux32.linkerFlags += " -lfreetype"
|
||||||
|
linux64.cppFlags += " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
|
||||||
|
linux64.linkerFlags += " -lfreetype"
|
||||||
|
// End
|
||||||
|
|
||||||
new AntScriptGenerator().generate(buildConfig, win32, win64, linux32, linux64)
|
new AntScriptGenerator().generate(buildConfig, win32, win64, linux32, linux64)
|
||||||
|
|
||||||
// Generate native libraries
|
// Generate native libraries
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package imgui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read: https://raw.githubusercontent.com/ocornut/imgui/v1.76/misc/freetype/README.md
|
||||||
|
*/
|
||||||
|
public final class ImGuiFreeType {
|
||||||
|
private ImGuiFreeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*JNI
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_freetype.h>
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void buildFontAtlas(final ImFontAtlas atlas) {
|
||||||
|
nBuildFontAtlas(atlas.ptr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void buildFontAtlas(final ImFontAtlas atlas, int extraFlags) {
|
||||||
|
nBuildFontAtlas(atlas.ptr, extraFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void nBuildFontAtlas(long atlasPtr, int extraFlags); /*
|
||||||
|
ImGuiFreeType::BuildFontAtlas((ImFontAtlas*)atlasPtr, (unsigned int)extraFlags);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hinting greatly impacts visuals (and glyph sizes).
|
||||||
|
* When disabled, FreeType generates blurrier glyphs, more or less matches the stb's output.
|
||||||
|
* The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
|
||||||
|
* The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
|
||||||
|
* <p>
|
||||||
|
* You can set those flags on a per font basis in ImFontConfig::RasterizerFlags.
|
||||||
|
* Use the 'extra_flags' parameter of BuildFontAtlas() to force a flag on all your fonts.
|
||||||
|
*/
|
||||||
|
public static final class RasterizerFlags {
|
||||||
|
/**
|
||||||
|
* By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
|
||||||
|
* Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
|
||||||
|
*/
|
||||||
|
public static final int NoHinting = 1;
|
||||||
|
/**
|
||||||
|
* Disable auto-hinter.
|
||||||
|
*/
|
||||||
|
public static final int NoAutoHint = 1 << 1;
|
||||||
|
/**
|
||||||
|
* Indicates that the auto-hinter is preferred over the font's native hinter.
|
||||||
|
*/
|
||||||
|
public static final int ForceAutoHint = 1 << 2;
|
||||||
|
/**
|
||||||
|
* A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape.
|
||||||
|
* This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis),
|
||||||
|
* as is done by Microsoft's ClearType and Adobe's proprietary font renderer.
|
||||||
|
* This preserves inter-glyph spacing in horizontal text.
|
||||||
|
*/
|
||||||
|
public static final int LightHinting = 1 << 3;
|
||||||
|
/**
|
||||||
|
* Strong hinting algorithm that should only be used for monochrome output.
|
||||||
|
*/
|
||||||
|
public static final int MonoHinting = 1 << 4;
|
||||||
|
/**
|
||||||
|
* Styling: Should we artificially embolden the font?
|
||||||
|
*/
|
||||||
|
public static final int Bold = 1 << 5;
|
||||||
|
/**
|
||||||
|
* Styling: Should we slant the font, emulating italic style?
|
||||||
|
*/
|
||||||
|
public static final int Oblique = 1 << 6;
|
||||||
|
/**
|
||||||
|
* Disable anti-aliasing. Combine this with MonoHinting for best results!
|
||||||
|
*/
|
||||||
|
public static final int Monochrome = 1 << 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import imgui.ImFontAtlas;
|
import imgui.ImFontAtlas;
|
||||||
import imgui.ImFontConfig;
|
import imgui.ImFontConfig;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
import imgui.ImGuiFreeType;
|
||||||
import imgui.ImGuiIO;
|
import imgui.ImGuiIO;
|
||||||
import imgui.callbacks.ImStrConsumer;
|
import imgui.callbacks.ImStrConsumer;
|
||||||
import imgui.callbacks.ImStrSupplier;
|
import imgui.callbacks.ImStrSupplier;
|
||||||
@@ -262,7 +263,7 @@ public final class ImGuiGlfwExample {
|
|||||||
// ------------------------------
|
// ------------------------------
|
||||||
// Fonts from file/memory example
|
// Fonts from file/memory example
|
||||||
|
|
||||||
fontConfig.setRasterizerMultiply(1.2f); // This will make fonts a bit more readable
|
// fontConfig.setRasterizerMultiply(1.2f); // This will make fonts a bit more readable
|
||||||
|
|
||||||
// We can add new fonts directly from file
|
// We can add new fonts directly from file
|
||||||
fontAtlas.addFontFromFileTTF("src/test/resources/DroidSans.ttf", 13, fontConfig);
|
fontAtlas.addFontFromFileTTF("src/test/resources/DroidSans.ttf", 13, fontConfig);
|
||||||
@@ -276,6 +277,8 @@ public final class ImGuiGlfwExample {
|
|||||||
|
|
||||||
fontConfig.destroy(); // After all fonts were added we don't need this config more
|
fontConfig.destroy(); // After all fonts were added we don't need this config more
|
||||||
|
|
||||||
|
ImGuiFreeType.buildFontAtlas(fontAtlas, ImGuiFreeType.RasterizerFlags.LightHinting);
|
||||||
|
|
||||||
// Method initializes LWJGL3 renderer.
|
// Method initializes LWJGL3 renderer.
|
||||||
// This method SHOULD be called after you've initialized your ImGui configuration (fonts and so on).
|
// This method SHOULD be called after you've initialized your ImGui configuration (fonts and so on).
|
||||||
// ImGui context should be created as well.
|
// ImGui context should be created as well.
|
||||||
|
|||||||
Reference in new issue
Block a user