OpenGL is Awesome!!

By Kshitij Aucharmal β€’ 4 minutes read β€’

Okay, so this is gonna be a bit long, get excited!

Lets divide this into three Parts:

  1. OpenGL
  2. C++
  3. Kdevelop

Lets start with OpenGL first.

OpenGL

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics

OpenGL is cross-platform like vulkan, and wayyyy easier to understand and code than vulkan. While vulkan took me one week to get started and to draw a triangle on the screen (the one thing you do first as a graphics programming beginner), OpenGL allowed this to happen in under a few hours !!!

I’ve identified some differences, which maybe good or bad according to industry standards, but I’ll list them here according to my standards

Lets focus on the good points first:

  1. OpenGL is easy: The code is easy to understand, it does not require a hell lot of setup to get started, and also makes everything easier to understand. I of course am comparing it to Vulkan
  2. Handles a lot of things on its own: using glad, which is library for managing function pointers for OpenGL, initialization is a cinch
  3. Fast on my machine: Vulkan gave me some lagging when resizing windows, maybe it was my fault (probably), but in OpenGL I just used a callback function and it worked without any significant lags

Unfortunately, OpenGL is not all good:

  1. Not explicit: Many things are handled internally, unlike vulkan which allows for in depth customization of each system using structs.
  2. Not Shader friendly: Although people may call it shader friendly as you can compile the shaders anywhere you want in the code, but the code has to be compiled and shaders are a part of this. shaders can be kept different from the full code compilation, unlike vulkan.
  3. Slower: I haven’t personally experienced this, but people have said that Vulkan is much more performant than OpenGL

Given everything above, I’m going to stick to OpenGL and try my best to make the engine Next step will be to integrate Imgui, which is much easier as compared to Vulkan

Current Progress

Two triangles

Yup, two triangles forming a rectangle with only 4 vertices defined and 6 indices for drawing/filling in the triangles using VBO and EBO This is the progress I got, and I can even send these values to the vertex shader !!!

The process is for rendering anything on the screen is as follows, taken from the LearnOpenGL website pipline

The Vertex Buffer Objects (VBO) and Element Buffer Objects (EBO) are stored as follows under the Vertex Array Objects vertex

C++

I’m learning c++ from the c++ playlist series by the cherno, and its been amazing. I understand a lot of concepts, and it really allows my code to flow seamlessly. I have taken the liberty to seperate all of the code into seperate files, creating namespaces for certain systems such as WindowManagement and InputManagement. The heirarchy of the code is as follows:

OpenGL
β”œβ”€β”€ build
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ external
β”‚Β Β  β”œβ”€β”€ glad
β”‚Β Β  └── imgui
β”œβ”€β”€ include
β”‚Β Β  β”œβ”€β”€ input.hpp
β”‚Β Β  β”œβ”€β”€ shaderman.hpp
β”‚Β Β  └── window.hpp
β”œβ”€β”€ Makefile
β”œβ”€β”€ OpenGL.kdev4
β”œβ”€β”€ shaders
└── src
    β”œβ”€β”€ input.cpp
    β”œβ”€β”€ main.cpp
    β”œβ”€β”€ shaderman.cpp
    └── window.cpp

As you can see, the structure is a pretty standard one with all the headers in the include directory, c++ files in the src directory, and the libaries in the external directory. The shaders is for storing the shader files, which is currently not being used as the shaders are written as const char * (I’m following the tutorial man)

The CmakeLists.txt handles everything, and I have a new Target in it to run the program once its compiled as well

Kdevelop

Yeah, I started using Kdevelop. Neovim is amazing, but the syntax highlighting and lsp server messes up as the structure changes. It does not take the CmakeLists.txt in consideration, and hence I’m always faced with not resolved/found errors.

As to why I don’t use VSCode, its electron based, and feels too slow for me.

Kdevelop has been perfect, it automatically detects what my CmakeLists.txt defines, and adds targets to the project window. It also has much better autocomplete, vi mode, and my preffered theme ayu-dark built-in, so thats definately a plus.

I’ve added a custom target to the make system, so that I can just build (the build system is amazing as well, you can just add and remove targets) and it will run the binary generated as well. I can’t use harpoon (a nvim plugin) in it, but I’ll soon get used to Kdevelop’s version of it, and it definately feels fast as nvim too.

Thats it! That was the update, will see you guys in the next one!!