-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_font_loading.bas
66 lines (47 loc) · 2.52 KB
/
example_font_loading.bas
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
' raylib [text] example - Font loading
'$INCLUDE:'include/raylib.bi'
' Initialization
'--------------------------------------------------------------------------------------
CONST screenWidth = 800
CONST screenHeight = 450
InitWindow screenWidth, screenHeight, "raylib [text] example - font loading"
' Define characters to draw
CONST msg = "~!@#$%^&*()_+QWERTYUIOP{}|" + CHR$(10) + "ASDFGHJKL:" + CHR$(34) + "ZXCVBNM<>?" + CHR$(10) + "`1234567890-=qwertyuiop[]\" + CHR$(10) + "asdfghjkl;'zxcvbnm,./"
' NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
' BMFont (AngelCode) : Font data and image atlas have been generated using external program
DIM AS RFont fontBm: RLoadFont "assets/font/pixantiqua.fnt", fontBm
' TTF font : Font data and atlas are generated directly from TTF
' NOTE: We define a font base size of 32 pixels tall and up-to 250 characters
DIM AS RFont fontTtf: LoadFontEx "assets/font/pixantiqua.ttf", 32, NULL, 250, fontTtf
DIM useTtf AS _BYTE, v AS Vector2: v.x = 20!: v.y = 100!
SetTargetFPS (60) ' Set our game to run at 60 frames-per-second
'--------------------------------------------------------------------------------------
' Main game loop
WHILE NOT WindowShouldClose ' Detect window close button or ESC key
' Update
'----------------------------------------------------------------------------------
IF IsKeyDown(KEY_SPACE) THEN useTtf = TRUE ELSE useTtf = FALSE
'----------------------------------------------------------------------------------
' Draw
'----------------------------------------------------------------------------------
BeginDrawing
ClearBackground (RAYWHITE)
DrawText "Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY
IF NOT useTtf THEN
DrawTextEx fontBm, msg, v, fontBm.baseSize, 2, MAROON
DrawText "Using BMFont (Angelcode) imported", 20, GetScreenHeight - 30, 20, GRAY
ELSE
DrawTextEx fontTtf, msg, v, fontTtf.baseSize, 2, LIME
DrawText "Using TTF font generated", 20, GetScreenHeight - 30, 20, GRAY
END IF
EndDrawing
'----------------------------------------------------------------------------------
WEND
' De-Initialization
'--------------------------------------------------------------------------------------
UnloadFont fontBm ' AngelCode Font unloading
UnloadFont fontTtf ' TTF Font unloading
CloseWindow ' Close window and OpenGL context
'--------------------------------------------------------------------------------------
SYSTEM
'$INCLUDE:'include/raylib.bas'