Getting Started
So you want to take advantage of the power of the OpenGL API? If you are visiting this page because a game or software uses the OpenGL API, you need to install the appropriate graphic driver which enables usage of the functionality provided.
To program using the OpenGL API, you need the driver and the development package (depends on platform and programming language). More platform-specific details are described in the sections below.
Contents
This Wiki maintains a FAQ page for OpenGL.
Downloading OpenGL
In all three major desktop platforms (Linux, macOS, and Windows), OpenGL more or less comes with the system. However, you will need to ensure that you have downloaded and installed a recent driver for your graphics hardware.
Windows
Appropriate Windows driver websites:
Some sites also distribute beta versions of graphics drivers, which may give you access to bug fixes or new functionality before an official driver release from the manufacturer:
Without drivers, you will default to a software version of OpenGL 1.1 (on Win98, ME, and 2000), a Direct3D wrapper that supports OpenGL 1.1 (WinXP), or a Direct3D wrapper that supports OpenGL 1.1 (Windows Vista and Windows 7). None of these options are particularly fast, so installing drivers is always a good idea.
If your system does not contain a GPU, or the GPU vendor delivers graphics drivers providing OpenGL support that’s so old as to be useless to you, you might want to consider installing the Mesa3D OpenGL library on your system. See this wiki link for details:
Linux
Graphics on Linux is almost exclusively implemented using the X Window system. Supporting OpenGL on Linux involves using GLX extensions to the X Server. There is a standard Application Binary Interface defined for OpenGL on Linux that gives application compatibility for OpenGL for a range of drivers. In addition the Direct Rendering Infrastructure (DRI) is a driver framework that allows drivers to be written and interoperate within a standard framework to easily support hardware acceleration, the DRI is included in of XFree86 4.0 but may need a card specific driver to be configured after installation. These days, XFree86 has been rejected in favor of XOrg due to the change in the license of XFree86, so many developers left Xfree86 and joined the XOrg group. Popular Linux distros come with XOrg now.
Vendors have different approaches to drivers on Linux, some support Open Source efforts using the DRI, and others support closed source frameworks but all methods support the standard ABI that will allow correctly written OpenGL applications to run on Linux.
For more information on developing OpenGL applications on Linux, see Platform specifics: Linux
macOS
Unlike other platforms, where the Operating System and OpenGL implementations are often updated separately, OpenGL updates are included as part of macOS system updates. To obtain the latest OpenGL on macOS, users should upgrade to the latest OS release, which can be found at Apple.com.
For developers, a default installation of macOS does not include any OpenGL headers, nor does it include other necessary development tools. These are installed by a separate developer tools package called Xcode. This installer includes the OpenGL headers, compilers (gcc), debuggers (gdb), Apple’s Xcode IDE, and a number of performance tools useful for OpenGL application development.
For more information on developing OpenGL applications on macOS, see Platform specifics: macOS.
Writing an OpenGL Application
The first step is to pick your language. Bindings for OpenGL exist in many languages, from C# and Java to Python and Lua. Some languages have multiple sets of OpenGL bindings, none of them being official. All of them are ultimately based on the C/C++ bindings.
If you are not using C/C++, you must download and install a package or library for your chosen language that includes the OpenGL bindings. Some come pre-installed, but others have separate downloads.
If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you’re building a 64-bit executable. The «32» part is meaningless). Visual Studio, and most Windows compilers, come with this library.
On Linux, you need to link to libGL. This is done with a command-line parameter of «-lGL».
Initialization
Before you can actually use OpenGL in a program, you must first initialize it. Because OpenGL is platform-independent, there is not a standard way to initialize OpenGL; each platform handles it differently. Non-C/C++ language bindings can also handle these differently.
There are two phases of OpenGL initialization. The first phase is the creation of an OpenGL Context; the second phase is to load all of the necessary functions to use OpenGL. Some non-C/C++ language bindings merge these into one.
OpenGL Context Creation
An OpenGL context represents all of OpenGL. Creating one is very platform-specific, as well as language-binding specific.
If you are using the C/C++ language binding for OpenGL, then you are strongly advised to use a window toolkit for managing this task. These libraries create a window, attach an OpenGL context to this window, and manage basic input for that window. Once you are comfortable with OpenGL, you can then start learning how to do this manually.
Most non-C/C++ language bindings will provide you with a language-specific mechanism for creating a context.
Getting Functions
If you are using a non-C/C++ language binding, then the maintainer of that binding will already handle this as part of context creation. If you are using C/C++, read on.
In order to use OpenGL, you must get OpenGL API functions. For most libraries you are familiar with, you simply #include a header file, make sure a library is linked into your project or makefile, and it all works. OpenGL doesn’t work that way.
For reasons that are ultimately irrelevant to this discussion, you must manually load functions via a platform-specific API call. This boilerplate work is done with various OpenGL loading libraries; these make this process smooth. You are strongly advised to use one.
If you want to do it manually however, there is a guide as to how to load functions manually. You still should use an extension loader.
Using OpenGL
OpenGL is a rendering library. What OpenGL does not do is retain information about an «object». All OpenGL sees is a ball of triangles and a bag of state with which to render them. It does not remember that you drew a line in one location and a sphere in another.
Because of that, the general way to use OpenGL is to draw everything you need to draw, then show this image with a platform-dependent buffer swapping command. If you need to update the image, you draw everything again, even if you only need to update part of the image. If you want to animate objects moving on the screen, you need a loop that constantly clears and redraws the screen.
There are techniques for only updating a portion of the screen. And you can use OpenGL with these techniques. But OpenGL itself doesn’t do it internally; you must remember where you drew everything. You must figure out what needs updating and clear only that part of the screen. And so forth
There are many tutorials and other materials available for learning how to use OpenGL, both on this wiki and online.
OpenGL Viewers
These are programs that you install and run, and they give you information specific to the OpenGL API your system implements, like the version offered by your system, the vendor, the renderer, the extension list, supported viewport size, line size, point size, plus many other details. Some might include a benchmark. Some are standalone benchmarks.
Setting Up OpenGL for Windows

