Commit graph

53 commits

Author SHA1 Message Date
Vladislav Belov
e8a5103f8c
Fixes #8057 by properly initializing atlas texture.
Fixes #8057
Fixes #8184
Fixes #8345
2025-09-17 14:31:16 +02:00
trompetin17
7027655864
Fix clipping logic in PutString to properly handle vertical boundaries
This commit enable "contains" or "intersects" to be visible instead of
hide.
2025-09-13 09:58:27 -05:00
trompetin17
690838e3dc
Add [locale] inline tag for per-locale fonts
New `[locale='xx']...[/locale]` markup lets GUI text sections render
with a locale-specific font (e.g. CJK) while the rest of the caption
keeps the current game font.

guiObject.caption = "Hello [locale='ja']世界[/locale], how do you
[locale='zh']感覺[/locale]" This is ideal for language pickers and
similar UI where you want the language name shown in its own script.

This commit unlocks richer, self-explanatory international UI while
keeping the legacy text behaviour unchanged.
2025-08-04 09:35:41 -05:00
trompetin17
47454a592e
Fix casing for debug box configuration keys in default.cfg and TextRenderer.cpp 2025-08-04 07:44:12 -05:00
Ralph Sennhauser
8398f1baf4
Fix some includes in source/graphics
Make include-what-you-use happy with some files in source/graphics and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-20 17:28:48 +02:00
Ralph Sennhauser
a03268ebae
Drop header lib/posix/posix_errno.h
Does only include <errno.h> with the exception on Windows but only if
not using MSVC and even then depends on whether boost is included first
or not.

Use <cerrno> which was added in C++11 and is based of of Posix instead
of a particular cerrno.h of a particular C library.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-15 19:42:34 +02:00
Ralph Sennhauser
58219b974c
Fix trailing whitespace and add pre-commit hook
Some have their editor configured to remove trailing whitespace and
editing such a file would "fix" it, adding an unrelated change.

Fix whitespace violations excluding third party libs and generated files
like glad or patches.

Enable pre-commit hook trailing-whitespace to enforce it in the future.

Fixes: #8016
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-15 20:08:48 +02:00
trompetin17
d323797d98
Add glyph debug box rendering for font system
This commit introduces optional debugging visuals for font glyph
rendering. When enabled, each glyph is drawn with a surrounding debug
box to aid in visual inspection of glyph layout, spacing, and atlas
behavior.

Usage examples (via console):

// Enable debug box rendering
Engine.ConfigDB_CreateValue("user","fonts.debugBox", true);

// Set debug box color (R G B)
Engine.ConfigDB_CreateValue("user","fonts.debugBoxColor", "35 0 35");

This feature is intended for developers working on font layout or atlas
generation logic, and has no effect on normal gameplay or UI rendering
when disabled.
2025-05-29 06:23:20 -05:00
trompetin17
e024f5c88b
Fix blurry text by aligning glyph positions
Text rendering appeared blurry due to subpixel positioning when using
LINEAR filtering. Replaced glyph position calculation with std::ceilf()
to ensure integer-aligned drawing coordinates and crisper text.
2025-05-27 21:30:57 -05:00
trompetin17
bdd94bd264
Add font engine aware of Gui.scale
This commit enhances text rendering by leveraging FreeType and a dynamic
font atlas. Previously, GUI scaling relied on bitmap fonts, which led to
blurry and distorted text when scaling up. Now, we scale the font size
directly using FreeType, resulting in much sharper and more readable
text at any GUI scale.

Key improvements:
- Replaced bitmap font scaling with true font size scaling via FreeType.
- Reduced glyph cache dependency on fixed positions, relying on shader
  scaling instead.
- Switched to float-based glyph positioning for more accurate rendering
  and scaling.

These changes ensure clean and consistent text appearance across
different GUI scales.
2025-05-26 13:12:47 -05:00
trompetin17
734386ce9f
Use freetype for font rendering
Replace premade bitmap fonts with FreeType2 and dynamic texture atlas.

Switched from static, premade bitmap fonts to runtime-generated glyphs using FreeType2.
Glyphs are rendered on demand into a dynamic texture atlas, improving scalability,
font quality, and support for internationalization.

Currently using RGBA format for compatibility across all render
paths while initial support for R8_UNORM is being added.
This prepares for future optimizations in VRAM and performance

Includes groundwork for gamma-corrected blending and future swizzling support.
2025-05-16 14:57:59 -05:00
vladislavbelov
ffc4a56b9f Revert non-ASCII characters from source and configuration files introduced in 157c6af18e.
Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185
This was SVN commit r27965.
2023-12-03 00:30:12 +00:00
bb
157c6af18e Make the space in 0 A.D. non-breaking throughout the codebase.
Avoid cases of filenames
Update years in terms and other legal(ish) documents
Don't update years in license headers, since change is not meaningful

Will add linter rule in seperate commit

Happy recompiling everyone!

