Bonjour

Je voudrais avec mon application créer des bitmap fonts, c'est à dire des textures contenant tous les caractères d'une police donnée.

Tout marche très bien, à part que je n'arrive pas à charger la police que je veux, c'est toujours la même qui apparaît sur la texture créée. Pourtant CreateFont ne renvoie pas d'erreur, tout comme les autres fonctions utilisées d'ailleurs. Ce qui est encore plus étonnant c'est que j'ai repris ce code d'une appli qui fait la même chose, et dans cette appli ça marche très bien.
Je ne suis pas un pro du développement Win32, alors je suppose que quelque chose m'a echappé.

Voilà mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
string FontName = "Arial";

unsigned char* Data = NULL;
BITMAPINFO BitmapInfo;
memset(&BitmapInfo, 0, sizeof(BITMAPINFO));
BitmapInfo.bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth    = 256;
BitmapInfo.bmiHeader.biHeight   = 256;
BitmapInfo.bmiHeader.biBitCount = 24;
BitmapInfo.bmiHeader.biPlanes   = 1;

HDC     Hdc          = CreateCompatibleDC(NULL);
HBITMAP BitmapHandle = CreateDIBSection&#40;Hdc, &BitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>&#40;&Data&#41;, NULL, 0&#41;;
HFONT   FontHandle   = CreateFont&#40;16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, FontName.c_str&#40;&#41;&#41;;

SelectObject&#40;Hdc, BitmapHandle&#41;;
SelectObject&#40;Hdc, FontHandle&#41;;
SetBkColor&#40;Hdc, RGB&#40;0, 0, 0&#41;&#41;;
SetTextColor&#40;Hdc, RGB&#40;255, 255, 255&#41;&#41;;

char Character = 0;
for &#40;int j = 0; j < 16; ++j&#41;
&#123;
    for &#40;int i = 0; i < 16; ++i, Character++&#41;
    &#123;
        RECT Rect = &#123;i * 16, j * 16, &#40;i + 1&#41; * 16, &#40;j + 1&#41; * 16&#125;;
        DrawText&#40;Hdc, &Character, 1, &Rect, DT_LEFT&#41;;
    &#125;
&#125;

// Création de la texture à partir des pixels pointés par Data
// ...

DeleteObject&#40;FontHandle&#41;;
DeleteObject&#40;BitmapHandle&#41;;
DeleteDC&#40;Hdc&#41;;
Merci !