Skip to content

Commit

Permalink
gl.use_default_font_shader
Browse files Browse the repository at this point in the history
aardappel committed Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8906088 commit e7451ea
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions dev/src/font.cpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ map<string, OutlineFont *, less<>> loadedfaces;
OutlineFont *curface = nullptr;
string curfacename;

extern Shader *currentshader;
Shader *texturedshader = nullptr;

void CullFonts() {
@@ -56,6 +57,10 @@ void FontCleanup() {
FTClosedown();
}

void SetDefaultFontShader() {
texturedshader = LookupShader("textured");
}

void AddFont(NativeRegistry &nfr) {

nfr("set_font_name", "filename", "S", "B",
@@ -70,8 +75,7 @@ nfr("set_font_name", "filename", "S", "B",
curfacename = piname;
return Value(true);
}
texturedshader = LookupShader("textured");
assert(texturedshader);
SetDefaultFontShader();
curface = LoadFont(piname);
if (curface) {
curfacename = piname;
@@ -143,7 +147,8 @@ nfr("text", "text", "S", "Sb",
otransforms.append_object2view(scaling(curfontsize / float(maxfontsize)));
}
SetTexture(0, f->tex);
texturedshader->Set();
if (texturedshader) texturedshader->Set();
else currentshader->Set();
f->RenderText(s.sval()->strv());
if (curfontsize > maxfontsize) {
otransforms.pop();
@@ -176,4 +181,17 @@ nfr("get_char_code", "name", "S", "I",
return Value(curface ? curface->GetCharCode(n.sval()->strvnt()) : 0);
});

nfr("use_default_font_shader", "on", "B", "",
"by default set_font_name sets the use of the \"textured\" shader."
" With this function you can turn that on/off to use a current shader instead.",
[](StackPtr &, VM &vm, Value &on) {
extern void TestGL(VM &vm); TestGL(vm);
if (on.True()) {
SetDefaultFontShader();
} else {
texturedshader = nullptr;
}
return NilVal();
});

} // AddFont

0 comments on commit e7451ea

Please sign in to comment.