1 Example
Snowiiii edited this page 2021-12-23 14:50:42 +01:00

Example code

GLFW Introduction

Initialize the library

The library is initialized with glfwInit, which returns GLFW_FALSE if an error occurred.

if (!glfwInit()) {
     // Handle initialization failure
     return -1;
}

Version information

glfwGetVersionString();

Terminate the library

Before your application exits, you should terminate the GLFW library if it has been initialized.

glfwTerminate();

Window

GLFW Window guide

Create a windowed mode window and its OpenGL context

  GLFWwindow* window;

  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);

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

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

Window destruction

glfwDestroyWindow(window);