GB
  
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

QUICK TIP

QUICK TIP

VARIABLE SCOPE

QUICK TIP

DATA TYPES

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.

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

There is a file in the folder of the chess program and of the OpenGL test program called build.txt, which contains the build commands that can be copied and pasted into command line.

Variables in a C/C++ program can be declared locally, globally or across different files. In this project, variables are mainly declared both globally and locally, which determines how code within the program can access them. Usually, global variables are declared near the top of a C/C++ program, just after the library files have been included, so they can be accessed by functions in the code. For example, the function processGameControllerOutput() uses variables such as actionRightTaken, actionLeftTaken, actionUpTaken and actionDownTaken. These variables are accessible to any function in the program because they are declared globally. A variable would be a local variable if it was declared inside a function itself, which results in only that function being able to access the variables. In main.cpp there is a function called drawMoveToSquare that, at the start of the function, declares two local variables of type float that can only be accessed by the code within that function and nowhere else. Variables or values may also be passed into functions as what is known as arguments or parameters, which can be accessed by the code within the function. An example of this is a function in main.cpp called showWord that takes in two integer values and one string value. This is then used by the code in the function to manipulate text and position.

Instead of scrolling through code, it may be better to use the editor’s search facility to go directly where you want to go in the code.

In C/C++, data types can be applied to variables and functions (and methods in C++). The main data types in C/C++ are: Integers (int) Decimal values (float) String (string or char *)

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.

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.
ADVERTISEMENT
GO. COMPARE
go.compare
Magazinesdirect
www.magazinesdirect.com/LIN/B74L
Magazinesdirect
magazinesdirect.com
Magazinesdirect
magazinesdirect.com
Magazinesdirect
www.magazinesdirect.com
Linux
www.magazinesdirect.com/linux-format
codeclub
www.codeclub.org.uk
EFF
EFF.ORG
The braintumour charity
thebraintumourcharity.org
Chat
X
Pocketmags Support