<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ttf.sdl | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/ttf-sdl/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sat, 05 Dec 2020 11:50:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>ttf.sdl | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Timing of SDL vs TTF fonts</title>
		<link>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=timing-of-sdl-vs-ttf-fonts</link>
					<comments>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/#comments</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 05 Dec 2020 00:00:28 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[timing]]></category>
		<category><![CDATA[ttf.sdl]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1975</guid>

					<description><![CDATA[<p>So I got round to writing that SDL vs TTF timing comparison. However I had to make a few assumptions. The program was written for Windows but easily converts to Linux (apart from the timing code but I did that back in March for Linux) is about 250 lines long. I&#8217;ve uploaded it to GitHub, [&#8230;]</p>
The post <a href="https://learncgames.com/timing-of-sdl-vs-ttf-fonts/">Timing of SDL vs TTF fonts</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:13,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250807013721\/https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 18:24:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:16:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 22:22:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 04:17:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:17:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 04:22:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 04:38:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 08:48:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 09:17:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 10:18:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:14:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 16:38:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 19:05:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 22:49:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 04:18:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 04:19:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 09:53:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 10:17:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 13:35:54&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:342,&quot;href&quot;:&quot;https:\/\/www.libsdl.org\/projects\/SDL_ttf&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260203013147\/https:\/\/www.libsdl.org\/projects\/SDL_ttf\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:11:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 08:45:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 09:27:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 20:03:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 12:06:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 15:37:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:34:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 17:50:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 07:52:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 21:40:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 22:50:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 06:25:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 16:36:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 19:27:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 21:41:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 01:44:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 13:20:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 00:37:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 06:01:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 08:55:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 17:40:48&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 17:40:48&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-1976" src="https://learncgames.com/wp-content/uploads/2020/12/timings.png" alt="Timings" width="649" height="325" srcset="https://learncgames.com/wp-content/uploads/2020/12/timings.png 649w, https://learncgames.com/wp-content/uploads/2020/12/timings-300x150.png 300w" sizes="(max-width: 649px) 100vw, 649px" />So I got round to writing that SDL vs TTF timing comparison. However I had to make a few assumptions. The program was written for Windows but easily converts to Linux (<em>apart from the timing code but I did that <a title="Compiling Linux timing code" href="https://learncgames.com/that-clang-c-compilation/" target="_blank" rel="nofollow noopener noreferrer">back in March</a> for Linux</em>) is about 250 lines long. I&#8217;ve uploaded it to <a title="Link to LearnC on GitHub" href="https://github.com/David-H-Bolton/LearnC" target="_blank" rel="nofollow noopener noreferrer">GitHub</a>, and the zip file contains not only the VS 2019 project and source but all the SDL2 dlls plus a free font MONOFONT.TTF (renamed to font.ttf) and test.png which is the bitmap font as a .png file.</p>
<p>Note you&#8217;ll have to edit the <strong>sdlttf.c</strong> file and change the paths to load the font .png and ttf files in lines 96 and 97.</p>
<p>I&#8217;d never used <a title="Link to SDL_ttf on libsdl.org" href="https://www.libsdl.org/projects/SDL_ttf/" target="_blank" rel="nofollow noopener noreferrer">SDL_ttf</a> before though it worked out easy enough. There are three levels of TTF &#8211; fast, not so fast and slow but pretty. I went for the fastest setting. The SDL text is in red and the TTF in yellow and are roughly the same height about 30 points.</p>
<p>If you read the caption you&#8217;ll see that my bitmap font drawing (I call it SDL) is nearly 14 x slower than TTF. In my code I prerendered the phrase &#8220;Sphinx of black quartz, judge my vow&#8221; which has all 26 letters a-z but is shorter than standard phrase &#8220;the lazy quick fox&#8230;&#8221;.</p>
<p>SDL_ttf renders the phrase into a <strong>surface</strong> which is a memory structure in RAM. Calling <strong>SDL_CreateTextureFromSurface</strong> (line 188) creates a texture from this (it copies the bitmap from RAM to VRAM) and so in my program I was just blitting this texture to the screen. The SDL printing in the <strong>print</strong> function (Line 157) gets each character, and calls <strong>printch</strong> (line 143) which works out where in the <strong>textFont</strong> texture that character and blits it. I&#8217;m guessing the overhead of blitting individual characters is what makes it so much slower.</p>
<p>So for fixed phrases where you can prerender the surface and texture, SDL_ttf is way faster and more flexible with colour and to a certain extent size. Colour is set at runtime while size is set when you prerender the font into the surface. If you want different sizes then you need multiple surfaces and corresponding textures for each size. Things like say a score would be a bit slower because it would need to be rendered each time and copied to a texture or prerender all 10 digits and have a texture for each and draw it much like the print method does.</p>
<p>The program is a little rough in places; it was thrown together over three nights.</p>The post <a href="https://learncgames.com/timing-of-sdl-vs-ttf-fonts/">Timing of SDL vs TTF fonts</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://learncgames.com/timing-of-sdl-vs-ttf-fonts/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1975</post-id>	</item>
	</channel>
</rss>
