1. install GLFW Library
sudo apt update
sudo apt install libglfw3 libglfw3-dev
2. Create a "Hello world.cpp" file and copy the under codes
-------------------------------------------------------------
#include <GLFW/glfw3.h>
#include <iostream>
int main() {
// Initialize the library
if (!glfwInit()) return -1;
// Create a windowed mode window and its OpenGL context
GLFWwindow* 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();
}
glfwTerminate();
return 0;
}
-------------------------------------------------------------
3. Build code
g++ "Hello world.cpp" -o "Hello world" -lglfw -lGL
4. Run
./Hello\ world
5. Search GLFW version
apt show libglfw3-dev
沒有留言:
張貼留言