Irrlicht: Setting Up Code::Blocks

Introduction

In this tutorial, we will learn how to set up Code::Blocks and link Irrlicht to our C++ project.

Code::Blocks is a free, cross-platform IDE (integrated development environment) used for developing C++ applications. It supports multiple types of compilers, such as GCC, Cland and Visual C++.

Irrlicht is an open source graphics rendering library, which in-a-nutshell is a package of pre-written code bundled together to help graphics programmers solve their tasks more easily. Therefore, Irrlicht is just a library and not a program by itself. We use Irrlicht in our projects to create applications that render 3D graphics.

Installing Code::Blocks

Latest stable Code::Blocks can be downloaded here. Download the binary release instead of any other options listed on the website. We don’t recommend using any of the Nightly Builds because it’s still under rapid development and very unstable to be used for production.

The installation is really simple, just click through all the pages and you’re done. You can also download the zip file that contains the whole Code::Blocks without any installation required. This is useful if you’re planning to carry it around in a thumb drive and use it anywhere on any computers. Otherwise, download the installer will do.

Code::Blocks installer for Windows

The preceding screenshot shows the Code::Blocks installer for Windows platform. You can also download the installer for different linux operating systems and Mac OS X on Code::Blocks’ website. Once you have installed Code::Blocks, let’s proceed to install Irrlicht.

Installing Irrlicht

1. Go and download Irrlicht from the official download page.

2. After you have downloaded, unzip the files and place it somewhere in your computer. The directories in the zip file should look something like this:

Irrlicht directories

The purpose of these folders are described below:

  • bin – This is where all the binary files are located. You can find all the runnable demos here as well as the DLL file required to run Irrlicht applications. However, only binaries built with Windows Visual Studios are included here. Binaries built for Linux, Mac and Windows GCC are not included.
  • doc – This is where the Irrlicht scripting reference and official tutorials are located. The documents are generated using doxygen and presented in HTML format.
  • examples – The examples folder stores the source code for all the Irrlicht demos. You should definitely check it out and learn something from there.
  • include – This folder contains all the Irrlicht header files which are important for development.
  • lib – This is where you can find the library files required for building Irrlicht applications. Just like the bin folder, only library files built with Visual Studios are included by default. You need to compile the library yourself for other platforms and compilers.
  • media – The media folder is where you can find the screenshots, textures, 3d models, bitmap fonts and icons used in the Irrlicht demos.
  • source – Since Irrlicht is an open source project, the full source code is included in the package by default. You may not need it but it’s there.
  • tools – The tools folder contains the source code for some of the utility tools which you might find useful for your Irrlicht projects.

Setting Up Project

1. First, open up Code::Blocks and create a new project by clicking the Create a new project option on the starting page:

Code::Blocks starting page

2. Once the New from template window popped out, select Empty Project to create an empty C++ project. Do note that there is an Irrlicht project option located at the bottom, but we’re not going to use that.

Choose “Empty project” option

3. Name your project and click through all the Next buttons to create your project.

4. Once you have created your project, go to File 🡒 New 🡒 Empty file. Then, a message box will pop out and ask you to save the file and add it to your current project. Click Yes and name the file as main.cpp.

Add file to project

5. A typical C++ project must have a main() function in-order to compile correctly. Therefore, let’s write one to our main.cpp file:

int main()
{
    return 0;
}

6. Next, we are going to link Irrlicht to our C++ project. Go to Project 🡒 Build options… and open up the Project build options window. Make sure that your project name is highlighted on the hierarchy tree instead of Debug or Release. This is because we want our settings to affect both Debug and Release:

Project build options

7. After that, go to Linker settings tab and click the Add button. Then, select one of the Irrlicht.lib library files located in lib folder:

Add “Irrlicht.lib” to Linker settings

8. Next, open up the Search directories tab and add the include folder from Irrlicht folder to the Compiler sub-tab:

Add “include” folder to search directories

9. Proceed to the Linker tab and add the lib folder this time around:

Add “lib” folder to search directories

10. Finally, we try and include irrlicht.h and see if we have successfully linked Irrlicht to our project:

#include <irrlicht.h>

int main()
{
    return 0;
}

11. Build the project now by going to Build 🡒 Build. If the program compiles without any error… Hooray! We have successfully linked the Irrlicht library to our C++ project!

We can now start creating an empty window that runs the Irrlicht renderer. Please proceed to the next tutorial by clicking on the link below.

Leave a Reply