You are currently viewing the United Kingdom version of the site.
Would you like to switch to your local site?
14 MIN READ TIME

OPENGL CHESS

Add controllers and menus with OpenGL

Never a man to miss deadlines, Andrew Smith stays in control adding mouse menus to our OpenGL-powered 3D chess game.

OUR EXPERT

Andrew Smith is a software developer for NHS England. He enjoys video gaming and started coding in C/C++ in 1997 on a Borland C++ for DOS compiler.

QUICK TIP

You can find the full source to this project at https:// github.com/ asmith1979/ lxf302/.

This month, we are continuing with the 3D chess program that we started in LXF301. T We’re creating a basic mouse-driven menu system to be shown at the start of the game program and adding game controller support.

The original source code for the 3D chess program can be downloaded or cloned from https://github.com/ stevenalbert/3d-chess-opengl. Some aspects of the original code have been modified for this tutorial.

We used a PC-compatible Xbox One controller to test and implement the functionality, but other PCcompatible game controllers should also be applicable.

Before we continue any further, let’s set up our development environment: $ sudo apt-get update $ sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev $ sudo apt-get install libglfw3 $ sudo apt-get install libglfw3-dev $ git clone https://github.com/asmith1979/lxf302

Run the OpenGL test program to make sure OpenGL has been set up properly. There should be a file called testOpenGL.cpp in the lxf302 folder. The g++ build command is in the build.txt file.

Going on the basis that OpenGL and GLFW have been set up correctly, navigate into the folder called 3d-chess-lxf302. You should find a file called build.txt that contains the build code for the project, which you can copy and paste into the command line to build an executable program called chessgame. After this has been built, run the program to familiarise yourself with the chess program. Currently, it is keyboard controlled using the a, s, w and d keys to navigate round the chess board, and Space to select a piece on the board. When you’ve finished, press Escape to exit the program.

To edit and view the source code, you can use any editor or IDE of your choice. The build code to put into the command line is stored in build.txt, which can be copied and pasted to save you having to type out all the commands. Also, as we will be both editing and executing the chess program simultaneously to see the result of code changes we have made, it may be advisable to open up two terminal windows – one used for editing and the other for building and executing the game program.

The test OpenGL program showing that OpenGL is installed correctly. Adjust the size of the window if it opens with no image.
Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for 99p
SUBSCRIBE NOW
30 day trial, then just £9.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
June 2023
VIEW IN STORE

Other Articles in this Issue


