-
Render text on screen
-
Control:
-
where the text shows
-
the font
-
the detail in the font
-
-
Change the text on demand
-
Have a working build system, that uses SDL
-
Create a window, change its size, including fullscreen
-
Have a program that draws a sprite on the screen
-
with a size and position that you can control/change
-
sprite position and size independent of window resolution
-
-
Compensate for real-time in your Game Loop
-
Have a sprite class to encapsulate sprite data
-
Have a container to store multiple sprites
-
Be able to update and render multiple sprites
-
We’ll be adding stuff to
main.cppto do more interesting things -
You could continue with your existing code (take a snapshot/commit)
-
or start a fresh project
-
-
Text is represented by a series of glyphs (symbols)
-
Glyphs are generated from a font
-
A font is a particular size, weight and style of a typeface.
-
A typeface (aka font-family) is a set of fonts that share common design features
-
!!!
-
the words "font" and "typeface" are frequently confused
-
Fonts are usually described in some format of vector format
-
rather than a raster format
-
-
TrueType is the most common format (.ttf files)
-
the content of .ttf files is protected by copyright
-
you should be careful distributing .ttf files in your game
-
there are a variety of openly licensed .ttf files/formats
-
e.g. the Hack typeface - http://sourcefoundry.org/hack/
-
-
-
In games, text is usually rendered to the screen via a texture or sprite
-
with SDL2 this is reasonably easy
-
-
the SDL2_ttf library provides useful functions
-
the
TTF_OpenFont()function loads a font from a.ttffile -
the
TTF_RenderText_Solid()function generates anSDL_Surfacefrom a font, a string, and a colour -
this
SDL_Surfacecan be converted to anSDL_TexturewithSDL_CreateTextureFromSurface() -
an
SDL_Surfacecan then be rendered usingSDL_RenderCopy(), just like a sprite
-
-
There are a number of sources for SDL2_ttf on conan.io
-
Choose one
-
Add it to your
conanfile.txt -
(re)run conan to install the library
-
-
#includethe library in your code to check you can include it -
add lines of code that use the library (initialisation?) to check it links
-
build your program, and check it runs
-
You’ll need a font file to generate a font
-
Choose/find one that you have license to use
-
-
Where should you put the file?
-
how do you make it so that it gets copied to your binary folder
-
HINT: like other assets
-
HINT: cmake supports this
-
-
Using the docs, load the file to a
TTF_Font *
-
Using the docs, Turn the font into an SDL_Surface
-
what can you control?
-
-
What stages will you need to repeat?
-
What aspects do you need to be careful about?
-
HINT: memory management - both CPU and GPU side
-
-
There are some hints for how the texture should be handled
-
Read the docs on SDL_CreateTextureFromSurface and follow the links
-
What kind of texture access should you use?
-