Month: June 2020

How to find files in Ubuntu

How to find files in Ubuntu

In this I’m looking for the SDL2 header files. These are installed when you install libsdl2-dev as we saw yesterday.

While you can do it from a terminal with the find command, I find it easier to do it from the GUI. We need the Files utility which you get by clicking on this icon on the left toolbar. files-icon Now click Other Locations on the left and you should see something like this.

On This computer
Click Computer. This will let you search through the entire Linux file tree.

Click on the magnifying glass icon and in the text box that appears type in sdl2 and press enter. It will spend a few seconds or minutes searching and then find a number of files/folders.

The first result was SDL2 and the usr/include is a big clue. Double-click on this and it will open on a folder full of header files!That’s what we want.SDL2 Folder

 

When you are configuring gcc/clang and want to add paths for include files like SDL2, it’s important to know where those files are located.

Publishing excerpts from my 2nd ebook

Publishing excerpts from my 2nd ebook

learn C Games Book coverI’m changing horses in midstream so this won’t appear as it’s been done so far. Rather than let it go to waste, I’ll be publishing it in parts here. My next book will be Learn C Games Programming on the Raspberry Pi.

Installing SDL2 on Ubuntu/Debian

The SDL2 library is an open source library available from the libsdl.org website. However in Ubuntu it’s fairly easy to install. We do need not just the binary files but the headers so we can include them.
On Ubuntu (and Debian system) the apt tool maintains a cache of files. You can search these from a terminal with this command.
apt-cache search libsdl2
On my PC this output.
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

We’ll eventually need libsdl2, libsdl2-image for graphics support and libsdl2-mixer for sounds. We’ll also need libsdl2-dev so let’s start with that. Run this command . It will probably ask for your password.

sudo apt-get install libsdl2-dev

That downloaded and installed 73 MB of files.   More to follow

A large collection of ARM links

A large collection of ARM links

Circit board
From Pixabay

ARM being the CPU brand inside Raspberry Pis. This is a collection of talks and links to articles about the ARM architecture, concurrency, performance and way too much other stuff to list. There’s a lot in there and I defy anyone with the vaguest interest not to find something of interest.

I’m not a hardware person myself, but dipping into stuff like this can yield benefits. Remember the CPU in the Pi 4B has four cores. If you are writing software that just runs one one thread then it’s like driving a car with a four cylinder engine but its only firing on one. And if you manage to write software to use all four cores, do you know how to avoid false sharing? (Yes it’s a thing!)

 

 

 

Added the sources of another game

Added the sources of another game

Basic Computer games bookThis was a text mode game, my idea being to do something like the old Star Trek BASIC game but better. I called it Star Empires and it’s on GitHub, just follow the link to GitHub on the C Games sources link.

The zip file includes both C and a C++ version. Both will compile with Visual C++ 2019 Community edition. There is a minor compile error, a = that should be == in the C++ source. I ill get round to fixing it and uploading a replacement.

