Setting up CLion for OpenGL Programming on Windows 11
In this how-to, I will be showing how to setup the JetBrains CLion IDE for modern OpenGL programming in C++
Prerequisites
Before we can proceed to setting up CLion for an OpenGL project we have to get some
required libraries, namely GLFW and GLAD.
GLFW is an open source multi-platform library for OpenGL. It provides a simple API for creating
windows, contexts, and surfaces, receiving input and events. It is written in C and supports
Windows, macOS, and Linux. This makes creating a window very easy on any platform otherwise
you would have to write lots of code on each platform just to create a simple window.
GLAD is used to load and manage runtime function pointers for OpenGL and related graphics
APIs. It acts as a bridge so your code can call modern GPU driver function that are not
hardcoded into your OS.
I used GLFW 3.5.1 binaries for Win64 but you can use whatever the latest
version is at the time you do this. Go to this link to get
the files. Looks like the latest version as I write this is 3.5.1. Click on the "64-bit Windows binaries" button
and save the zip file somewhere on your computer.
I used GLAD for OpenGL version 3.3 since we won't need any advanced features present in the other versions.
Feel free to use whatever version of OpenGL you want to though. Go to this link.
At the glad homepage you will be presented with a form to fill out and generate the glad files to download for the
version of OpenGL you select. Choose these values:
- For Language: C++
- For API gl: 3.3
- For Specification: OpenGL
- For Profile: Core
- Don't worry about Extensions
- Make sure the "Generate a loader" checkbox is checked
- Click on the "Generate" button at the bottom right
Save the glad.zip file somewhere on your computer.
Below is a diagram of the CLionProjects folder that CLion automatically creates when you make a a new project, if you have not changed it on your computer.
Creating a new C++ project in CLion
Now that all of the GLFW and GLAD files are in place,
open the CLion IDE and if it opens in an existing project you may have
been working on, close that project and you will be back at the welcome
screen where you can see any existing projects you have. If you don't have
any existing projects, you will go right to the welcome screen when you start
the CLion IDE. Below is a screenshot of the welcome screen.
To create our project click on the "New Project" button at the top pointed out by
the red arrow symbol I have added to the picture. You will be presented with the New
Project dialog shown below.
In the "New Project" dialog you will see I have added some red arrows numbered 1 to 4.
- Select "C++ Executable" on the left.
- Replace the "untitled" project name in the "Location" with the name of your project. In this example I have chosen the name "HelloWindow".
- Select C++17 for the "Language Standard"
- Then click the "Create" button at the bottom of the dialog.
You have created the project in CLion as show in the screenshot below.
The image above shows the contents of the "CMakeLists.txt" file. Make sure you use this exact
file contents. Notice that it points to the "include" and "lib" folders one level above the project
folder (../include) and (../lib).
Also notice that the glad.c file is in the "HelloWindow" project along side of the main.cpp file that
the project creates for you. You have to delete the default code that CLion puts in the main.cpp file and
replace it with the code below:
Contents of the main.cpp file you need to use in your project.
If you have setup your CLion project as instructed, you will be able to run the program and see
the OpenGL window as displayed in the following screenshot:
Good luck and enjoy your journey learning OpenGL with C++ in CLion IDE.