What is OpenGL

This is a library for 2D and 3D graphics rendering. It provides API(Application Programming Interface) for drawing graphics on a computer screen.
GPU manufacturers(eg: AMD, Nvidia) implement OpenGL functions, and we use them in our Application.

OpenGL vs DirectX

OpenGL DirectX
What API for rendering graphics Same
Platform Cross-platform, open-source(Windows, macOS, Linux, and other operating systems) Windows, Xbox
Focus Primarily graphics Graphics, audio, input, multimedia
Supported By Nvidia, AMD, Intel GPU manufacturers Primarily Windows

Hello World Window

1. Write this code in Visual Studio
2. Download library, include files from glfw.org
3. Provide path of headers in include directory
Project > C/C++ > General > Additional Include Directories

4. Provide path of lib in Library directory
Project > Linker > General > Additional Library Directories


5. Draw Triangle by providing vertices

glBegin(GL_TRIANGLES);
glVertex2f(0, 1);   //Provide Vertices of Traingle
glVertex2f(-1, 0);
glVertex2f(1, 0);
glEnd();
                    

6. See the rendered Widow as below
OpenGL Window

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        // Draw Triangle in between. Render happens between Begin and end. Provide 3 vertices
        /*
        *           (0,1)
        *       (-1,0)  (1,0)
        */
        glBegin(GL_TRIANGLES);
        glVertex2f(0, 1);   //Provide Vertices of Traingle
        glVertex2f(-1, 0);
        glVertex2f(1, 0);
        glEnd();
        // End Drawing Triangle

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}