OpenGL( Open Graphics Library) is a cross-platform and cross-language Application Programming Interface (API) for rendering the graphics in the computer system. It covers wide range of dimensions from 2D-3D.
Writing the code and being creative is one part, but it becomes so irritating and annoying when we cannot initially setup the OpenGL API in Windows OS. Linux system has simpler method for installing it with less than two lines of code or so.
In this tutorial, we will dissect the problem of setting up the OpenGL in Windows OS. For that we are using a command line interface for initial configuration and code blocks IDE for running the OpenGL program.
So let’s get started!
1. Install and Setup MSYS

Head over to this link https://www.msys2.org/ and download the mysy2 installer. From there you can download the complete program.
2. Open MSYS2

Search for MSYS2 in search box and open it. You will get a Command Prompt-like UI as:

3. Install Pacman in the MSYS2
Hit the below command in your brand new MSYS2 CLI
3. Install MinGW package via CLI
After Pacman is installed you will be able to use Pacman manager to install the MinGW package easily with the command below
4. Install Freeglut
Hit the below command to install freeglut
5. Install Glew
Now install glew with the following command
6. Download Code Blocks
Here you have to be super careful on how to download the specific version of code blocks.
Since we have already set up MinGW package we don’t need code block with mingw setup so install simple code block without mingw-setup as shown below :
Head over to this link http://www.codeblocks.org/downloads and download the binary release of code blocks as shown below:

7. Set up the compiler in Code Blocks
After you are done with the installation of the code blocks, we have to do some compiler configuration in it.
Click on Settings > Compiler > Global Compiler Settings
Under Toolchain Executables Tab there is Compiler’s Installation Directory
You have to replace that with the mingw64 which resides inside the msys64 in the Local Disk C which is C:\msys64\mingw64 as shown in the below figure:

After setting up the path in Toolchain executables now Click on the Linker Settings Tab. In the Right Portion, there is Other linker options where you have to add the following command.
After adding it, the tab looks like as :

All done. Now you can create a new project for creating your OpenGL program. But before that we have to get some ground idea to start a project for OpenGL program in code blocks.
8. Creating a OpenGL program
Click on File > New > Project

Now a New From Template Tab pops out in which you have to select Console Application and Click Go as illustrated below:

Now a console application tab pops out as

Click on Next.
Now there will be given an option for C and C++. Choose the language in which you are going to write the program. For now we are choosing C++ language as :