- Hands-On Game Development with WebAssembly
- Rick Battagline
- 263字
- 2021-06-24 13:41:07
Using the WebAssembly virtual filesystem
The next few lines will open up the TrueType font file in the virtual filesystem, and render it to SDL_Texture, which can be used to render to the canvas:
font = TTF_OpenFont( FONT_FILE, FONT_SIZE );
SDL_Color font_color = {255, 255, 255, 255 }; // WHITE COLOR
SDL_Surface *temp_surface = TTF_RenderText_Blended( font, MESSAGE,
font_color );
texture = SDL_CreateTextureFromSurface( renderer, temp_surface );
SDL_FreeSurface( temp_surface );
In the first line of the preceding code, we open the TrueType font by passing in the location of the file in the WebAssembly virtual filesystem, defined at the top of the program. We also need to specify the font's point size, which was defined as 16 at the top of the program as well. The next thing we do is create an SDL_Color variable that we will use for the font. This is a RGBA color, and we have all values set to 255 so that it is a fully opaque white color. After we have done this, we will need to render the text to a surface using the TTF_RenderText_Blended function. We pass the TrueType font we opened a few lines earlier, the MESSAGE, which was defined as "HELLO SDL!", near the top of the program, and the font color, defined as white. Then, we will create a texture from our surface and free the surface memory we have just allocated. You should always free the memory from your surface pointers immediately after using them to create a texture, as once you have your textures the surfaces are no longer needed.
- Intel FPGA/CPLD設(shè)計(jì)(基礎(chǔ)篇)
- Python GUI Programming:A Complete Reference Guide
- Intel FPGA/CPLD設(shè)計(jì)(高級(jí)篇)
- 嵌入式系統(tǒng)設(shè)計(jì)教程
- 從零開(kāi)始學(xué)51單片機(jī)C語(yǔ)言
- Learning Stencyl 3.x Game Development Beginner's Guide
- OUYA Game Development by Example
- 微軟互聯(lián)網(wǎng)信息服務(wù)(IIS)最佳實(shí)踐 (微軟技術(shù)開(kāi)發(fā)者叢書)
- 筆記本電腦應(yīng)用技巧
- Hands-On Artificial Intelligence for Banking
- VMware Workstation:No Experience Necessary
- 基于S5PV210處理器的嵌入式開(kāi)發(fā)完全攻略
- The Machine Learning Workshop
- 電腦主板維修技術(shù)
- 施耐德M241/251可編程序控制器應(yīng)用技術(shù)