Skip to content

Commit da04a3e

Browse files
committed
Added example.
1 parent 7630deb commit da04a3e

File tree

12 files changed

+99
-1
lines changed

12 files changed

+99
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $(TARGET): src/raylib.f90 src/raylib_util.f90
2121
$(FC) $(FFLAGS) -c src/raylib_util.f90
2222
$(AR) $(ARFLAGS) $(TARGET) raylib.o raylib_camera.o raylib_math.o raylib_util.o
2323

24-
examples: camera castle cubes flags fly keys map truck window
24+
examples: camera castle cubes flags fly font keys map truck window
2525

2626
camera: $(TARGET) examples/camera.f90
2727
$(FC) $(FFLAGS) $(LDFLAGS) -o camera examples/camera.f90 $(TARGET) $(LDLIBS)
@@ -38,6 +38,9 @@ flags: $(TARGET) examples/flags.f90
3838
fly: $(TARGET) examples/fly.f90
3939
$(FC) $(FFLAGS) $(LDFLAGS) -o fly examples/fly.f90 $(TARGET) $(LDLIBS)
4040

41+
font: $(TARGET) examples/font.f90
42+
$(FC) $(FFLAGS) $(LDFLAGS) -o font examples/font.f90 $(TARGET) $(LDLIBS)
43+
4144
keys: $(TARGET) examples/keys.f90
4245
$(FC) $(FFLAGS) $(LDFLAGS) -o keys examples/keys.f90 $(TARGET) $(LDLIBS)
4346

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ More examples can be found in `examples/`:
9898
* **cubes** renders waving cubes.
9999
* **flags** shows window flags.
100100
* **fly** renders a 3-D scene, with keyboard and mouse controls.
101+
* **font** displays text using bitmap fonts.
101102
* **keys** demonstrates keyboard input.
102103
* **map** renders a height map.
103104
* **truck** rotates a 3-D model loaded from file.

examples/font.f90

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
! font.f90
2+
!
3+
! Example program that demonstrates bitmap font rendering. Based on the raylib
4+
! example `text_raylib_fonts.c`.
5+
!
6+
! Author: Philipp Engel
7+
! Licence: ISC
8+
program main
9+
use, intrinsic :: iso_c_binding
10+
use :: raylib
11+
implicit none (type, external)
12+
13+
integer, parameter :: MAX_FONTS = 8
14+
integer, parameter :: SCREEN_WIDTH = 800
15+
integer, parameter :: SCREEN_HEIGHT = 450
16+
17+
integer :: i
18+
integer :: spacings(MAX_FONTS)
19+
character(len=72) :: messages(MAX_FONTS)
20+
type(color_type) :: colors(MAX_FONTS)
21+
type(font_type) :: fonts(MAX_FONTS)
22+
type(vector2_type) :: positions(MAX_FONTS)
23+
type(vector2_type) :: v2
24+
25+
call init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'Fortran + raylib' // c_null_char)
26+
call set_target_fps(60)
27+
28+
fonts = [ &
29+
load_font('share/alagard.png' // c_null_char), &
30+
load_font('share/pixelplay.png' // c_null_char), &
31+
load_font('share/mecha.png' // c_null_char), &
32+
load_font('share/setback.png' // c_null_char), &
33+
load_font('share/romulus.png' // c_null_char), &
34+
load_font('share/pixantiqua.png' // c_null_char), &
35+
load_font('share/alpha_beta.png' // c_null_char), &
36+
load_font('share/jupiter_crash.png' // c_null_char) &
37+
]
38+
39+
messages = [ character(len=72) :: &
40+
'ALAGARD FONT designed by Hewett Tsoi', &
41+
'PIXELPLAY FONT designed by Aleksander Shevchuk', &
42+
'MECHA FONT designed by Captain Falcon', &
43+
'SETBACK FONT designed by Brian Kent (AEnigma)', &
44+
'ROMULUS FONT designed by Hewett Tsoi', &
45+
'PIXANTIQUA FONT designed by Gerhard Grossmann', &
46+
'ALPHA_BETA FONT designed by Brian Kent (AEnigma)', &
47+
'JUPITER_CRASH FONT designed by Brian Kent (AEnigma)' &
48+
]
49+
50+
spacings = [ 2, 4, 8, 4, 3, 4, 4, 1 ]
51+
52+
do i = 1, MAX_FONTS
53+
v2 = measure_text_ex(fonts(i), trim(messages(i)) // c_null_char, fonts(i)%base_size * 2.0, real(spacings(i)))
54+
55+
positions(i)%x = SCREEN_WIDTH / 2.0 - v2%x / 2.0
56+
positions(i)%y = 60.0 + fonts(i)%base_size + 45.0 * (i - 1)
57+
end do
58+
59+
! Small Y position corrections.
60+
positions(4)%y = positions(4)%y + 8
61+
positions(5)%y = positions(5)%y + 2
62+
positions(8)%y = positions(8)%y - 8
63+
64+
colors = [ MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED ]
65+
66+
do while (.not. window_should_close())
67+
call begin_drawing()
68+
call clear_background(RAYWHITE)
69+
70+
call draw_text('free fonts included with raylib' // c_null_char, 250, 20, 20, DARKGRAY)
71+
call draw_line(220, 50, 590, 50, DARKGRAY)
72+
73+
do i = 1, MAX_FONTS
74+
call draw_text_ex(fonts(i), &
75+
trim(messages(i)) // c_null_char, &
76+
positions(i), &
77+
fonts(i)%base_size * 2.0, &
78+
real(spacings(i)), &
79+
colors(i))
80+
end do
81+
call end_drawing()
82+
end do
83+
84+
do i = 1, MAX_FONTS
85+
call unload_font(fonts(i))
86+
end do
87+
88+
call close_window()
89+
end program main

fpm.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ name = "fly"
4141
source-dir = "examples"
4242
main = "fly.f90"
4343

44+
[[executable]]
45+
name = "font"
46+
source-dir = "examples"
47+
main = "font.f90"
48+
4449
[[executable]]
4550
name = "keys"
4651
source-dir = "examples"

share/alagard.png

3.46 KB
Loading

share/alpha_beta.png

2.28 KB
Loading

share/jupiter_crash.png

2.82 KB
Loading

share/mecha.png

2.22 KB
Loading

share/pixantiqua.png

2.59 KB
Loading

share/pixelplay.png

2.68 KB
Loading

0 commit comments

Comments
 (0)