Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

What are the first 40 you learn from glad glfw and OpenGL

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen3-30b-a3b’s answer.
  1. User

    What are the first 40 you learn from glad glfw and OpenGL

  2. Assistant

    Below is a “cheat-sheet” style list of 40 API calls that almost everyone bumps into during their very first OpenGL project that uses

    • GLAD – to load the OpenGL procedures
    • GLFW – to create the window/context & read input
    • OpenGL core – to actually draw something

    Think of it as a chronological tour through the code you usually write in main.cpp.

    #Function / MacroComes fromWhy you meet it so early
    1glfwInit()GLFWBoot-up the GLFW library.
    2glfwWindowHint()GLFWSet window / context hints (version, profile, etc.).
    3glfwCreateWindow()GLFWMake the actual OS window + OpenGL context.
    4glfwMakeContextCurrent()GLFWTell OpenGL to route commands to that context.
    5gladLoadGLLoader()GLADLoad all OpenGL function pointers (must be done after a context exists).
    6glfwSetFramebufferSizeCallback()GLFWAuto-resize viewport when the window is resized.
    7glfwGetFramebufferSize()GLFWQuery initial drawable resolution.
    8glViewport()OpenGLMap NDC space to window pixels.
    9glClearColor()OpenGLDefine the background color.
    10glClear()OpenGLClear the color (and/or depth) buffer each frame.

    Input & event loop |11| glfwSetInputMode() | GLFW | E.g. hide the cursor, enable raw motion. | |12| glfwGetKey() | GLFW | Poll keyboard keys. | |13| glfwPollEvents() | GLFW | Pump the OS event queue. | |14| glfwSwapBuffers() | GLFW | Present the back buffer to the screen. |

    Vertex array / buffer setup |15| glGenVertexArrays() | OpenGL | Create a VAO object. | |16| glBindVertexArray() | OpenGL | Make a VAO current. | |17| glGenBuffers() | OpenGL | Create VBO / EBO handles. | |18| glBindBuffer() | OpenGL | Select which buffer you’re going to touch. | |19| glBufferData() | OpenGL | Upload vertex/element data to the GPU. | |20| glEnableVertexAttribArray() | OpenGL | Turn on a vertex attribute slot. | |21| glVertexAttribPointer() | OpenGL | Tell OpenGL how to read the attribute data. |

    Shaders |22| glCreateShader() | OpenGL | Make a shader object (vertex, fragment, …). | |23| glShaderSource() | OpenGL | Pass GLSL source code string(s). | |24| glCompileShader() | OpenGL | Compile to GPU machine code. | |25| glGetShaderiv() | OpenGL | Check compile status. | |26| glGetShaderInfoLog() | OpenGL | Fetch the error/warning log. | |27| glCreateProgram() | OpenGL | Create a program object. | |28| glAttachShader() | OpenGL | Attach compiled shaders to the program. | |29| glLinkProgram() | OpenGL | Link them into a final GPU program. | |30| glGetProgramiv() | OpenGL | Check link status. | |31| glGetProgramInfoLog() | OpenGL | Fetch link-time messages. | |32| glUseProgram() | OpenGL | Make that program active. |

    Uniforms (most common starters) |33| glUniform1f() | OpenGL | Pass a single float (time, mix factor, etc.). | |34| glUniformMatrix4fv() | OpenGL | Send transform matrices. |

    Drawing & state |35| glDrawArrays() | OpenGL | Render non-indexed geometry (e.g., a triangle). | |36| glEnable() | OpenGL | Turn on a piece of fixed-function state (depth test, blending…). | |37| glDisable() | OpenGL | Turn it back off if needed. |

    Cleanup |38| glDeleteShader() | OpenGL | Free individual shader objects after linking. | |39| glDeleteVertexArrays() | OpenGL | Destroy VAO(s). | |40| glDeleteBuffers() | OpenGL | Destroy VBO/EBO(s). |

    (You’d also call glfwTerminate() at shutdown, but I squeezed in exactly 40 items 😉.)

    Mini code skeleton (showing ~25 of them in action)

    #include <glad/glad.h>
    #include <GLFW/glfw3.h>
    int main() {
        glfwInit();
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
        GLFWwindow* window = glfwCreateWindow(800, 600, "Hello", nullptr, nullptr);
        glfwMakeContextCurrent(window);
        gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
    
        glfwSetFramebufferSizeCallback(window, [](GLFWwindow*,int w,int h){ glViewport(0,0,w,h); });
    
        // --- build geometry ---
        GLuint vao, vbo;
        glGenVertexArrays(1,&vao); glBindVertexArray(vao);
        glGenBuffers(1,&vbo);      glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
        glEnableVertexAttribArray(0);
    
        // --- build shaders ---
        GLuint vs = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vs,1,&vsSrc,nullptr);  glCompileShader(vs);
        GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fs,1,&fsSrc,nullptr);  glCompileShader(fs);
        GLuint prog = glCreateProgram();
        glAttachShader(prog,vs); glAttachShader(prog,fs); glLinkProgram(prog);
        glDeleteShader(vs); glDeleteShader(fs);
    
        while(!glfwWindowShouldClose(window)){
            glClearColor(0.1f,0.1f,0.2f,1.0f);
            glClear(GL_COLOR_BUFFER_BIT);
            glUseProgram(prog);
            glBindVertexArray(vao);
            glDrawArrays(GL_TRIANGLES,0,3);
    
            glfwSwapBuffers(window);
            glfwPollEvents();
        }
    
        glDeleteVertexArrays(1,&vao);
        glDeleteBuffers(1,&vbo);
        glfwTerminate();
    }
    

    Feel free to treat this list as your “first 40 flashcards.” Once you’re comfortable with them, you’re ready to explore textures (glTexImage2D, glGenerateMipmap), framebuffers, uniform buffers, SSBOs, compute shaders, etc. — Have fun hacking! 🎉

  3. User

    Can you explain glfwDestroyWindow() – Destroy a window. glfwTerminate() – Clean up GLFW. by only using Minecraft

  4. Assistant

    🏰 Minecraft-style analogy

    1. You’ve launched Minecraft and hit “Create New World…”
      (that’s like glfwCreateWindow()—a brand-new game session appears).

    2. You play, build, fight mobs, etc.

    Now you have two different “exit” buttons:

    🍞 1. Save & Quit to Title → glfwDestroyWindow()
    • All the loaded chunks for that specific world unload.
    • Mobs despawn, block updates stop, sounds cease.
    • You’re back at the main menu, ready to open another world.
    • The Minecraft app itself is still running; its textures, music, and options GUI are still in memory.

    🚪 2. Quit Game → glfwTerminate()
    • You’re done for the day.
    • The entire Minecraft program closes: menus vanish, resource packs unload, the JVM shuts down, the launcher reclaims its RAM.
    • Nothing Minecraft-related remains running; you’re back on the desktop.

    Quick mnemonic ────────────── “Leave the world” → destroy window
    “Leave the game” → terminate GLFW

    So: call glfwDestroyWindow() when you want to exit just that one in-game world, and glfwTerminate() when you’re ready to close Minecraft itself. 🪄

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.