Original Patch By: Nescio
Comment By: Gallaecio
Differential Revision: D2620
This was SVN commit r27786.
2023-07-27 20:54:46 +00:00
vladislavbelov
a311539ec9 Reduces the number of SetVertexAttributeFormat calls in Canvas2D.
This was SVN commit r27138.
2022-10-09 12:21:26 +00:00
vladislavbelov
dffde00e5f Reduces uniforms sizes for the Canvas2D shader.
Differential Revision: https://code.wildfiregames.com/D4796
This was SVN commit r27136.
2022-10-09 10:44:51 +00:00
vladislavbelov
a6f60afdc5 Adds instancing support to backend and enables it for minimap.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4650
This was SVN commit r26901.
2022-05-24 07:11:23 +00:00
vladislavbelov
62e589ab76 Adds renderer backend interface and dummy backend.
Comments By: phosit, Stan
Tested By: Langbart, phosit
Differential Revision: https://code.wildfiregames.com/D4636
This was SVN commit r26858.
2022-05-08 22:02:46 +00:00
vladislavbelov
3ed4eaf247 Removes ogl_WarnIfError from regular renderer code.
This was SVN commit r26850.
2022-05-02 21:52:21 +00:00
vladislavbelov
04bd96cee0 Moves uniform and texture binding to CDeviceCommandContext.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4631
This was SVN commit r26848.
2022-05-02 20:57:22 +00:00
vladislavbelov
aba7a170d9 Moves vertex attribute binding to CDeviceCommandContext.
Tested By: Langbart, Stan
Differential Revision: https://code.wildfiregames.com/D4610
This was SVN commit r26815.
2022-04-23 20:11:14 +00:00
vladislavbelov
b4253d48cb Moves CShaderProgram to backend and handling via CDeviceCommandContext.
Differential Revision: https://code.wildfiregames.com/D4548
This was SVN commit r26652.
2022-03-14 22:16:14 +00:00
vladislavbelov
647fccd410 Replaces native GL types by backend format in vertex attributes in CShaderProgram.
This was SVN commit r26594.
2022-03-07 02:21:05 +00:00
vladislavbelov
3a4bbd11fd Moves all GL draw commands to CDeviceCommandContext.
Differential Revision: https://code.wildfiregames.com/D4518
This was SVN commit r26525.
2022-03-03 07:09:59 +00:00
vladislavbelov
8a63adc40d Uses CDeviceCommandContext as an input parameter for CCanvas2D.
This was SVN commit r26480.
2022-02-25 08:14:11 +00:00
vladislavbelov
4de89c3db1 Moves texture management to CDeviceCommandContext, adds quality options.
Comments By: nwtour, Stan
Tested By: nwtour, Stan
Differential Revision: https://code.wildfiregames.com/D4488
This was SVN commit r26365.
2022-02-13 19:30:28 +00:00
vladislavbelov
990d61a74a Draws all characters for a very long text of the same style.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4120
This was SVN commit r25749.
2021-06-08 18:17:10 +00:00
vladislavbelov
83608c9205 Removes complex transform from TextRenderer.
This was SVN commit r25648.
2021-06-02 22:16:09 +00:00
vladislavbelov
2d455df18d Removes Z value from TextRenderer translate, renames TextRenderer methods to more explicit ones.
This was SVN commit r25645.
2021-06-02 21:21:28 +00:00
vladislavbelov
2cc671fd36 Makes 2D text drawing via Canvas2D.
This was SVN commit r25607.
2021-05-30 19:10:10 +00:00
vladislavbelov
7f16a5c40c Moves TextRenderer shader to a more relevant place, into the rendering function argument.
This was SVN commit r25606.
2021-05-30 18:28:06 +00:00
wraitii
0c23e595fa Include CStrInternStatic where necessary only.
This makes incremental recompilation faster when changing static
interned strings.

Differential Revision: https://code.wildfiregames.com/D3975
This was SVN commit r25457.
2021-05-18 11:09:54 +00:00
vladislavbelov
63e0f13f1b Reduces the number of GL state changes in GUI.
This was SVN commit r24885.
2021-02-11 19:15:35 +00:00
wraitii
369c2e8801 Further header & precompiled cleanup, fix no-PCH builds.
GUIObjectBase is made a IGUIObject* to avoid including those headers
un-necessarily. Subsequent diffs ought to clean up the various of
pointers for that with a similar type with reference semantics.

Also:
- Add standard C and C++ headers (mostly cstring for memcpy, string and
vector) where needed.
- Swap out some includes for forward declarations
- Clean up un-necessary boost includes in precompiled and other headers.
- Clean up precompiled headers, including fewer things.
- Move ACPI to the windows-specific folder as it's included there only
and mostly specific to that platform.

Thanks Stan for the testing.

