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...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
* VRAM (put font on VRAM and draw from there; slower to initialize, quicker to draw), | * VRAM (put font on VRAM and draw from there; slower to initialize, quicker to draw), | ||
* Sprite (draw text using sprites). | * Sprite (draw text using sprites). | ||
+ | |||
+ | 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> | ||
+ | |||
+ | 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"); | ||
+ | |||
+ | Print_SetVRAMFont(g_Font_MGL_Sample6, 212, COLOR_WHITE); | ||
+ | Print_SetPosition(100, 150); // Position in pixel unit | ||
+ | Print_DrawText("VRAM mode"); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | 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> |
Latest revision as of 20:58, 7 January 2024
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 set for tiled-based screen modes),
- Bitmap (draw text from RAM to VRAM for bitmap screen modes),
- Bitmap with transparency.
- VRAM (put font on VRAM and draw from there; slower to initialize, quicker to draw),
- Sprite (draw text using sprites).
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");
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"); Print_SetVRAMFont(g_Font_MGL_Sample6, 212, COLOR_WHITE); Print_SetPosition(100, 150); // Position in pixel unit Print_DrawText("VRAM mode");
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");