SAVE 20% OFF PURCHASE OF $20 OR MORE WITH CODE SAVE20

Opengl: 20

#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() 
    // Initialize GLFW and create a window
    if (!glfwInit()) 
        return -1;
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL 2.0 Example", NULL, NULL);
    if (!window) 
        glfwTerminate();
        return -1;
glfwMakeContextCurrent(window);
// Initialize GLEW
    if (glewInit() != GLEW_OK) 
        return -1;
// Create and compile vertex shader
    GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
    const char* vertex_shader_source = "#version 200\n"
                                      "in vec3 position;\n"
                                      "void main() \n"
                                      "    gl_Position = vec4(position, 1.0);\n"
                                      "\n";
    glShaderSource(vertex_shader, 1, &vertex_shader_source, NULL);
    glCompileShader(vertex_shader);
// Create and compile fragment shader
    GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
    const char* fragment_shader_source = "#version 200\n"
                                         "out vec4 frag_color;\n"
                                         "void main() \n"
                                         "    frag_color = vec4(1.0, 0.0, 0.0, 1.0);\n"
                                         "\n";
    glShaderSource(fragment_shader, 1, &fragment_shader_source, NULL);
    glCompileShader(fragment_shader);
// Create and link program
    GLuint program = glCreateProgram();
    glAttachShader(program, vertex_shader);
    glAttachShader(program, fragment_shader);
    glLinkProgram(program);
// Specify vertices for a triangle
    GLfloat vertices[] = 
        -0.5f, -0.5f, 0.0f,
         0.5f, -0.5f, 0.0f,
         0.0f,  0.5f, 0.0f
    ;
// Create and bind vertex buffer object (VBO)
    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Specify vertex attribute
    GLint position_location = glGetAttribLocation(program, "position");
    glEnableVertexAttribArray(position_location);
    glVertexAttribPointer(position_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
while (!glfwWindowShouldClose(window)) 
        glClear(GL_COLOR_BUFFER_BIT);
        glUseProgram(program);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glfwSwapBuffers(window);
        glfwPollEvents();
glfwTerminate();
    return 0;

This example demonstrates the basic usage of OpenGL 2.0 and GLSL for rendering a simple triangle.

The defining feature of OpenGL 2.0 was the introduction of the OpenGL Shading Language (GLSL) and the standardization of the programmable pipeline. This shifted the API from a configuration-based model to a programming-based model.

Vertex shader responsibilities:

Fragment shader responsibilities:

(Actual GLSL code omitted here but follows the vertex/fragment roles above.) opengl 20

Despite its power, OpenGL 2.0 retained much of the legacy fixed-function baggage. The specification was a hybrid beast: you could still call glBegin()/glEnd() and glLightfv() alongside shaders. This flexibility was a blessing for migrating legacy code but a curse for clean, modern design.

Common frustrations for developers at the time: #include &lt;GL/glew

These issues would eventually lead to OpenGL 3.0 and later the radical deprecation of OpenGL 3.1. But in 2004, developers were just happy to have shaders.


A Vertex Shader executes once per vertex. It replaces the fixed-function transform and lighting. In your GLSL code, you can: This example demonstrates the basic usage of OpenGL 2