<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Posts on ambit&#39;s projects</title>
        <link>http://ambits.org/posts/</link>
        <description>Recent content in Posts on ambit&#39;s projects</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
        <lastBuildDate>Fri, 03 Sep 2021 00:00:00 +0000</lastBuildDate>
        <atom:link href="http://ambits.org/posts/index.xml" rel="self" type="application/rss+xml" />
        
        <item>
            <title>SDL2 example Android</title>
            <link>http://ambits.org/posts/2021/09/sdl2-example-android/</link>
            <pubDate>Fri, 03 Sep 2021 00:00:00 +0000</pubDate>
            
            <guid>http://ambits.org/posts/2021/09/sdl2-example-android/</guid>
            <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;These instructions will focus on Linux / CMake but it can be easily adopted when using Android Studio on other platforms like Windows and OSX.
I have used [Allegro] for many years but recently I decided to switch to &lt;a href=&#34;https://www.libsdl.org&#34;&gt;SDL2&lt;/a&gt; because it&amp;rsquo;s a somewhat lower
level library and has more cross platform support for some applications such as bluetooth &amp;amp; USB name a few. I usually develop under
Linux whenever I can and I needed to port my old graphics engine to the Android platform. Since my engine already was developed for
cross platform - and has been ported to Windows and OSX - I thought Android should be fairly simple. Well as it turns out I was
in for a surprise. I like difficult challanges as much as any other C++ developer but Android Studio + SDL2 was more like being
in the passenger seat of destruction derby. I admit I tried doing things the hard way (the right way in my view): use only command
line tools and the cross compiler. But not knowing about the pitfalls of Android build system I had to resort to for now using
Android Studio, sigh. So this guide describes how to build a simple SDL2 project with the latest Android Studio 2020.3.2.
I will focus on the pitfalls I ran into as the SDL2 android docs are missing some details.&lt;/p&gt;</description>
            <content type="html"><![CDATA[<h2 id="introduction">Introduction</h2>
<p>These instructions will focus on Linux / CMake but it can be easily adopted when using Android Studio on other platforms like Windows and OSX.
I have used [Allegro] for many years but recently I decided to switch to <a href="https://www.libsdl.org">SDL2</a> because it&rsquo;s a somewhat lower
level library and has more cross platform support for some applications such as bluetooth &amp; USB name a few. I usually develop under
Linux whenever I can and I needed to port my old graphics engine to the Android platform. Since my engine already was developed for
cross platform - and has been ported to Windows and OSX - I thought Android should be fairly simple. Well as it turns out I was
in for a surprise. I like difficult challanges as much as any other C++ developer but Android Studio + SDL2 was more like being
in the passenger seat of destruction derby. I admit I tried doing things the hard way (the right way in my view): use only command
line tools and the cross compiler. But not knowing about the pitfalls of Android build system I had to resort to for now using
Android Studio, sigh. So this guide describes how to build a simple SDL2 project with the latest Android Studio 2020.3.2.
I will focus on the pitfalls I ran into as the SDL2 android docs are missing some details.</p>
<h2 id="install-android-studio">Install Android Studio</h2>
<p>I won&rsquo;t go into how to install Android Studio as there are a few good tutorials online not to mention the
<a href="https://developer.android.com/studioinstall">Android documentation</a>.</p>
<p>Here is the download <a href="https://developer.android.com/studio">site</a>.</p>
<p>Don&rsquo;t forget that afterwards you will need to install the <a href="https://developer.android.com/studio/projects/install-ndk">Android NDK</a>
as our code is in C/C++ and without it we can only write Java/Kotlin, which would make us all very sad developers indeed&hellip;</p>
<p>You want to select from the SDK manager-&gt;SDK Tools-&gt;CMake to be sure.</p>
<h2 id="create-a-virtual-device-via-avd">Create a virtual device via AVD</h2>
<p>There is an AVD(Virtual Device Manager) built into Android Studio that let&rsquo;s you create devices if you choose
to use the emulator. Just click on the AVD icon on the right top corner to bring up the manager and follow the wizard
to create a new device.</p>
<p><a href="https://developer.android.com/studio/run/emulator">AVD docs</a></p>
<h2 id="download-sdl2hello">Download SDL2Hello</h2>
<ol>
<li>Download or clone my <a href="https://github.com/ambitslix/SDL2Hello.git">SDL2Hello</a> example code from github.</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$git clone git@github.com:ambitslix/SDL2Hello.git
</span></span></code></pre></div><p>Or download the zip/tar.gz and extract it to a convenient location.</p>
<ol start="2">
<li>
<p>Download or clone <a href="https://github.com/libsdl-org/SDL">SDL</a>.</p>
</li>
<li>
<p>Download or clone <a href="https://github.com/libsdl-org/SDL_image">SDL_image</a>.</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Clone both</span>
</span></span><span style="display:flex;"><span>$git clone https://github.com/libsdl-org/SDL
</span></span><span style="display:flex;"><span>$git clone https://github.com/libsdl-org/SDL_image
</span></span></code></pre></div><p>Now we will symlink SDL and SDL_image into our <strong>SDL2Hello/app/src/main/cpp</strong> folder so our CMakeLists.txt will
find. You can alternately clone both repos inside that folder as well. But I prefer symlinks as
I don&rsquo;t want to clutter my project repo with other git repos inside it. Git Submodules are a nightmare, but that&rsquo;s
a topic of another post&hellip;</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Create symlinks</span>
</span></span><span style="display:flex;"><span>ln -s /path/SDL /path/SDL2Hello/app/src/main/cpp
</span></span><span style="display:flex;"><span>ln -s /path/SDL_image /path/SDL2Hello/app/src/main/cpp
</span></span></code></pre></div><p>Now you should be able to open the folder SDL2Hello from Androd Studio via File-&gt;Open. And SDL and SDL_image
should be inside app/src/main/cpp.</p>
<h2 id="build--run-sdl2hello">Build + Run SDL2Hello</h2>
<p>Android Studio will - after you open the project - automatically configure it. Then you can build it from the menu.
If all goes well you should see in the build log at the bottom that that the build succeded.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>BUILD SUCCESSFUL in 56s
</span></span></code></pre></div><p>Now you can try to run the app in the emulated device, and you should see the folllowing:</p>
<p><img alt="screnshot" src="/images/SDL2Hello-screenshot.png"></p>
<h2 id="pitfalls">PitFalls</h2>
]]></content>
        </item>
        
        <item>
            <title>Installing latest Hugo</title>
            <link>http://ambits.org/posts/2021/08/installing-latest-hugo/</link>
            <pubDate>Mon, 30 Aug 2021 00:00:00 +0000</pubDate>
            
            <guid>http://ambits.org/posts/2021/08/installing-latest-hugo/</guid>
            <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;More often than not you need the latest version of sofware package for development. Here I cover how to install the latest version of &lt;a href=&#34;https://github.com/gohugoio&#34;&gt;hugo&lt;/a&gt;, a great website builder that&amp;rsquo;s written in the GO language. When you install golang(GO) from the command line via apt or yum it will be a version from your &lt;strong&gt;Linux&lt;/strong&gt; software repo, but this version may not suffice for building the latest version of hugo and other cutting edge features. So&amp;hellip;&lt;/p&gt;</description>
            <content type="html"><![CDATA[<h2 id="introduction">Introduction</h2>
<p>More often than not you need the latest version of sofware package for development. Here I cover how to install the latest version of <a href="https://github.com/gohugoio">hugo</a>, a great website builder that&rsquo;s written in the GO language. When you install golang(GO) from the command line via apt or yum it will be a version from your <strong>Linux</strong> software repo, but this version may not suffice for building the latest version of hugo and other cutting edge features. So&hellip;</p>
<h2 id="uninstall-existing-go">Uninstall existing GO</h2>
<p>First I recommend removing existing installed version of GO.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># For Ubuntu/Debian based distros</span>
</span></span><span style="display:flex;"><span>$sudo apt purge golang -y
</span></span><span style="display:flex;"><span>$sudo apt autoremove -y
</span></span><span style="display:flex;"><span><span style="color:#75715e"># For Fedora/RedHat based distros</span>
</span></span><span style="display:flex;"><span>$sudo dnf purge golang -y
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Make sure go is gone :)</span>
</span></span><span style="display:flex;"><span>$which go
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Should return nothing</span>
</span></span><span style="display:flex;"><span>$
</span></span></code></pre></div><h2 id="install-latest-go-from-go-distribution">Install latest GO from GO distribution</h2>
<p>We install the latest GO directly from their release site &ldquo;<a href="https://golang.org/dl%22">https://golang.org/dl"</a>.
Choose the latest version. For me it was 17 at the time.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$wget -c https://golang.org/dl/go1.17.linux-amd64.tar.gz
</span></span><span style="display:flex;"><span>$tar xvzf go1.17.linux-amd64.tar.gz
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Move GO to a convenient location of your choice</span>
</span></span><span style="display:flex;"><span>$sudo mv go /opt/local
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Append this to the end of your ~/.bashrc</span>
</span></span><span style="display:flex;"><span>export PATH<span style="color:#f92672">=</span>$PATH:/opt/local/go/bin:$HOME/go/bin
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Adding $HOME/go/bin to .bashrc because when GO builds and installs hugo</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># it will be installed into $HOME/go by default</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># You can change where GO installs software by setting GOPATH</span>
</span></span><span style="display:flex;"><span>$source ~/.bashrc
</span></span><span style="display:flex;"><span>$which go
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Should return</span>
</span></span><span style="display:flex;"><span>$/opt/local/bin/go
</span></span><span style="display:flex;"><span>$go version
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Should return</span>
</span></span><span style="display:flex;"><span>$go version go1.17 linux/amd64
</span></span></code></pre></div><h2 id="build--install-hugo">Build + Install Hugo</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$git clone https://github.com/gohugoio
</span></span><span style="display:flex;"><span>$cd hugo
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Build and install the Extended hugo</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># needed by some modern themes</span>
</span></span><span style="display:flex;"><span>$go install --tags extended
</span></span><span style="display:flex;"><span>$hugo version
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Should return similar</span>
</span></span><span style="display:flex;"><span>$hugo v0.88.0-DEV+extended linux/amd64 BuildDate<span style="color:#f92672">=</span>unknown
</span></span></code></pre></div><p>You are now ready do download some themes and build your website.
For more info check <strong>hugo</strong> docs.
This site uses the <a href="https://github.com/rhazdon/hugo-theme-hello-friend-ng">hello-friend-ng</a>
theme.</p>
]]></content>
        </item>
        
    </channel>
</rss>
