Урок 4. Растрові шрифти | Participants
|
- Statistics
- Participants
- Translate into Ukrainian
- Translation result
- 24% translated in draft.
If you do not want to register an account, you can sign in with OpenID.
Lesson 4: Bitmap Fonts | ||
Hi all! This lesson is about drawing bitmap fonts on a surface in SDL. They are called bitmap fonts because our fonts will be stored in one big bitmap that contains all of them. Here's what one of our font map looks like: | Привіт всім! Цей урок присвячений виводу растрових шрифтів на поверхні SDL. Вони так називаються тому, що наші шрифти будуть зберігатися в одному великому зображенні. Ось приклад наших растрових шрифтів: | |
Our font system will consist of 2 files: font.cpp and font.h. The lesson itself will also have the file lesson4.cpp. I decided to put the font routines into seperate files because this way it's much easier to use the same code in many programs - just copy the 2 files to your new project, add an '#include "font.h"' line and you're all set. | Наш шрифтовий двигун складатиметься з двох файлів: font.cpp і font.h. В уроці також буде міститись файл lesson4.cpp. Я вирішив виділити функції для роботи з шрифтом в окремих файлах. Це набагато простіше у використанні і цей самий код можливо буде використовувати в багатьох програмах - просто скопіювавши 2 файли в новий проект, та додати рядок '#include "font.h"'. | |
Note: I won't talk about what code goes into which file. You can put all the code into one big file if you want (if you like to follow this tutorial while coding your font routines). I will only talk about the functions. If you want to look at the code in many files, look at the source. Also this code could really easilly be put into a class. I won't use classes this time. | Примітка: Я не буду говорити, як розподілив код між файлами. Ви можете помістити весь код в один великий файл, якщо хочете (ви можете притримуватись цього керівництва, поки програмуєте власну шрифтову процедуру). Я буду говорити лише про функції. Якщо ви хочете подивитися як код розбитий на багато файлів, подивіться на вихідники. Також цей код можна легко помістити в клас. Я не буду використовувати класи на цей раз. | |
All our fonts will be stored inside one structure called SDLFont. It looks like this: | Всі наші шрифти будуть зберігається всередині однієї структури, яка називається SDLFont. Виглядає це приблизно так: | |
// Structure to hold our font | ||
struct SDLFont | ||
{ | ||
SDL_Surface *font; // The SDL Surface for the font image | SDL_Surface *font; // вказівник SDL для зберігання зображення шрифта | |
int width; // Width of the SDL Surface (=height) | int width; // ширина зображеня (таке ж як і довжина) | |
int charWidth; // Width of one block character in the font | int charWidth; // ширина одного символа у шрифті (таке ж як і довжина) | |
int *widths; // Real widths of all the fonts | ||
unsigned char *data; // The raw font data | ||
}; | ||
The SDL_Structure font will hold the font image map. Width is the width of the font (for easy access) and since the font image is a square, the width = height. charWidth is the with of one "character cell" on the font (width/16). Since mostly all of the characters in the font have different real widths, then the array widths will hold the widths of all the characters. Data will hold the raw image data for the SDL_Surface. | ||
Now here's one function that you should remember from the previous lessons (if you have read them). It simply blits one part of a surface onto an other part of some other surface. It will be used when drawing the font. |
