diff --git a/Example.md b/Example.md new file mode 100644 index 0000000..b082a4c --- /dev/null +++ b/Example.md @@ -0,0 +1,64 @@ +# Example code + +[GLFW Introduction](https://www.glfw.org/docs/latest/intro_guide.html) + +### Initialize the library +The library is initialized with glfwInit, which returns **GLFW_FALSE** if an error occurred. +```c++ +if (!glfwInit()) { + // Handle initialization failure + return -1; +} +``` + +### Version information +```c++ +glfwGetVersionString(); +``` + +### Terminate the library +Before your application exits, you should terminate the GLFW library if it has been initialized. +```c++ +glfwTerminate(); +``` + +## Window + +[GLFW Window guide](https://www.glfw.org/docs/latest/window_guide.html) + +### Create a windowed mode window and its OpenGL context +```c++ + 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 + +```c++ + 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 + +```c++ +glfwDestroyWindow(window); +``` \ No newline at end of file