From 1702abc29275ad2857411b650983e6a2cac01a99 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Thu, 23 Dec 2021 14:50:42 +0100 Subject: [PATCH] Created Example (markdown) --- Example.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Example.md 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