From 5112241a93dd57946cd4924951cfee4a024b7059 Mon Sep 17 00:00:00 2001 From: gmueller Date: Sat, 8 Jan 2011 17:53:45 +0100 Subject: [PATCH] restructure main, add basic font support --- data/fonts/console.fnt | 195 ++++++++++++++++++++++++++ data/fonts/console.tga | Bin 0 -> 262162 bytes src/CMakeLists.txt | 3 +- src/Schedule.h | 56 ++++++++ src/main.cpp | 311 +++++++++++++++++++++++++---------------- src/oglfont.cpp | 270 +++++++++++++++++++++++++++++++++++ src/oglfont.h | 49 +++++++ 7 files changed, 759 insertions(+), 125 deletions(-) create mode 100644 data/fonts/console.fnt create mode 100644 data/fonts/console.tga create mode 100644 src/Schedule.h create mode 100644 src/oglfont.cpp create mode 100644 src/oglfont.h diff --git a/data/fonts/console.fnt b/data/fonts/console.fnt new file mode 100644 index 0000000..f2a1f97 --- /dev/null +++ b/data/fonts/console.fnt @@ -0,0 +1,195 @@ +info face="Courier New" size=-13 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=1,1 outline=0 +common lineHeight=16 base=12 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0 +page id=0 file="console.tga" +chars count=191 +char id=32 x=12 y=49 width=1 height=1 xoffset=0 yoffset=12 xadvance=8 page=0 chnl=15 +char id=33 x=199 y=30 width=1 height=8 xoffset=4 yoffset=4 xadvance=8 page=0 chnl=15 +char id=34 x=156 y=40 width=5 height=4 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=35 x=215 y=0 width=6 height=10 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=36 x=6 y=13 width=4 height=10 xoffset=2 yoffset=3 xadvance=8 page=0 chnl=15 +char id=37 x=133 y=31 width=5 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=38 x=237 y=29 width=5 height=7 xoffset=2 yoffset=5 xadvance=8 page=0 chnl=15 +char id=39 x=200 y=39 width=1 height=4 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=40 x=253 y=0 width=2 height=10 xoffset=4 yoffset=4 xadvance=8 page=0 chnl=15 +char id=41 x=19 y=12 width=2 height=10 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=42 x=115 y=40 width=5 height=6 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=43 x=201 y=30 width=7 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=44 x=192 y=39 width=3 height=4 xoffset=2 yoffset=10 xadvance=8 page=0 chnl=15 +char id=45 x=0 y=49 width=6 height=1 xoffset=1 yoffset=8 xadvance=8 page=0 chnl=15 +char id=46 x=223 y=37 width=2 height=2 xoffset=3 yoffset=10 xadvance=8 page=0 chnl=15 +char id=47 x=0 y=13 width=5 height=10 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=48 x=218 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=49 x=225 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=50 x=169 y=31 width=5 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=51 x=163 y=31 width=5 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=52 x=232 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=53 x=239 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=54 x=145 y=31 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=55 x=105 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=56 x=246 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=57 x=0 y=33 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=58 x=253 y=29 width=2 height=6 xoffset=3 yoffset=6 xadvance=8 page=0 chnl=15 +char id=59 x=249 y=29 width=3 height=7 xoffset=2 yoffset=6 xadvance=8 page=0 chnl=15 +char id=60 x=230 y=29 width=6 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=61 x=202 y=38 width=6 height=3 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=62 x=209 y=29 width=6 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=63 x=193 y=30 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=64 x=241 y=0 width=5 height=10 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=65 x=83 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=66 x=14 y=33 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=67 x=21 y=32 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=68 x=28 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=69 x=42 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=70 x=49 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=71 x=27 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=72 x=248 y=11 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=73 x=187 y=30 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=74 x=56 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=75 x=187 y=21 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=76 x=63 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=77 x=171 y=21 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=78 x=203 y=11 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=79 x=163 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=80 x=70 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=81 x=42 y=12 width=7 height=9 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=82 x=107 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=83 x=84 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=84 x=131 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=85 x=123 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=86 x=230 y=11 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=87 x=139 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=88 x=147 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=89 x=155 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=90 x=175 y=30 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=91 x=15 y=12 width=3 height=10 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=92 x=235 y=0 width=5 height=10 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=93 x=11 y=12 width=3 height=10 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=94 x=150 y=40 width=5 height=4 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=95 x=238 y=37 width=8 height=1 xoffset=0 yoffset=15 xadvance=8 page=0 chnl=15 +char id=96 x=226 y=37 width=2 height=2 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=97 x=35 y=40 width=7 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=98 x=35 y=22 width=7 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=99 x=66 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=100 x=43 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=101 x=59 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=102 x=91 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=103 x=59 y=22 width=7 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=104 x=67 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=105 x=157 y=31 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=106 x=247 y=0 width=5 height=10 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=107 x=91 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=108 x=151 y=31 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=109 x=9 y=42 width=8 height=6 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15 +char id=110 x=27 y=41 width=7 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=111 x=87 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=112 x=98 y=31 width=6 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=113 x=99 y=22 width=7 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=114 x=94 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=115 x=73 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=116 x=223 y=29 width=6 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=117 x=51 y=40 width=7 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=118 x=0 y=42 width=8 height=6 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15 +char id=119 x=43 y=40 width=7 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=120 x=101 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=121 x=203 y=20 width=7 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=122 x=121 y=40 width=5 height=6 xoffset=2 yoffset=6 xadvance=8 page=0 chnl=15 +char id=123 x=195 y=11 width=3 height=9 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=124 x=22 y=12 width=1 height=10 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=125 x=199 y=11 width=3 height=9 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=126 x=213 y=37 width=6 height=2 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=15 +char id=160 x=254 y=36 width=1 height=1 xoffset=0 yoffset=12 xadvance=8 page=0 chnl=15 +char id=161 x=253 y=20 width=1 height=8 xoffset=4 yoffset=6 xadvance=8 page=0 chnl=15 +char id=162 x=243 y=29 width=5 height=7 xoffset=2 yoffset=5 xadvance=8 page=0 chnl=15 +char id=163 x=112 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=164 x=108 y=40 width=6 height=6 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=165 x=195 y=21 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=166 x=24 y=12 width=1 height=10 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=167 x=142 y=12 width=6 height=9 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=168 x=7 y=49 width=4 height=1 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=169 x=0 y=24 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=170 x=167 y=40 width=4 height=4 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=171 x=127 y=40 width=7 height=5 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=15 +char id=172 x=142 y=40 width=7 height=4 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=15 +char id=173 x=247 y=37 width=6 height=1 xoffset=1 yoffset=8 xadvance=8 page=0 chnl=15 +char id=174 x=239 y=11 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=175 x=229 y=37 width=8 height=1 xoffset=0 yoffset=2 xadvance=8 page=0 chnl=15 +char id=176 x=172 y=40 width=4 height=4 xoffset=2 yoffset=3 xadvance=8 page=0 chnl=15 +char id=177 x=51 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=178 x=177 y=39 width=4 height=4 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=179 x=182 y=39 width=4 height=4 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=180 x=220 y=37 width=2 height=2 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=181 x=75 y=22 width=7 height=8 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15 +char id=182 x=74 y=12 width=7 height=9 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=183 x=14 y=49 width=1 height=1 xoffset=5 yoffset=7 xadvance=8 page=0 chnl=15 +char id=184 x=209 y=37 width=3 height=3 xoffset=3 yoffset=11 xadvance=8 page=0 chnl=15 +char id=185 x=196 y=39 width=3 height=4 xoffset=3 yoffset=4 xadvance=8 page=0 chnl=15 +char id=186 x=187 y=39 width=4 height=4 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=187 x=135 y=40 width=6 height=5 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=15 +char id=188 x=9 y=24 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=189 x=18 y=23 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=190 x=221 y=11 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=191 x=139 y=31 width=5 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=192 x=73 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=193 x=113 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=194 x=105 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=195 x=33 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=196 x=167 y=0 width=7 height=10 xoffset=1 yoffset=2 xadvance=8 page=0 chnl=15 +char id=197 x=0 y=0 width=7 height=12 xoffset=1 yoffset=0 xadvance=8 page=0 chnl=15 +char id=198 x=212 y=11 width=8 height=8 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=199 x=121 y=0 width=6 height=11 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=200 x=128 y=0 width=6 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=201 x=135 y=0 width=6 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=202 x=142 y=0 width=6 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=203 x=222 y=0 width=6 height=10 xoffset=1 yoffset=2 xadvance=8 page=0 chnl=15 +char id=204 x=149 y=0 width=5 height=11 xoffset=2 yoffset=1 xadvance=8 page=0 chnl=15 +char id=205 x=161 y=0 width=5 height=11 xoffset=2 yoffset=1 xadvance=8 page=0 chnl=15 +char id=206 x=155 y=0 width=5 height=11 xoffset=2 yoffset=1 xadvance=8 page=0 chnl=15 +char id=207 x=229 y=0 width=5 height=10 xoffset=2 yoffset=2 xadvance=8 page=0 chnl=15 +char id=208 x=119 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=209 x=8 y=0 width=8 height=11 xoffset=0 yoffset=1 xadvance=8 page=0 chnl=15 +char id=210 x=65 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=211 x=81 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=212 x=49 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=213 x=41 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=214 x=175 y=0 width=7 height=10 xoffset=1 yoffset=2 xadvance=8 page=0 chnl=15 +char id=215 x=162 y=40 width=4 height=4 xoffset=2 yoffset=6 xadvance=8 page=0 chnl=15 +char id=216 x=50 y=12 width=7 height=9 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=217 x=17 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=218 x=97 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=219 x=89 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=220 x=207 y=0 width=7 height=10 xoffset=1 yoffset=2 xadvance=8 page=0 chnl=15 +char id=221 x=57 y=0 width=7 height=11 xoffset=1 yoffset=1 xadvance=8 page=0 chnl=15 +char id=222 x=126 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=223 x=211 y=20 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=224 x=34 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=225 x=26 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=226 x=106 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=227 x=58 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=228 x=115 y=22 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=229 x=199 y=0 width=7 height=10 xoffset=1 yoffset=2 xadvance=8 page=0 chnl=15 +char id=230 x=18 y=42 width=8 height=6 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15 +char id=231 x=156 y=12 width=6 height=9 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=232 x=149 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=233 x=163 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=234 x=170 y=11 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=235 x=7 y=33 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=236 x=189 y=11 width=5 height=9 xoffset=2 yoffset=3 xadvance=8 page=0 chnl=15 +char id=237 x=183 y=11 width=5 height=9 xoffset=2 yoffset=3 xadvance=8 page=0 chnl=15 +char id=238 x=177 y=11 width=5 height=9 xoffset=2 yoffset=3 xadvance=8 page=0 chnl=15 +char id=239 x=181 y=30 width=5 height=8 xoffset=2 yoffset=4 xadvance=8 page=0 chnl=15 +char id=240 x=35 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=241 x=66 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=242 x=114 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=243 x=121 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=244 x=128 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=245 x=135 y=12 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=246 x=77 y=31 width=6 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=247 x=216 y=29 width=6 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=15 +char id=248 x=80 y=40 width=6 height=6 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15 +char id=249 x=82 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=250 x=90 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=251 x=98 y=12 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=252 x=179 y=21 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 +char id=253 x=25 y=0 width=7 height=11 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=15 +char id=254 x=183 y=0 width=7 height=10 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=15 +char id=255 x=191 y=0 width=7 height=10 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=15 diff --git a/data/fonts/console.tga b/data/fonts/console.tga new file mode 100644 index 0000000000000000000000000000000000000000..989be5259dce4d35b56d7143073b6075fbcff8e4 GIT binary patch literal 262162 zcmeH}(UKg=jRaTsbf2OB|4E$%dtDR6A*-rqNQ%4id>AAm0?2A#%1nR!@jrk3`~2gN zfBf@*|J`|!fCMBU0SQPz0uqpb1SB8<2}nQ!5|DrdBp?9^NI(J-kbndvAOQ(TKmrnw zfCMBU0SQPz0uqpb1SB8<2}nQ!5|DrdBp?9^NI(J-kbndvAOQ(TKmrnwfCMBU0SQPz z0uqpb1SB8<2}nQ!5|DrdBp?9^NI(J-kbndvAOQ(TKmrnwfCMBU0SQPz0uqpb1SB8< z2}nQ!5|DrdBp?9^NI(J-kbndvAOQ(TKmrnwfCMBU0SQPz0uqpb1SB8<2}nQ!5|Drd zBp?9^NI(J-kbndvAOQ(TKmrnwfCMBU0SQPz0uqpb1SB8<2}nQ!5|DrdBp?9^NI(J- zkbndvAOQ(TKmrnw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l8k(W&UEQ|mr=PR}s+8IRey?<;z~qxa1oul3w>@V58ysWThB&-71y&-9&qwA`ua z)Tesqa?fE$S9EH7x!>vS_kEjv*Y6#7v&rU=qrTLSzf-5DlAQfXCr3TyHvMkq&d*LV zRNkSYQ>RWpD|u@BXw;`(a@)*T^to^Ld|T^%-~9fbnVo%S?{;ne+?Sq1zH7Yhxlf&b zR`S#6kkKczksPVX;=J8M2sh{#Eo%vbGQ}29oT{FW$r%#Rc)qd`! zpLM?T)Sq*+XU|EWKK-nx`KiC#^A2W_huzC z_3p1SS6+5p`FPZRllv3zNrrvYIWzm@HtjS&^=interval = interval; + } + + double getInterval() { + return interval; + } + + void setExact(bool exact) { + this->exact = exact; + } + + void setPaused(bool paused) { + this->paused = paused; + } + + bool next(double now) { + if (now > (last + interval)) { + if (exact) + last += interval; + else + last = now; + if (paused) + return false; + else + return true; + } else { + return false; + } + } +}; +#endif /* SCHEDULE_H_ */ diff --git a/src/main.cpp b/src/main.cpp index 3df7da8..25f732f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,8 @@ #include "common.h" #include "game.h" #include "Explosion.h" +#include "Schedule.h" +#include "oglfont.h" GLUquadricObj *quadratic; ENetHost *host; @@ -61,7 +63,7 @@ void setup_opengl() { glEnable( GL_LIGHTING); // Enable vertical sync (on cards that support it) - glfwSwapInterval(1); + glfwSwapInterval(0); } void draw_team(team_t *team) { @@ -456,19 +458,80 @@ void explosion_callback(double x, double y, double z) { explosion.add(x, y, z); } -int main(int argc, char ** argv) { - int width, height, x, y, last_x, last_y; - double time, last_time, phi = 0.0, theta = 0.0, last_player_update, - last_bomb; - GLboolean running; - int server = 0; +class Application { +public: + void initialize(int argc, char ** argv); + void update(); + void shutdown(); + bool isRunning(); +private: + bool running; + double last_time, last_bomb; //TODO: use bomb schedule; + int last_x, last_y; + double phi, theta; + double camX, camY, camZ; + Schedule accelerate_schudule; + Schedule player_update_schudule; + game_t game; + int server; + int width, height; + //TrueTyeFont font; + oglf_font_t font; + + void prepareFrame(double rx, double ry, double rz); + + void loadConsoleFont(); +}; + +void Application::loadConsoleFont() { + GLuint font_id = 0; + + glGenTextures(1, &font_id); + glBindTexture(GL_TEXTURE_2D, font_id); + + // Set texture parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + // Upload texture from file to texture memory + glfwLoadTexture2D("data/fonts/console.tga", 0); + oglf_load(&font, "data/fonts/console.fnt", font_id); +} +void Application::prepareFrame(double rx, double ry, double rz) { + // Get window size (may be different than the requested size) + glfwGetWindowSize(&width, &height); + height = height > 0 ? height : 1; + + // Set viewport + glViewport(0, 0, width, height); + + // Clear color buffer + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Select and setup the projection matrix + glMatrixMode( GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0f, (GLfloat) width / (GLfloat) height, 1.0f, 10000.0f); + + // Select and setup the modelview matrix + glMatrixMode( GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(camX, camY, camZ, camX + rx * 10.0f, camY + ry * 10.0f, camZ + rz + * 10.0f, 0.0f, 1.0f, 0.0f); + +} + +void Application::initialize(int argc, char ** argv) { + server = 0; + double time, last_player_update; quadratic = gluNewQuadric(); gluQuadricNormals(quadratic, GLU_SMOOTH); gluQuadricTexture(quadratic, GL_TRUE); - game_t game; - game_setup(&game); setup_opengl(); @@ -484,44 +547,56 @@ int main(int argc, char ** argv) { team_t *team = game_team(&game, 0); local_player = game_spawn_player(&game, team); } - float plane_color[] = { 0.2f, 0.3f, 0.4f, 1.0f }; size_t i; running = GL_TRUE; last_time = glfwGetTime(); last_player_update = last_time; last_bomb = last_time; - double camX, camY, camZ; glfwGetMousePos(&last_x, &last_y); - while (running) { - // Get time and mouse position - time = glfwGetTime(); - double dt = time - last_time; - glfwGetMousePos(&x, &y); - if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2) == GLFW_PRESS) { - phi += (x - last_x) * 0.01; - theta += (y - last_y) * -0.01; - if (theta > 1.5) - theta = 1.5; - if (theta < -1.5) - theta = -1.5; - } - last_x = x; - last_y = y; - if (local_player) { - camX = local_player->x; - camY = local_player->y; - camZ = local_player->z; - } else { - camX = 1000.0; - camY = 1000.0; - camZ = 1000.0; - } + accelerate_schudule.setExact(true); + accelerate_schudule.setInterval(0.05); - double rx = cos(phi) * cos(theta); - double ry = sin(theta); - double rz = sin(phi) * cos(theta); - double v = 50.0f * dt; + player_update_schudule.setExact(true); + player_update_schudule.setInterval(0.1); + + loadConsoleFont(); +} + +void Application::update() { + + // Get time and mouse position + double time = glfwGetTime(); + double dt = time - last_time; + int x, y; + glfwGetMousePos(&x, &y); + if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2) == GLFW_PRESS) { + phi += (x - last_x) * 0.01; + theta += (y - last_y) * -0.01; + if (theta > 1.5) + theta = 1.5; + if (theta < -1.5) + theta = -1.5; + } + last_x = x; + last_y = y; + + if (local_player) { + camX = local_player->x; + camY = local_player->y; + camZ = local_player->z; + } else { + camX = 1000.0; + camY = 1000.0; + camZ = 1000.0; + } + + double rx = cos(phi) * cos(theta); + double ry = sin(theta); + double rz = sin(phi) * cos(theta); + if (accelerate_schudule.next(time)) { + double t = accelerate_schudule.getInterval(); + double v = 50.0 * t; if (glfwGetKey('W')) { accelerate(&game, rx * v, ry * v, rz * v); } else if (glfwGetKey('S')) { @@ -535,101 +610,89 @@ int main(int argc, char ** argv) { } if (glfwGetKey(GLFW_KEY_SPACE)) { - accelerate(&game, local_player->vx * -dt, local_player->vy * -dt, - local_player->vz * -dt); + accelerate(&game, local_player->vx * -0.1, local_player->vy * -0.1, + local_player->vz * -0.1); } - - if (glfwGetKey(GLFW_KEY_LCTRL)) { - if (time - last_bomb > 5.0) { - last_bomb = time; - drop_bomb(&game, local_player->x + rx - 20.0, local_player->y - + ry * -20.0, local_player->z + rz * -20.0, 5.0); - } - } - - if (glfwGetKey(GLFW_KEY_ENTER)) { - explosion.add(200.0, 200.0, 200.0); - } - - // Get window size (may be different than the requested size) - glfwGetWindowSize(&width, &height); - height = height > 0 ? height : 1; - - // Set viewport - glViewport(0, 0, width, height); - - // Clear color buffer - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Select and setup the projection matrix - glMatrixMode( GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60.0f, (GLfloat) width / (GLfloat) height, 1.0f, - 10000.0f); - - // Select and setup the modelview matrix - glMatrixMode( GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(camX, camY, camZ, camX + cos(phi) * cos(theta) * 10.0f, camY - + sin(theta) * 10.0f, camZ + sin(phi) * cos(theta) * 10.0f, // View-point - 0.0f, 1.0f, 0.0f); // Up-vector - - service_network(&game); - if (server) { - if (time > last_player_update + 0.1) { - send_player_updates(&game); - last_player_update = time; - } - } - - game_update_players(&game, dt); - game_update_bombs(&game, dt, explosion_callback); - - glEnable( GL_LIGHT0); - glEnable( GL_LIGHTING); - glEnable( GL_CULL_FACE); - - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, plane_color); - // Draw a textured quad - glBegin( GL_QUADS); - glVertex3f(-5000.0f, 5000.0f, -5000.0f); - glVertex3f(5000.0f, 5000.0f, -5000.0f); - glVertex3f(5000.0f, 5000.0f, 5000.0f); - glVertex3f(-5000.0f, 5000.0f, 5000.0f); - glEnd(); - for (i = 0; i < GAME_TEAM_COUNT; i++) - draw_team(&game.team[i]); - - for (i = 0; i < GAME_PLAYER_COUNT; i++) - draw_player(&game.player[i]); - - for (i = 0; i < GAME_BOMB_COUNT; i++) - draw_bomb(&game.bomb[i]); - - glDisable(GL_LIGHT0); - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - explosion.update(dt * 1000.0, camX, camY, camZ); - explosion.render(); - - // Swap buffers - glfwSwapBuffers(); - - // Check if the ESC key was pressed or the window was closed - running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); - - last_time = time; } + if (glfwGetKey(GLFW_KEY_LCTRL)) { + if (time - last_bomb > 5.0) { + last_bomb = time; + drop_bomb(&game, local_player->x + rx * 20.0, local_player->y + ry + * 20.0, local_player->z + rz * 20.0, 5.0); + } + } + + prepareFrame(rx, ry, rz); + + glEnable( GL_LIGHT0); + glEnable( GL_LIGHTING); + glEnable( GL_CULL_FACE); + const float plane_color[] = { 0.2f, 0.3f, 0.4f, 1.0f }; + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, plane_color); + // Draw a textured quad + glBegin( GL_QUADS); + glVertex3f(-5000.0f, 5000.0f, -5000.0f); + glVertex3f(5000.0f, 5000.0f, -5000.0f); + glVertex3f(5000.0f, 5000.0f, 5000.0f); + glVertex3f(-5000.0f, 5000.0f, 5000.0f); + glEnd(); + for (size_t i = 0; i < GAME_TEAM_COUNT; i++) + draw_team(&game.team[i]); + + for (size_t i = 0; i < GAME_PLAYER_COUNT; i++) + draw_player(&game.player[i]); + + for (size_t i = 0; i < GAME_BOMB_COUNT; i++) + draw_bomb(&game.bomb[i]); + + glDisable(GL_LIGHT0); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + explosion.update(dt * 1000.0, camX, camY, camZ); + explosion.render(); + + oglf_begin(&font, width, height); + oglf_print(&font, 40, 40, "Hello"); + oglf_end(); + + // Swap buffers + glfwSwapBuffers(); + + // Check if the ESC key was pressed or the window was closed + running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); + service_network(&game); + if (server && player_update_schudule.next(time)) { + send_player_updates(&game); + } + + game_update_players(&game, dt); + game_update_bombs(&game, dt, explosion_callback); + + last_time = time; + +} + +void Application::shutdown() { gluDeleteQuadric(quadratic); enet_host_destroy(host); enet_deinitialize(); - + oglf_destroy(&font); // Close OpenGL window and terminate GLFW glfwTerminate(); +} +bool Application::isRunning() { + return running; +} + +int main(int argc, char ** argv) { + Application app; + app.initialize(argc, argv); + while (app.isRunning()) + app.update(); + app.shutdown(); return 0; } diff --git a/src/oglfont.cpp b/src/oglfont.cpp new file mode 100644 index 0000000..634d519 --- /dev/null +++ b/src/oglfont.cpp @@ -0,0 +1,270 @@ +#include "oglfont.h" +#include +#include +#include +#include +#include +#include + +#define GL_Y_FIX(f) (1 - (f)) +static void _compile(oglf_font_t *font) { + int chr; + + font->base_list = glGenLists(OGLF_MAX_ASCII); + glBindTexture(GL_TEXTURE_2D, font->fontTex); + + for (chr = 0; chr < OGLF_MAX_ASCII; chr++) { + glNewList(font->base_list + chr - 1, GL_COMPILE); + + if (font->chars[chr].w) { + glBegin(GL_QUADS); + glTexCoord2f( + (float) font->chars[chr].x / (float) font->w, + (float) GL_Y_FIX((font->chars[chr].y+font->chars[chr].h) / (float) font->h)); + glVertex2d((float) font->chars[chr].x_ofs, + (float) font->chars[chr].h + font->chars[chr].y_ofs); + + glTexCoord2f( + (float) (font->chars[chr].x + font->chars[chr].w) + / (float) font->w, + (float) GL_Y_FIX((font->chars[chr].y + font->chars[chr].h) / (float) font->h)); + glVertex2d((float) font->chars[chr].w + font->chars[chr].x_ofs, + (float) font->chars[chr].h + font->chars[chr].y_ofs); + + glTexCoord2f((float) (font->chars[chr].x + font->chars[chr].w) + / (float) font->w, + (float) GL_Y_FIX( font->chars[chr].y / (float) font->h)); + glVertex2d((float) font->chars[chr].w + font->chars[chr].x_ofs, + (float) font->chars[chr].y_ofs); + + glTexCoord2f((float) font->chars[chr].x / (float) font->w, + (float) GL_Y_FIX( font->chars[chr].y / (float) font->h)); + glVertex2d((float) font->chars[chr].x_ofs, + (float) font->chars[chr].y_ofs); + glEnd(); + glTranslatef((float) (font->chars[chr].x_advance + ), 0, 0); + } else { + // if char has no width, treat it like a space + glTranslatef((float) font->base, 0, 0); + } + + glEndList(); + } +} + +static int _starts_with(const char *buffer, const char *text) { + const char *text_ptr = text; + const char *buffer_ptr = buffer; + while (*text_ptr != 0) { + + if (*text_ptr != *buffer_ptr) + return 0; + + text_ptr++; + buffer_ptr++; + } + + return 1; +} + +static int _parse_line(oglf_font_t *font, char *buffer) { + + if (_starts_with(buffer, "common")) { + int count = sscanf(buffer, + "common lineHeight=%d base=%d scaleW=%d scaleH=%d pages=%d\n", + &font->line_h, &font->base, &font->w, &font->h, &font->pages); + + if (count != 5) + return 0; + } else if (_starts_with(buffer, "char ")) { + oglf_char_t temp_char; + int id; + int + count = + sscanf( + buffer, + "char id=%d x=%d y=%d width=%d height=%d xoffset=%d yoffset=%d xadvance=%d page=%d chnl=%*d\n", + &id, &temp_char.x, &temp_char.y, &temp_char.w, + &temp_char.h, &temp_char.x_ofs, + &temp_char.y_ofs, &temp_char.x_advance, + &temp_char.page); + font->chars[id] = temp_char; + + if (count != 9) + return 0; + } + + return 1; +} + +int oglf_load(oglf_font_t *font, const char *bmf_path, unsigned int texture) { + FILE *file; + char buffer[256]; + + file = fopen(bmf_path, "r"); // could not open file for read + if (file == 0) + return 0; + + font->chars = (oglf_char_t *) malloc(OGLF_MAX_ASCII * sizeof(oglf_char_t)); + + while (fgets(buffer, sizeof(buffer), file) != 0) { + int result = _parse_line(font, buffer); + if (result == 0) + return 0; + } + + fclose(file); // close the source file + + font->fontTex = texture; + font->scale = 1.f; + + _compile(font); + + return 1; +} + +// calculate the approx. width of a string of text +// note: no kerning info is currently evaluated +int oglf_width(oglf_font_t *font, const char *text) { + int w, l, i; + w = 0; + l = strlen(text); + for (i = 0; i < l; i++) { + //w += font->chars[text[i]].w; + w += font->chars[text[i]].x_advance; + } + return w; +} + +// destroy the charset +void oglf_destroy(oglf_font_t *font) { + glDeleteLists(font->base_list, OGLF_MAX_ASCII); + glDeleteTextures(1, &font->fontTex); + free(font->chars); +} +/* + void ogl___font_in(ogl_font *font); + + void bmf___font_in(ogl_font *font) { + ogl___font_in(font); + } + + + + */ + +void oglf_begin(oglf_font_t *font, int width, int height) { + glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT + | GL_TRANSFORM_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + //glNormal3f( 0.0, 0.0, 1.0); + + // set projection matrix + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + //int newheight = (_width / 16.0) * 9.0; + glOrtho(0.0, + (double)width, + (double)height, + 0.0, + -1.0, + 1.0); + // prepare model matrix + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + //glScalef(font->scale, font->scale, 1.f); + + glBindTexture(GL_TEXTURE_2D, font->fontTex); + glEnable(GL_TEXTURE_2D); + + glAlphaFunc(GL_GEQUAL,0.1); + glEnable(GL_ALPHA_TEST); +} + +void oglf_print_l(oglf_font_t *font, float x, float y, const char *text, int l) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(x, y, 0); + glCallLists(l, GL_UNSIGNED_BYTE, text); + glPopMatrix(); +} + +void oglf_end() { + glPopAttrib(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void oglf_print(oglf_font_t *font, float x, float y, const char *text) { + oglf_print_l(font, x, y, text, strlen(text)); +} + +void oglf_printf(oglf_font_t *font, int x, int y, const char *fmt, ...) { + char text[OGLF_MAX_LINE], *line_start, *c; + float h; + va_list ap; + int row; + + if (strlen(fmt) == 0) + return; + + va_start(ap, fmt); + vsprintf(text, fmt, ap); + va_end(ap); + + line_start = text; + row = 0; + h = font->h / .63f; + + NextL: c = strchr(line_start, '\n'); + if (c) { + row++; + oglf_print_l(font, (float) x, (float) (y - h * row), line_start, c + - line_start); + line_start = c + 1; + goto NextL; + } + + oglf_print_l(font, (float) x, (float) (y - h * row), line_start, strlen( + line_start)); +} + +/* + #define OGLF_CENTER_TEXT(rect, txtw, ofs) ((float)((rect[ofs+_W] - txtw - rect[ofs])/2 + rect[ofs])) + + // printf function which takes in account the alignment + void ogl_printf_al(oglf_font_t *font, alignment align, GLuint *rect, + const char *fmt, ...) { + char text[BMF_MAX_LINE]; + va_list ap; + + if (!strlen(fmt)) + return; + + va_start(ap, fmt); + vsprintf(text, fmt, ap); + va_end(ap); + + switch (align) { + case al_left: + ogl_print(font, (float) rect[_X], + OGLF_CENTER_TEXT(rect, font->line_h, _Y), text); + break; + case al_right: + ogl_print(font, ((float) rect[_W] - ogl__width(font, text)), + OGLF_CENTER_TEXT(rect, font->line_h, _Y), text); + break; + case al_center: + ogl_print(font, OGLF_CENTER_TEXT(rect, ogl__width(font, text), _X), + OGLF_CENTER_TEXT(rect, font->line_h, _Y), text); + break; + } + } + */ diff --git a/src/oglfont.h b/src/oglfont.h new file mode 100644 index 0000000..2285f3a --- /dev/null +++ b/src/oglfont.h @@ -0,0 +1,49 @@ +#ifndef OGLF_H_ +#define OGLF_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGLF_MAX_ASCII 256 +#define OGLF_MAX_LINE 1024 +#define OGLF_MAX_PATH 256 + +typedef struct oglf_char_t { + unsigned int x, y, w, h; + unsigned int x_ofs, y_ofs; + unsigned int x_advance, page; +} oglf_char_t; + +typedef struct oglf_kerninfo_t { + unsigned short first, second; + short kerning; +} oglf_kerninfo_t; + +typedef struct oglf_font_t { + float scale; + int base, line_h, w, h, pages, kerninfo_count; + unsigned int fontTex; + int base_list; + oglf_kerninfo_t *kerninfo; + oglf_char_t *chars; + float mmat[16]; +} oglf_font_t; + +int oglf_load(oglf_font_t *font, const char *bmf_path, unsigned int texture); +int oglf_width(oglf_font_t *font, const char *text); +void oglf_destroy(oglf_font_t *font); + +void oglf_begin(oglf_font_t *font, int width, int height); +void oglf_end(); + +void oglf_print(oglf_font_t *font, float x, float y, const char *text); +void oglf_printf_al(oglf_font_t *font, int align, unsigned int *rect, + const char *fmt, ...); +void oglf_printf(oglf_font_t *font, int x, int y, const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +#endif // _FONT_H_