官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 韶关市| 华阴市| 精河县| 新巴尔虎右旗| 雷州市| 商丘市| 梅河口市| 鄄城县| 东乌珠穆沁旗| 杭锦旗| 庆元县| 彰化县| 镇远县| 嘉祥县| 武乡县| 巴南区| 屏南县| 永济市| 晋宁县| 微博| 万山特区| 靖宇县| 简阳市| 五家渠市| 依安县| 台州市| 蒙阴县| 灵山县| 呼玛县| 监利县| 勐海县| 正宁县| 兰州市| 买车| 福州市| 拜泉县| 德令哈市| 屯昌县| 什邡市| 四会市| 高州市|