-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from scenerygraphics/font-fixes
* `FontBoard` has been renamed to `TextBoard` * fixes signed distance field font rendering for both OpenGL and Vulkan (though it could need a bit more polishing for better filtering, etc) * introduces a GPU compatibility matrix in the README * if `TextBoard.fontFamily` contains a dot (e.g. "SourceSans.ttf"), the corresponding TTF font file will be searched for in the classpath and loaded; if it cannot be found, the system default font will be used * Kotlin has been bumped to 1.1.60 * when running OpenGLRenderer on a Retina display, `Renderer.SupersamplingFactor` will be set to 0.5 to improve performance
- Loading branch information
Showing
21 changed files
with
363 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package graphics.scenery | ||
|
||
import cleargl.GLVector | ||
|
||
/** | ||
* TextBoard is a possibly billboarded display of a string of text, | ||
* rendered using signed-distance fields. | ||
* | ||
* @author Ulrik Günther <hello@ulrik.is> | ||
* @property[font] Name of the font to use for this text board | ||
* @property[isBillboard] Whether the board should be billboarded or not | ||
* | ||
* @constructor Returns a TextBoard instance, with [fontFamily] and a declared [ShaderMaterial] | ||
*/ | ||
class TextBoard(font: String = "SourceSansPro-Regular.ttf", override var isBillboard: Boolean = false) : Mesh() { | ||
|
||
/** The text displayed on this font board */ | ||
var text: String = "" | ||
set(value) { | ||
dirty = true | ||
field = value | ||
} | ||
|
||
/** The font family of this font board. If reset, this will set the [dirty] flag, | ||
* such that the renderer can recreate the signed-distance fields used for displaying. | ||
* | ||
* If the name contains a dot (e.g. as in "Helvetica.ttf"), scenery will attempt to load | ||
* the font as a file from the class path. | ||
*/ | ||
var fontFamily: String = "SourceSansPro-Regular.ttf" | ||
set(value) { | ||
dirty = true | ||
field = value | ||
} | ||
|
||
/** The [ShaderProperty] storing whether the font board should be renderer transparently. */ | ||
@ShaderProperty var transparent: Int = 1 | ||
/** [ShaderProperty] to store the size of the used texture atlas storing the font's signed distance field */ | ||
@ShaderProperty var atlasSize = GLVector(1024.0f, 1024.0f, 0.0f, 0.0f) | ||
/** The [ShaderProperty] storing the font's color. */ | ||
@ShaderProperty var fontColor: GLVector = GLVector(0.5f, 0.5f, 0.5f, 1.0f) | ||
/** The [ShaderProperty] storing the background color of the font board, | ||
* used only if [transparent] is 0. */ | ||
@ShaderProperty var backgroundColor: GLVector = GLVector(1.0f, 1.0f, 1.0f, 1.0f) | ||
|
||
init { | ||
name = "TextBoard" | ||
fontFamily = font | ||
material = ShaderMaterial(arrayListOf("DefaultForward.vert", "TextBoard.frag")) | ||
material.blending.transparent = true | ||
material.blending.sourceColorBlendFactor = Blending.BlendFactor.One | ||
material.blending.destinationColorBlendFactor = Blending.BlendFactor.OneMinusSrcAlpha | ||
material.blending.sourceAlphaBlendFactor = Blending.BlendFactor.One | ||
material.blending.destinationAlphaBlendFactor = Blending.BlendFactor.Zero | ||
material.blending.colorBlending = Blending.BlendOp.add | ||
material.blending.alphaBlending = Blending.BlendOp.add | ||
} | ||
|
||
/** Stringify the font board. Returns [fontFamily] used as well as the [text]. */ | ||
override fun toString(): String { | ||
return "TextBoard ($fontFamily): $text" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.