FANDOM


This page is primarily used for taking notes from the Lean OpenGL website and it's Wikipedia page. Here are the notes I found most important in the 'Getting Started' section.

What is OpenGL? Edit

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) used for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering. OpenGL is mainly considered an API that provides us with a large set of functions that we can use to manipulate graphics and images. However, OpenGL by itself is not an API, but merely a specification, developed and maintained by the Khronos Group. Since most implementations of OpenGL are built by graphics card manufacturers, whenever there is a bug in the implementation this is usually solved by updating your video card drivers; those drivers include the newest versions of OpenGL that your card supports. This is one of the reasons why it's always advised to occasionally update your graphics drivers.

Core-profile vs Immediate modeEdit

In past years, using OpenGL meant developing in immediate mode (often referred to as fixed function pipeline) which was an easy-to-use method for drawing graphics. Most of the functionality of OpenGL was hidden in the library and developers did not have much freedom at how OpenGL did it's calculations. Immediate mode is really easy to understand and use, but it is also very inefficient. For that reason the specification started to deprecate immediate mode functionality from version 3.2 and started motivating developers to develop in OpenGL's Core-Profile mode.

Core-Profile mode is a division of OpenGL's specification that removed all the old deprecated functionality. When using Core-Profile, OpenGL forces the user to use modern practices. Whenever we try to use of OpenGL's deprecated functions, it raises an error and stops drawing. The advantage of learning the modern approach is that it is very flexible and efficient, but unfortunately it is difficult to learn. The modern approach requires the developer to truly understand OpenGL and graphics programming and while it is a bit difficult, it allows for much more flexibility, more efficieny and most importantly a much better understanding of graphics programming.

An important thing to note on versions : When using functionality from the most recent version of OpenGL, only the most modern graphics cards will be able to run your application. This is often why most developers generally target lower versions of OpenGL and optionally enable higher version functionality.

ExtensionsEdit

A great feature of OpenGL is its support of extentions. Whenever a graphics company comes up with a new technique or a new large optimization for rendering this is often found in extension implemented drivers. If the hardware an application runs on supports such an extension the developer can use the functionality provided by the extension for more advanced or efficient graphics. This way, a graphics developer can still use these new rendering techniques without having to wait for OpenGL to include the functionality in its future versions, simply by checking if the extension is supported by the graphics card.

State machineEdit

OpenGL is by itself a large state machine: a collection of variables that define how OpenGL should currently operate. The state of OpenGL is commonly referred to as the OpenGL context. When using OpenGL, we often change its state by setting some options, manipulating some buffers and then render using the current context.

For example, if we tell OpenGL that we now want to draw lines instead of triangles, we change the state by telling OpenGL it should draw lines, the next drawing commands will now draw lines instead of triangles.

When working in OpenGL we will come across several state-changing functions that change the context and several state-using functions that perform some operations based on the current state of OpenGL.

ObjectsEdit

The OpenGL libraries are written in C and allows for many derivations in other languages, but in its core it remains a C-library. Since many of Cs language-constructs do not translate that well to other higher-level languages, OpenGL was developed with several abstractions in mind. One of those abstractions are objects in OpenGL.

An object in OpenGL is a collection of options that represents a subset of OpenGL's state. For example, we could have an object that represents the settings of the drawing window; we could then set it's size, how many colours it supports and so on. We could visualize an object an object as a C-like struct:

 struct object_name {
    float option1;
    int option2;
    char[] name;
};

The great thing about using objects is that we can define more than one object in our application, set their options and whenever we start an operation that uses OpenGL's state, we bind the object with our preferred settings. There are objects for example that act as container objects for 3D model data (a house or a character) and whenever we want to draw one of them, we bind the object containing the model data that we want to draw. Having several objects allows us to specify many models and whenever we want to draw a specific model, we simply bind the corresponding object before drawing without setting all their options again.

ReferencesEdit

OpenGL Wikipedia page

Learn OpenGL - Getting Started

Community content is available under CC-BY-SA unless otherwise noted.