Created Example (markdown)
parent
59af2f3180
commit
1702abc292
64
Example.md
Normal file
64
Example.md
Normal file
@ -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);
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user