<?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>SDL | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/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>Fri, 05 Mar 2021 20:50:02 +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>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>New Tutorial on getting started with SDL</title>
		<link>https://learncgames.com/new-tutorial-on-getting-started-with-sdl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-tutorial-on-getting-started-with-sdl</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 07 Mar 2021 00:00:31 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[tutorials]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2838</guid>

					<description><![CDATA[<p>I had this tutorial pencilled in to do and it&#8217;s now done. It&#8217;s the old SDL rectangles program that was part of the eBook. I&#8217;ve modernised it a bit so the same file will now compile under either MSVC on Windows or VS Code/Clang on Linux without changes. I used the _WIN32 predefined macro so [&#8230;]</p>
The post <a href="https://learncgames.com/new-tutorial-on-getting-started-with-sdl/">New Tutorial on getting started with SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-medium wp-image-2836" src="https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-300x234.png" alt="SDL REctangles" width="300" height="234" srcset="https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-300x234.png 300w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-1024x798.png 1024w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-768x599.png 768w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles.png 1026w" sizes="(max-width: 300px) 100vw, 300px" />I had this tutorial pencilled in to do and it&#8217;s <a title="Link to Getting started with SDL tutorial" href="https://learncgames.com/getting-started-with-sdl-and-c/" target="_blank" rel="nofollow noopener">now done</a>. It&#8217;s the old SDL rectangles program that was part of the eBook. I&#8217;ve modernised it a bit so the same file will now compile under either MSVC on Windows or VS Code/Clang on Linux without changes.</p>
<p>I used the _WIN32 predefined macro so it compiles the call to Windows cod on Windows. Here&#8217;s an example:</p>
<pre><code class="language-c" data-line="">#ifdef _WIN32
		sprintf_s(buff, sizeof(buff), &quot;%10.6f&quot;, getElapsedTime(&amp;s));
#else
		snprintf(buff, sizeof(buff),&quot;%10.6f&quot;,diff(&amp;s));
#endif</code></pre>
<p>I do a similar thing with the path to SDL which is &#8220;SDL.h&#8221; on Windows but &#8220;SDL2/SDL.h&#8221; on Ubuntu. Writing code this way makes it  lot less of a hassle.</p>The post <a href="https://learncgames.com/new-tutorial-on-getting-started-with-sdl/">New Tutorial on getting started with SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2838</post-id>	</item>
		<item>
		<title>New tutorial on installing SDL on Linux</title>
		<link>https://learncgames.com/new-tutorial-on-installing-sdl-on-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-tutorial-on-installing-sdl-on-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 20 Dec 2020 00:00:33 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[install]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2109</guid>

					<description><![CDATA[<p>Well you might say, &#8220;Don&#8217;t many Linux distros have SDL installed so people can play games?&#8221; and the answer is yes but not the development files and headers, and that&#8217;s what this shows you how to do along with a simple program to test that you can compile and run. You&#8217;ll also need clang or [&#8230;]</p>
The post <a href="https://learncgames.com/new-tutorial-on-installing-sdl-on-linux/">New tutorial on installing SDL on Linux</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;:314,&quot;href&quot;:&quot;https:\/\/code.visualstudio.com&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206135041\/https:\/\/code.visualstudio.com\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-15 15:17:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 14:46:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 19:19:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-26 21:24:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 09:51:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 03:38:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 08:10:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 16:30:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 21:45:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 21:28:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 19:08:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 20:22:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 02:11:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 20:38:13&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-18 20:38:13&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignleft size-medium wp-image-2101" src="https://learncgames.com/wp-content/uploads/2020/12/sdldemo-300x236.png" alt="SDl Demo program" width="300" height="236" srcset="https://learncgames.com/wp-content/uploads/2020/12/sdldemo-300x236.png 300w, https://learncgames.com/wp-content/uploads/2020/12/sdldemo.png 450w" sizes="(max-width: 300px) 100vw, 300px" />Well you might say, &#8220;<em>Don&#8217;t many Linux distros have SDL installed so people can play games?</em>&#8221; and the answer is yes but not the development files and headers, and that&#8217;s what this shows you how to do along with a simple program to test that you can compile and run.</p>
<p>You&#8217;ll also need clang or gcc installed but as you can do that with a simple <strong>sudo apt install clang</strong>, it&#8217;s hardly worth a tutorial on its own.</p>
<p>However you also need to install VS Code and the C/C++ extension. Go to the <a title="Link to Visual Studio Code website" href="https://code.visualstudio.com/" target="_blank" rel="noopener">VS Code website</a>, download the Linux x64 version and double click on it to install it. After that from a terminal type <strong>code a</strong>nd it&#8217;ll appear. You then need to select extensions (5<em>th icon down the left hand side</em>) and pick the Microsoft C/C++ extension and install it.</p>
<p>I&#8217;ve added a new tutorial on the Tutorials page <a title="Link to tutortial on how to install SDL on Linux" href="https://learncgames.com/how-to-install-sdl-on-linux/" target="_blank" rel="nofollow noopener">How to Install SDL on Linux</a>. That includes a link to a demo file (<em>its just above the screenshot</em>) containing all three source code files and four VS Code configuration files for VS Code.</p>
<p>This program is almost identical to the asteroids_ch25 file (<em>it draws lots of random size and colour rectangles on screen</em>) but has been upgraded for <strong>Clang 10</strong> and also what looks like a bug with search paths. There&#8217;s an extra line in Tasks.json to include the path to the SDL2 header files or you&#8217;ll get a <strong>can&#8217;t find a particular SDL header</strong> error when you compile.</p>
<p>Building code with VS Code is easy to understand once you &#8220;get&#8221; how the <strong>Folder</strong> works. I always keep the .vscode folder in there with the four C/C++ JSON configuration files and all source for that whatever it is you are compiling.  In the screenshot below (<em>from WinSCP</em>), you can see the path is <strong>/home/david/Projects/Examples</strong> and it contains the .vscode folder the three source files and demo which is the compiled code.  In VS Code I opened Examples as the <strong>Folder</strong>.</p>
<p><img decoding="async" class="alignleft size-full wp-image-2111" src="https://learncgames.com/wp-content/uploads/2020/12/vscode-folder.png" alt="VS Code Folder" width="460" height="166" srcset="https://learncgames.com/wp-content/uploads/2020/12/vscode-folder.png 460w, https://learncgames.com/wp-content/uploads/2020/12/vscode-folder-300x108.png 300w" sizes="(max-width: 460px) 100vw, 460px" /></p>
<p>&nbsp;</p>
<p>The .vscode folder is greyed out because the . means it&#8217;s normally hidden.</p>The post <a href="https://learncgames.com/new-tutorial-on-installing-sdl-on-linux/">New tutorial on installing SDL on Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2109</post-id>	</item>
		<item>
		<title>SDL-TTF now on Raspberry Pi</title>
		<link>https://learncgames.com/sdl-ttf-now-on-raspberry-pi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sdl-ttf-now-on-raspberry-pi</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 11 Dec 2020 00:00:43 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[ttf]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2037</guid>

					<description><![CDATA[<p>I eventually got the Windows SDL vs TTF comparison program converted to run on Raspberry-pi, after wrestling with VS Code&#8217;s Folder. Get it wrong and you can waste hours trying to get it to compile and link. I originally set the Folder (VS Code&#8217;s way of managing projects) to the pi/Projects folder (which contained both [&#8230;]</p>
The post <a href="https://learncgames.com/sdl-ttf-now-on-raspberry-pi/">SDL-TTF now on Raspberry Pi</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;:14,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250213114627\/https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:14&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:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:30&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:24&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:10&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:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:49&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 19:29:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 21:51:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 22:18:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 22:18:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 22:20:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 07:27:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-2038" src="https://learncgames.com/wp-content/uploads/2020/12/pi-screenshot.png" alt="Raspberry Pi screenshot" width="450" height="264" srcset="https://learncgames.com/wp-content/uploads/2020/12/pi-screenshot.png 450w, https://learncgames.com/wp-content/uploads/2020/12/pi-screenshot-300x176.png 300w" sizes="auto, (max-width: 450px) 100vw, 450px" />I eventually got the <a title="Link to comparison of SDL vs TTF fonts" href="https://learncgames.com/timing-of-sdl-vs-ttf-fonts/" target="_blank" rel="nofollow noopener noreferrer">Windows SDL vs TTF comparison</a> program converted to run on Raspberry-pi, after wrestling with VS Code&#8217;s Folder. Get it wrong and you can waste hours trying to get it to compile and link. I originally set the Folder (<em>VS Code&#8217;s way of managing projects</em>) to the <strong>pi/Projects</strong> folder (<em>which contained both asteroids and sdlttf folders</em>) but eventually I sussed it and set <strong>sdlttf</strong> as my Folder.  The login user is pi and so the pi folder is my home folder. I created the Projects folder under it.</p>
<p>This time the home brewed print routine (<strong>print</strong>) took 28x as long as the SDL_ttf compared to 14x on Windows. I used the same text.png and font.ttf files. The times are in the Window caption and read (<em>for those with poor contrast</em>) <strong>sdl: 35538.574 ttf: 1235.630.</strong> These times are the microsecond times to draw the strings 100x.</p>
<p>Changes were fairly minimal. I changed the <strong>fopen_s</strong> to <strong>fopen (</strong><em>used for error logging</em><strong>) </strong> and changed the paths to the two font files. The other change was in the timing which used the Linux versions of <strong>hr_time.h/.c</strong> and called the <strong>diff</strong>() function instead of <strong>GetElapsedTime</strong>().</p>
<p>I&#8217;ve zipped up the source file (<strong>sdlttf.c)</strong> plus timing files and JSON config files for VS Code in the sdlttf_pi.zip file and put it in the LearnConLinux repository on <a title="Link to LearnCOnLinux repository on GitHub" href="https://github.com/David-H-Bolton/LearnCOnLinux" target="_blank" rel="nofollow noopener noreferrer">GitHub</a>.</p>
<p>Note I created a projects folder then sdlttf under that. The paths in <strong>tasks.json</strong> reflect this. To build this you&#8217;ll need <strong>libsdl2-dev,libsdl2_image_dev</strong> and <strong>libsdl2-ttf-dev</strong> installed. I used clang version 7 (<em>the default installed on pi when you do <strong>sudo apt install clang</strong></em>) but I imagine gcc should also build it without any problems.</p>
<p>This matches my conclusions from running the virtually identical Windows version. The sdlttf way is way faster for prerendered strings than my print routine which just blits the characters out of the font bitmap one by one.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/sdl-ttf-now-on-raspberry-pi/">SDL-TTF now on Raspberry Pi</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2037</post-id>	</item>
		<item>
		<title>Other ways to time code</title>
		<link>https://learncgames.com/other-ways-to-time-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=other-ways-to-time-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 15 Mar 2020 00:00:28 +0000</pubDate>
				<category><![CDATA[SDL]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[time]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=125</guid>

					<description><![CDATA[<p>As well as the hr_time code that I used in discussion of sdldemo SDL itself provides some other ways to time. If you are happy with millisecond level accuracy of timing, just call this function which returns an unsigned 32-bit (i.e. 0- 4 billion) giving the number of milliseconds since the SDL library was initialised. [&#8230;]</p>
The post <a href="https://learncgames.com/other-ways-to-time-code/">Other ways to time code</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;:819,&quot;href&quot;:&quot;https:\/\/pixabay.com\/photos\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:820,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:821,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29#SDL_GetTicks-1&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20210917191444\/http:\/\/wiki.libsdl.org\/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL3\/SDL_GetTicks&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:822,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20220524122630\/http:\/\/wiki.libsdl.org\/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:37:15&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-02-06 19:37:15&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:823,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20220524111032\/http:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=(\\bCategoryTimer\\b)|(CategoryEnum)|(CategoryStruc)&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_129" aria-describedby="caption-attachment-129" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="wp-image-129 size-medium" src="https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-300x200.jpg" alt="Stop Watch photo from Pixabay" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-1024x682.jpg 1024w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-768x512.jpg 768w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280.jpg 1280w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-129" class="wp-caption-text">Image by <a href="https://pixabay.com/photos/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110">Free-Photos</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110">Pixabay</a></figcaption></figure>
<p>As well as the hr_time code that I used in <a href="https://learncgames.com/the-joys-of-linux-c-compilation/" target="_blank" rel="noopener noreferrer">discussion of sdldemo</a> SDL itself provides some other ways to time. If you are happy with millisecond level accuracy of timing, just call this function which returns an unsigned 32-bit (i.e. 0- 4 billion) giving the number of milliseconds since the SDL library was initialised.</p>
<p><a href="http://wiki.libsdl.org/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29#SDL_GetTicks-1" target="_blank" rel="noopener noreferrer">SDL_GetTicks()</a></p>
<p>The link goes to the Wiki page on libsdl.org  for SDL_GetTicks().</p>
<p>As always, call it twice, once to get the start value and once to get the stop then subtract start from stop to get the elapsed time in milliseconds..</p>
<p>For some operations this can be easier to use. A frame is 16.666666 milliseconds so if your code runs in less than 16 milliseconds, it&#8217;s not going to cause problems. In my original Windows code, it ran is a fraction of a millisecond. Compiled C code really is fast and helped because the GPU is doing most of the donkey work!</p>
<p>There&#8217;s also a higher accuracy timer. This I guess is just a wrapper round the system call I call in hr_time.</p>
<p id="CA-pygments_173" dir="ltr" lang="en"><a href="http://wiki.libsdl.org/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29" target="_blank" rel="noopener noreferrer"><span class="line"><span class="n">Uint64</span> <span class="n">SDL_GetPerformanceCounter</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span></span></a><br />
Which I haven&#8217;t used yet but which I guess returns a processor clock count. To measure time you need to call it twice (start and stop values as before) then divide by the frequency value returned from a call to</p>
<p id="CA-pygments_245" dir="ltr" lang="en"><a href="http://wiki.libsdl.org/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29" target="_blank" rel="noopener noreferrer"><span class="line"><span class="n">Uint64</span> <span class="n">SDL_GetPerformanceFrequency</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span></span></a></p>
<p dir="ltr" lang="en">My computer returns a clock frequency of 3,500,000,000 clocks per second but the actual value is irrelevant just divide ((stop &#8211; start)/ frequency) to get the elapsed time in seconds.</p>
<p dir="ltr" lang="en">The post <a href="https://learncgames.com/other-ways-to-time-code/">Other ways to time code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">125</post-id>	</item>
		<item>
		<title>SDL on Linux</title>
		<link>https://learncgames.com/sdl-on-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sdl-on-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 08 Mar 2020 00:00:53 +0000</pubDate>
				<category><![CDATA[SDL]]></category>
		<category><![CDATA[Source code]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=80</guid>

					<description><![CDATA[<p>In my forthcoming ebook, which is the Linux equivalent of the first one I use Visual Studio Code (VSC) as the IDE to develop along with the Microsoft C/C++ extension. I&#8217;m using the SDL2 library for fast graphics and Clang as the compiler. Thankfully Microsoft have documented most of the process of using Clang with [&#8230;]</p>
The post <a href="https://learncgames.com/sdl-on-linux/">SDL on Linux</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;:538,&quot;href&quot;:&quot;http:\/\/libsdl.org&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205192603\/https:\/\/www.libsdl.org\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 15:57:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 02:51:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 09:33:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 18:09:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 06:45:36&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:04:30&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 01:13:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 01:47:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 09:00:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 09:18:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 17:14:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-25 02:02:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 15:58:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-01 03:07:18&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 04:19:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 10:54:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 09:47:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-19 18:12:41&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 18:12:41&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:825,&quot;href&quot;:&quot;https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206070134\/https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:47:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 23:31:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-14 14:08:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 11:37:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 22:40:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:04:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 22:12:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 23:44:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 08:11:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 15:27:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-23 03:49:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 15:06:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 15:26:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 17:07:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 04:19:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 10:54:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 09:47:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-19 18:12:41&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 18:12:41&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]'></div>
<p>In my forthcoming ebook, which is the Linux equivalent of the first one I use Visual Studio Code (VSC) as the IDE to develop along with the Microsoft C/C++ extension. I&#8217;m using the <a href="http://libsdl.org" target="_blank" rel="noopener noreferrer">SDL2</a> library for fast graphics and Clang as the compiler.</p>
<p>Thankfully Microsoft have documented most of the process of <a href="https://code.visualstudio.com/docs/cpp/config-clang-mac" target="_blank" rel="noopener noreferrer">using Clang with VSC</a>, albeit on a Mac. I&#8217;m using Ubuntu but it&#8217;s mostly the same.</p>
<p>Before I could configure SDL I had to add it and I never realised about <strong>apt-cache</strong> on Ubuntu (and Debian). The command</p>
<pre>apt- cache search libsdl2

<span style="font-family: 'Saira Semi Condensed', sans-serif;">Outputs this, showing what's available.</span>
</pre>
<pre>libsdl2-2.0-0 - Simple DirectMedia Layer
libsdl2-dev - Simple DirectMedia Layer development files
libsdl2-doc - Reference manual for libsdl2
libsdl2-gfx-1.0-0 - drawing and graphical effects extension for SDL2
libsdl2-gfx-dev - development files for SDL2_gfx
libsdl2-gfx-doc - documentation files for SDL2_gfx
libsdl2-image-2.0-0 - Image loading library for Simple DirectMedia Layer 2, libraries
libsdl2-image-dev - Image loading library for Simple DirectMedia Layer 2, development files
libsdl2-mixer-2.0-0 - Mixer library for Simple DirectMedia Layer 2, libraries
libsdl2-mixer-dev - Mixer library for Simple DirectMedia Layer 2, development files
libsdl2-net-2.0-0 - Network library for Simple DirectMedia Layer 2, libraries
libsdl2-net-dev - Network library for Simple DirectMedia Layer 2, development files
libsdl2-ttf-2.0-0 - TrueType Font library for Simple DirectMedia Layer 2, libraries
libsdl2-ttf-dev - TrueType Font library for Simple DirectMedia Layer 2, development files

</pre>
<p>So a quick</p>
<pre>sudo apt-get install libsdl2-dev</pre>
<p>Installed 73 MB of files including all the header files. I used the files app to search for SDL files and it found a folder SDL2 in <strong>/usr/include</strong>.</p>
<p>And all I needed in my program was</p>
<p>[perl]</p>
<p>#include &lt;SDL2/SDL.h&gt;</p>
<p>[/perl]</p>
<p>And I had to add <strong>&#8220;/usr/include/SDL2/&#8221; </strong>into the includePath section of c_cpp_properties.json and &#8220;-lSDL2&#8221; into the args section of tasks.json. These two JSON files are included in C/C++ projects in VSC.</p>
<p>At that point I could compile and run my first SDL program on Ubuntu. It throws 10,000 random sized coloured rectangles onto the screen</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-84 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/sdldemo-300x231.png" alt="The first SDL demo program" width="300" height="231" srcset="https://learncgames.com/wp-content/uploads/2020/03/sdldemo-300x231.png 300w, https://learncgames.com/wp-content/uploads/2020/03/sdldemo.png 550w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/sdl-on-linux/">SDL on Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">80</post-id>	</item>
	</channel>
</rss>