Differential Revision: https://code.wildfiregames.com/D3129
This was SVN commit r24352.
2020-12-09 14:39:14 +00:00
Itms
cc67d54aeb Fix compiler warnings on VS 2015, refs #3439, refs #5069.
Patch By: Stan
Reviewed By: Itms, vladislavbelov
Differential Revision: https://code.wildfiregames.com/D1262
This was SVN commit r21480.
2018-03-10 09:58:53 +00:00
Imarok
b94a54b18a Use direct gui.scale instead of reciprocal gui.scale
Patch by Dariost.

Differential Revision: https://code.wildfiregames.com/D328
This was SVN commit r19774.
2017-06-14 17:13:44 +00:00
Ykkrosh
e06a7b37d8 Convert debug_printf to take UTF-8 strings instead of wchar_t.
This fixes the problem where passing a non-ASCII string to
debug_printf(L"%hs", s) caused vswprintf_s to fail on Linux (because it
doesn't know what encoding the char* is meant to have). Now debug
messages will remain as UTF-8 until they reach the OS.

Fixes #3021.

This was SVN commit r16332.
2015-02-14 01:45:13 +00:00
Ykkrosh
59503b9ae9 Add basic support for GUI scaling factor, to help with high-res displays (e.g. 4K monitors and 1080p tablets).
Use the config setting "gui.scale = 0.5" to make the GUI bigger.

This was SVN commit r16223.
2015-01-24 20:06:37 +00:00
Ykkrosh
dcf5a2667f CLogger: Use cppformat instead of sys_vswprintf.
sys_vswprintf relies on platform-specific printf implementations, which
vary widely between platforms (in handling of truncation, return values,
use of %s/%S/%hs/%ls for mixing char and wchar_t strings, etc) and are
therefore a pain.

Use cppformat's fmt::sprintf instead, which has very similar syntax to
sprintf but is more C++ish and is portable.

Also, wchar_t is stupid, so use char* strings (which are expected to be
UTF-8) in CLogger. This creates a bit of a pain with changing all
callers to convert to char* strings, but that's their fault for not
using UTF-8 already.

Refs #3011.

This was SVN commit r16182.
2015-01-22 20:30:05 +00:00
Ykkrosh
30e851ab90 Forward-declare CShaderProgramPtr, to avoid pulling in more headers than necessary and to hypothetically reduce build times by a minuscule amount.
This was SVN commit r15481.
2014-07-02 22:36:45 +00:00
historic_bruno
b1c081e36d Set svn:eol-style=native, fix some inconsistent line endings
This was SVN commit r14299.
2013-12-06 00:42:50 +00:00
Ykkrosh
701508922f Use CStrIntern for font names to reduce lookup cost
This was SVN commit r14020.
2013-10-18 16:15:42 +00:00
Ykkrosh
91169c82c7 Optimise rendering of scrollable text boxes by clipping
Add optional clipping rectangle to CTextRenderer. Strings that are
printed
outside the vertical extent of the clipping rectangle will be
immediately
skipped. This greatly reduces the cost of large scrollable text boxes.

This was SVN commit r14019.
2013-10-18 16:05:02 +00:00
Ykkrosh
751558d894 Optimise text rendering by batching
When CTextRenderer is given multiple strings with no differences other
than position, render them in a single glDrawElements call to reduce
driver overhead.

Also avoid some unnecessary copies of std::wstrings.

This helps performance a bit with large GUI text boxes.

This was SVN commit r14018.
2013-10-18 16:02:48 +00:00
Ykkrosh
b6c7c0d799 Optimise glyph lookup in text renderer
std::map lookup was a major cost when rendering large amounts of text.
Replace it with a more efficient 2-level array.

This was SVN commit r14017.
2013-10-18 15:56:12 +00:00
Ykkrosh
5778484a77 Refactor text renderer
Replace unifont with CFont and CFontManager, since the h_mgr interface
was
needlessly inconvenient.

Load the font textures through CTextureManager, to support dynamic
reloading (e.g. when resetting GL state - see #741).

Add CFontMetrics as a convenient wrapper for code that just wants to
measure text.

Fixes #1117.

This was SVN commit r14016.
2013-10-18 15:53:07 +00:00
Ykkrosh
994ebd9836 Add a list of statically-constructed CStrIntern strings
Switch all the constant strings in graphics code to use the new
variables.
This avoids the cost of instantiating CStrInterns at runtime every
frame.

This was SVN commit r13906.
2013-09-29 13:19:52 +00:00
Ykkrosh
c888c00377 Avoid unnecessary use of printf in text renderer.
This was SVN commit r11154.
2012-02-25 17:14:47 +00:00
Ykkrosh
832a51da80 GLSL text support
This was SVN commit r11080.
2012-02-15 21:53:13 +00:00
Ykkrosh
531b40578a More GLES compatibility.
Add config option to disable hardware cursors on Windows.

This was SVN commit r11053.
2012-02-12 20:45:31 +00:00
Ykkrosh
db85833655 More GLES compatibility.
Move more rendering code to shader API.

This was SVN commit r11050.
2012-02-12 13:20:49 +00:00