I do get a bit of pleasure (more like an exercise in masochism!) converting old BASIC games to C. I’m looking at the two Creative Computing books (and while 95% of the games are not exactly great (well lets be generous and say they were good 45 years ago!) but there’s one or two that might be worth the effort! I bought these in 1982 lost those and then bought them a few years back again.

Plus when you think how the games industry has matured since the late 70s and 80s, and many of those early programmers will have cut their teeth on games like that before learning more advanced stuff, so  lets not be too harsh!

 

Raspberry Pi – a couple more tips

Raspberry Pi – a couple more tips

Cogs
Image by Arek Socha from Pixabay

I have my Pi networked via a switch to my main (Windows) PC. I use WinSCP or my PC for copying files both ways but it means I’m not using the Pi for periods of 15 or 20 minutes.

Unfortunately the default display timeout on the Pi is 10 minutes. It’s not a bad thing but I decided I wanted an hour.

This fix seems to work. It came from this page on the Raspberry Pi forums.  To save you the effort of reading through a few different suggestions, the one that worked for me is this in a terminal (From the answer at 1.02 am). The 3600 is the time period in seconds in case you hadn’t guessed!

Apparently there are two timeout mechanism hence two commands are needed.

xset s 3600
xset dpms 3600 3600 3600

You can view the settings with

xset q

However to make these settings permanent, you need to edit the file:

sudo nano /etc/xdg/lxsession/LXDE/autostart

That way they are set at boot time.

Note. I’m not really a fan of nano. From Ubuntu I’ve used gedit quite a bit and it is a visual full-screen editor, not line by line like nano. Yeah you could use VS Code if it were open but then on files where you have to use sudo, it’s easier to use gedit.

So

sudo apt install gedit

will install it. Just gedit or sudo gedit (for those awkward files!)

 

 

 

Bit of an oddity with VS Code

Bit of an oddity with VS Code

When I first started using it, the C++ extension, and configuring for C++, I got a tasks.json one which was suited for gcc, but recently when I install it, (and the C/C++ Extension for Visual Studio Code, the only choices seem to be these. What happened to the the ones for clang/gcc? The one on the right is what I’m expecting. Even with a C/C++ file open as the instructions here say, I’m getting the one on the left.

VS Code ConfigureVs Configure C++
It’s possible that I’m getting this because I’m using the headmelted and VsCodium versions on a Raspberry Pi.

There’s a bit of a question mark about using the official extension on non-official build of Visual Studio. Headmelted allows it, but VsCodium has its own marketplace.

It’s easy enough to copy tasks.json over so not really a problem but just a minor irritation.

A pleasant surprise – scrot handles multiple screens

A pleasant surprise – scrot handles multiple screens

Scrot screenshot of two monitosrMy Raspberry Pi now has both a 7″ touchscreen and a 24″ monitor working at the same time. Most work is done on the big screen but the smaller display is for testing. I’ve reconfigured it so the menu is on the bigger screen, it makes more sense.

For quick and dirty screen shots, I use scrot (the name is derived from SCReenshOT). I’m fairly certain this was included with the operating system as it was installed, it wasn’t anything I added. What I didn’t expect was that it would capture both screens and put them in the one image. It fills the gap with a copy of the smaller screen.

Scrot is fine for most stuff but I thought that if I wanted to capture things like menus then I was going to install another utility that offered a time delay but digging a bit deeper, it turns out that scrot can do that as well. As with most Linux programs,

scrot --help

Gives you a list of commands and there’s a -d (or –delay) NUM which pauses NUM seconds before doing the grab. Other options let you do a countdown (-c), capture with border (-b)  and you can even have it run another program (-e) on the screenshot. Handy if you had it running unattended on a cron job and wanted to email the grab.

There’s a bit more but I’ll leave that for you to investigate.

A rather powerful C Graphics library

A rather powerful C Graphics library

Raylib libraryI’m not going to be departing from SDL2 any day soon, but if I were starting from scratch, I would seriously consider raylib.  It ticks many boxes!

  • Written in C(C99). Tick.
  • Cross platform including Raspberry Pi desktop. Tick.
  • Open source and liberal licensing tick.
  • Full 3D support with animated models. Tick.
  • Extensive Sound support. Tick.
  • Very open license that even allows static linking with closed software. Tick.
  • Lots of examples. Tick.

There’s even a set of open source games on GitHub. including several that you can play in your browser (HTML5). Documntation is in the form of a 36-page Wiki. I took a quick glance through there and was impressed with some of the features. For example, OpenGl can be used directly and not through X11 though that is also available.

Plus full marks for including struct sizes on the data structures page. That’s not something you often see, nor is instructions for configuring Visual Studio, Visual Studio Cocde, Codeblocks, Eclipse and Sublime Text. The cheat sheet (which you can also download as a pdf) gives an idea of the number of functions in Raylib. They cover five pages!

Playing with VSCodium

Playing with VSCodium

open-vsx.orgThere are some subtle differences between it and Visual Studio Code. The main one is the not having access to the VisualStudio market place. The C/C++ template isn’t there but instead is installed by default.

However I have found that the tasks and launch json files created from the F1 menu don’t have the C++ choices. What this means is that you have to get them from an official Visual Studio source, like Visual Studio Code installed on 64-bit Windows/Ubuntu/Mac.

I’d already done this so I used WinSCP to send them via ssh from my Windows box to the Pi. It’s a slight irritation but once you’ve got them setup it works ok. I can build applications haven’t got debugging working yet though.

There is an alternate Extensions Marketplace which has 266 items in it.  That’s a screenshot of the programming language extensions.