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:
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
Installing and setting up the GLFW library:
Running the below commands would install GLFW in your system:
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:
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
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:
- Head on to the GLAD web service. 2.Set the language to C++ and choose the specification as OpenGL.
- 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.zipcontaining two folders(
src). 6.Copy the folders inside
KHR) into your include(s) directory:
cp -R include/* /usr/include/7.Now copy the file
srcfolder to your current working directory.
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 ; you can copy it and save it as
Let’s compile our code & generate an executable
g++ hello_triangle.cpp glad.c -ldl -lglfw
./a.out to see the program work. You should get the output as below:
Your setup for OpenGL is now complete. I hope things went smoothly and you were successful. Read this if you want to understand more about the source code you just copied!
See you then. Until next time!