Difference between revisions of "Modules/print/Usage"
From MSX Game Library
(Created page with "Use of this module begins with the initialization of a font. Then you can use all the functions to display text. You have several render mode: * Text (using tiles/characters...") |
|||
| (13 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | Use of this module begins with the initialization of a font. Then you can use all the functions to | + | Use of this module begins with the initialization of a font. Then you can use all the functions to draw text on screen. |
| − | You have several render mode: | + | === Modes === |
| − | * | + | You have several font render modes. |
| − | * Bitmap (draw | + | |
| − | + | ==== Text ==== | |
| − | + | Draw characters as pattern names (text mode). | |
| − | * | + | |
| + | Requirement: | ||
| + | * Compatible with tiled-based screen modes: Screen 0 (40/80 columns), 1, 2 and 4. | ||
| + | * You need to activate {{C|PRINT_USE_TEXT}} compile option in your library configuration ({{C|msxgl_config.h}}). | ||
| + | |||
| + | Example using tile-based render mode: | ||
| + | <syntaxhighlight lang="c"> | ||
| + | #include "font/font_mgl_sample8.h" | ||
| + | |||
| + | VDP_SetMode(VDP_MODE_SCREEN1); // Initialize screen mode 1 (tiled-base mode) | ||
| + | Print_SetTextFont(g_Font_MGL_Sample8, 1); // Upload font tile-set from index 1 | ||
| + | Print_SetPosition(10, 10); // Position in tile grid unit | ||
| + | Print_DrawText("Text mode"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Bitmap ==== | ||
| + | Draw characters from RAM (real-time unpack font data and draw it). | ||
| + | |||
| + | Requirement: | ||
| + | * Compatible with bitmap-based screen modes: Screen 5 to 8. | ||
| + | * You need to activate {{C|PRINT_USE_BITMAP}} or {{C|PRINT_USE_VRAM}} compile option in your library configuration ({{C|msxgl_config.h}}). | ||
| + | |||
| + | Example using bitmap render mode for MSX2: | ||
| + | <syntaxhighlight lang="c"> | ||
| + | #include "font/font_mgl_sample6.h" | ||
| + | |||
| + | VDP_SetMode(VDP_MODE_SCREEN5); // Initialize screen mode 5 (bitmap mode) | ||
| + | Print_SetBitmapFont(g_Font_MGL_Sample6); // Initialize bitmap font | ||
| + | Print_SetOutline(TRUE, COLOR_GRAY); // Set outline effect | ||
| + | Print_SetPosition(100, 100); // Position in pixel unit | ||
| + | Print_DrawText("Bitmap mode"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Bitmap with transparency ==== | ||
| + | Draw characters from RAM with transparency (real-time unpack font data and draw it). | ||
| + | |||
| + | Same mode than Bitmap but a little bit slower. | ||
| + | |||
| + | Can be activated using: | ||
| + | <syntaxhighlight lang="c"> | ||
| + | #include "font/font_mgl_sample6.h" | ||
| + | |||
| + | VDP_SetMode(VDP_MODE_SCREEN5); // Initialize screen mode 5 (bitmap mode) | ||
| + | Print_SetBitmapFont(g_Font_MGL_Sample6); // Initialize bitmap font | ||
| + | Print_SetMode(PRINT_MODE_BITMAP_TRANS); // Activate transparency | ||
| + | Print_SetPosition(100, 100); // Position in pixel unit | ||
| + | Print_DrawText("Bitmap mode with transparency"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== VRAM ==== | ||
| + | Draw characters from VRAM (font data is upack once in VRAM thne drawing is done by VRAM copy). | ||
| + | slower to initialize, far quicker to draw. | ||
| + | |||
| + | Requirement: | ||
| + | * Compatible with bitmap-based screen modes: Screen 5 to 8. | ||
| + | * You need to activate {{C|PRINT_USE_VRAM}} compile option in your library configuration ({{C|msxgl_config.h}}). | ||
| + | |||
| + | Example using bitmap render mode for MSX2: | ||
| + | <syntaxhighlight lang="c"> | ||
| + | #include "font/font_mgl_sample6.h" | ||
| + | |||
| + | Print_SetVRAMFont(g_Font_MGL_Sample6, 212, COLOR_WHITE); | ||
| + | Print_SetPosition(100, 150); // Position in pixel unit | ||
| + | Print_DrawText("VRAM mode"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Sprites ==== | ||
| + | Draw characters from sprites (load font data as sprite pattern in VRAM then display characters using sprite system). | ||
| + | |||
| + | Requirement: | ||
| + | * Compatible with all sprite enabled screen modes: | ||
| + | ** Screen 1 to 3 (4 sprites per line), | ||
| + | ** Screen 4 to 8 (8 sprites per line), | ||
| + | * You need to activate {{C|PRINT_USE_SPRITE}} compile option in your library configuration ({{C|msxgl_config.h}}). | ||
| + | |||
| + | Example using sprite render mode: | ||
| + | <syntaxhighlight lang="c"> | ||
| + | #include "font/font_mgl_sample8.h" | ||
| + | |||
| + | VDP_SetMode(VDP_MODE_SCREEN1); // Initialize screen mode 1 (tiled-base mode) | ||
| + | Print_SetSpriteFont(g_Font_MGL_Sample8, 0, 0); | ||
| + | Print_SetPosition(100, 50); // Position in pixel unit | ||
| + | Print_DrawText("SPRT"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | === Font modes compatibility matrix === | ||
| + | |||
| + | {| class="wikitable" | ||
| + | !rowspan="2"| Font mode | ||
| + | !colspan="11"| Screen modes | ||
| + | |- | ||
| + | ! 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 10 || 12 | ||
| + | |- | ||
| + | | Text || ✔️ || ✔️ || ✔️ || ❌ || ✔️ || ❌ || ❌ || ❌ || ❌ || ❌ || ❌ | ||
| + | |- | ||
| + | | Bitmap|| ❌ || ❌ || ❌ || ❌ || ❌ || ✔️ || ✔️ || ✔️ || ✔️ || ❔ || ❔ | ||
| + | |- | ||
| + | | VRAM || ❌ || ❌ || ❌ || ❌ || ❌ || ✔️ || ✔️ || ✔️ || ✔️ || ❔ || ❔ | ||
| + | |- | ||
| + | | Sprites || ❌ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ || ✔️ | ||
| + | |} | ||
Latest revision as of 18:39, 13 January 2025
Use of this module begins with the initialization of a font. Then you can use all the functions to draw text on screen.
Contents
Modes
You have several font render modes.
Text
Draw characters as pattern names (text mode).
Requirement:
- Compatible with tiled-based screen modes: Screen 0 (40/80 columns), 1, 2 and 4.
- You need to activate PRINT_USE_TEXT compile option in your library configuration (msxgl_config.h).
Example using tile-based render mode:
#include "font/font_mgl_sample8.h"
VDP_SetMode(VDP_MODE_SCREEN1); // Initialize screen mode 1 (tiled-base mode)
Print_SetTextFont(g_Font_MGL_Sample8, 1); // Upload font tile-set from index 1
Print_SetPosition(10, 10); // Position in tile grid unit
Print_DrawText("Text mode");
Bitmap
Draw characters from RAM (real-time unpack font data and draw it).
Requirement:
- Compatible with bitmap-based screen modes: Screen 5 to 8.
- You need to activate PRINT_USE_BITMAP or PRINT_USE_VRAM compile option in your library configuration (msxgl_config.h).
Example using bitmap render mode for MSX2:
#include "font/font_mgl_sample6.h"
VDP_SetMode(VDP_MODE_SCREEN5); // Initialize screen mode 5 (bitmap mode)
Print_SetBitmapFont(g_Font_MGL_Sample6); // Initialize bitmap font
Print_SetOutline(TRUE, COLOR_GRAY); // Set outline effect
Print_SetPosition(100, 100); // Position in pixel unit
Print_DrawText("Bitmap mode");
Bitmap with transparency
Draw characters from RAM with transparency (real-time unpack font data and draw it).
Same mode than Bitmap but a little bit slower.
Can be activated using:
#include "font/font_mgl_sample6.h"
VDP_SetMode(VDP_MODE_SCREEN5); // Initialize screen mode 5 (bitmap mode)
Print_SetBitmapFont(g_Font_MGL_Sample6); // Initialize bitmap font
Print_SetMode(PRINT_MODE_BITMAP_TRANS); // Activate transparency
Print_SetPosition(100, 100); // Position in pixel unit
Print_DrawText("Bitmap mode with transparency");
VRAM
Draw characters from VRAM (font data is upack once in VRAM thne drawing is done by VRAM copy). slower to initialize, far quicker to draw.
Requirement:
- Compatible with bitmap-based screen modes: Screen 5 to 8.
- You need to activate PRINT_USE_VRAM compile option in your library configuration (msxgl_config.h).
Example using bitmap render mode for MSX2:
#include "font/font_mgl_sample6.h"
Print_SetVRAMFont(g_Font_MGL_Sample6, 212, COLOR_WHITE);
Print_SetPosition(100, 150); // Position in pixel unit
Print_DrawText("VRAM mode");
Sprites
Draw characters from sprites (load font data as sprite pattern in VRAM then display characters using sprite system).
Requirement:
- Compatible with all sprite enabled screen modes:
- Screen 1 to 3 (4 sprites per line),
- Screen 4 to 8 (8 sprites per line),
- You need to activate PRINT_USE_SPRITE compile option in your library configuration (msxgl_config.h).
Example using sprite render mode:
#include "font/font_mgl_sample8.h"
VDP_SetMode(VDP_MODE_SCREEN1); // Initialize screen mode 1 (tiled-base mode)
Print_SetSpriteFont(g_Font_MGL_Sample8, 0, 0);
Print_SetPosition(100, 50); // Position in pixel unit
Print_DrawText("SPRT");
Font modes compatibility matrix
| Font mode | Screen modes | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 12 | |
| Text | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Bitmap | ❌ | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❔ | ❔ |
| VRAM | ❌ | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❔ | ❔ |
| Sprites | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |