A guide to set up OpenGL projects in Debian.
Tags: debian, opengl, glut, linux
Published: 2023-05-14 11:37:30

You will find a lot of articles on what OpenGL is & what's the uses of it. So, let's get straight into OpenGL initial setup which is given below step by step:

#### Step 1

installing dependencies:

Before installing the required libraries, we’ll first have to install a few dependencies. So open your terminal and run the following commands:

```
sudo apt-get update
sudo apt-get install cmake pkg-config
sudo apt-get install g++ mesa-utils libglu1-mesa-dev freeglut3 freeglut3-dev mesa-common-dev
sudo apt-get install libglew-dev libglfw3-dev libglm-dev
sudo apt-get install libao-dev libmpg123-dev
```

#### Step 2

Installing and setting up the GLFW library:

Running the below commands would install GLFW in your system:

```
sudo nautlius
```
The above command will grant you access to editing the root folders as a root administrator. Go to /usr and open the terminal there it should look something like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg4b6fgon4pw66jtnfta.png)

Afterward, run these commands in the terminal:

```
cd local/lib/
git clone https://github.com/glfw/glfw.git
cd glfw
cmake .
make
sudo make install
```

#### Step 3
Now let's install GLAD library,It is an open-source library that makes use of a web service, allowing us to instruct GLAD as to the version of OpenGL we want to define and load all pertinent OpenGL functions for.
So to install this library, perform the following steps:
1. Head on to the GLAD [web service](https://glad.dav1d.de/).
2.Set the language to C++ and choose the specification as OpenGL.
3. In the API section, select gl version of at least 3.3, make sure the profile is set to Core, and that the Generate a loader option is ticked.
4.Ignore the extensions and click Generate to produce the resulting library files.
5.GLAD, by now, should have provided you a zip file: `glad.zip` containing two folders(`include` and `src`).
6.Copy the folders inside `include` (`glad` and `KHR`) into your include(s) directory: `cp -R include/* /usr/include/`
7.Now copy the file `glad.c` inside the `src` folder to your current working directory.

#### Step 4
Now choose your prefered IDE as you’re now done with installing the required libraries. It's time to check that everything was installed correctly using the "Hello Triangle" application, a straightforward triangle rendering tool. The code is available [here] (https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp) ; you can copy it and save it as` hello_triangle.cpp`
Let’s compile our code & generate an executable `a.out`:

```
g++ hello_triangle.cpp glad.c -ldl -lglfw
```
Run `./a.out` to see the program work. You should get the output as below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw766lqcabsq0i5fkckr.png)

Your setup for OpenGL is now complete. I hope things went smoothly and you were successful. Read [this](https://learnopengl.com/Getting-started/Hello-Window) if you want to understand more about the source code you just copied!

See you then. Until next time!