LINUX FORMAT
LINUX FORMAT
The #1 open source mag Future Publishing Limited,
WELCOME
MEET THE TEAM
We’re looking at all manner of hacks this issue, from using Kali Linux to Hackfest and robot builds. What was your favourite hack?
Hacking away
It was a great experience to attend the
REGULARS AT A GLANCE
Newsdesk
THIS ISSUE: Ubuntu ties knot with RISC-V »
RISC-V on Ubuntu
Developers at Canonical and the RISC-V Foundation have been pulling out all the stops to marry everyone’s favourite distro with RISC-V.
Deutsche Telekom picks Collabora Online
An open source online office suite is now available to Telekom customers in Germany and Austria.
Storm in a Docker container?
Announcement causes confusion among customers.
LINUX FOCUSED
Keith Edmunds is MD of Tiger Computing, which
BACK TO BASICS
Joe Brockmeier is head of community, Percona. "There
Happy birthday to Curl!
As Curl turns 25, version 8.0.0 is released.
Multi-core improvements
Intel engineers have tweaked optimisations for the Linux kernel.
Google boosts VM performance
Google engineers release patches to improve KVMbased virtual machines.
Distro watch
What’s behind the free software sofa?
NEW DRIVER
Boris Brezillon is a senior software engineer at
CONFLICTS
Jon Masters is a kernel hacker who’s been
Kernel watch
Jon Masters keeps up with all the latest happenings in the Linux kernel, so you don’t have to.
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mails rver
MAILSERVER WRITE TO US Do you have a
HotPicks
System Monitoring Center Universal Media Server Element Carbonyl Nushell Tonfotos Conjure Space Station 14 Crispy Doom Singlebox Rymdport
UBUNTU 23.04 FAST AND LIGHT!
We take the latest Ubuntu release and sprinkle a little LXF magic on it, so it runs faster and lighter than ever before!
REVIEWS
LDO V0-S1 Voron 0.1
Denise Bertacchi thinks you can take DIY too far…
AMD Radeon RX 7900 XTX
It’s AMD’s fastest graphics card, powered by chiplets, cries Jacob Ridley.
Trisquel 11.0 Aramo
Nate Drake goes from being a Boy and his Blob to Trisquel, a truly free open source and blobless operating system.
Ubuntu 23.04 Lunar Lobster
Nate Drake finds this Lobster Linux to be a snappy dresser, with the stunning latest version of Gnome and improved settings.
Dome Keeper
The Management likes to think the monsters in the LXF dungeon are incentivisation multipliers. Jon Bailes is too busy mining a way out to argue.
ROUNDUP
Firewall distros
WE COMPARE TONS OF STUFF SO YOU DON’T HAVE TO!
Installation and setup
How simple are these firewalls to fire up?
Configuration and management
How easy do these firewalls make life for network admins?
Updates and upgrades
Which firewalls are easiest to keep in the loop?
Security features
How seriously do these firewalls take your safety?
Help and support
When all else fails, can you read the manual?
Cloud support
Which firewalls take to the cloud best of all?
Stability
Will your chosen firewall still be here 10 years from now?
The Verdict
Firewall distros
Master hacking with Kali
Daring David Rutland dons his black hoodie and joins the red team to try out Kali Linux from Offensive Security.
Ice cold with Kali
Kali is essentially a collection of tools gathered over the decades, and packaged in an easy-to-use, logical way.
Get to grips with Kali
Kali Linux enables amateurs and pros alike to take security into their own hands and carry out attacks on their own networks and equipment.
Metasploitation
No computer program is perfect and it’s not possible to predict every output for every input as neither humans nor computers are omniscient.
Chase the purple dragon
There are people who want to break into networks and machines, and people who try to stop them, known as red teams and blue teams.
Pi USER
Ada Computer Science platform launched
An English curriculum-mapped resource for GCSE and A-level grade students. Fill your boots!
Pico gets video-out with Adafruit
The latest microcontroller RP2040 comes with advanced visual goodies.
SPRING IS BEARING FRUIT
Les Pounder works with groups such as the
Argon ONE NVMe
Feeling the need, the need for 1980s film references, Les Pounder tries out a speedy Pi solution.
Pico Bricks
Learn all about electronics and programming with a simple, Pico-based kit and Les Pounder!
Boot your Pi faster from USB storage
Les Pounder feels the need, the need for speeding up his Raspberry Pi 4 using USB 3…
Robot object detection, side motion and video
To put the electronic cherry on Les Pounder’s finished robot, we add sonar sound, streaming video and sideways motion.
TOP OF THE FOSS!
Vanilla OS
Matt Holder discovers that Vanilla OS is anything but vanilla.
It’s Collabora time!
At Clare College, Cambridge, Neil Mohr catches up with the Collabora Online team to discover what’s state of the art in the online office world.
TUTORIALS
Check your disk usage
There are many vanilla tools that tell you the amount of free disk space but Shashank Sharma prefers one that values style as well as substance.
Speed up text-based tasks with Espanso
Nick Peers reveals how to boost your productivity with a free text replacement tool that has a multitude of different uses.
ALGOL: the father of mainstream languages
Time traveller Mike Bedford steps back 65 years to the birth of high-level languages and looks at ALGOL, the language that started a revolution.
Scale, repair and enhance your photos
G’MIC is a treasure chest with virtually inexhaustible content. But how do you use it? Karsten Günther helps open the box and explore the contents.
Rescuing data from legacy floppy disks
Matt Holder discovers that rescuing data from 20-yearold floppy disks is a lot more difficult than expected.
Relive the history of tracker music
Michael Reed looks at the history of so-called tracker music and explores some of the Linux tools that can work with that format.
IN DEPTH
Art beyond the canvas
Tam Hanna takes a look at running the Stable Diffusion image generator on your local Linux systems.
Chat
X
Pocketmags Support