Ubuntu下glfw的安装与使用

第一步,下载glfw

到地址www.glfw.org下载glfw source code:glfw-3.2.1.zip,解压

$unzip glfw-3.2.1.zip -d glfw-3.2.1


第二步,编译安装glfw

1. 安装依赖库,
$sudo apt-get build-dep glfw
$sudo apt-get install cmake xorg-dev libglu1-mesa-dev
2. 进入 glfw3-3.x.x 目录,建立glfw-build子目录,
$sudo mkdir glfw-build
3. 进入glfw-build,使用cmake命令生成Makefile
$sudo cmake ../
4. make && make install
$sudo make
$sudo make install

第三步,使用glfw

建立main.cpp 输入下面的代码:
#include   
  
int main(void)  
{  
    GLFWwindow* window;  
  
    /* Initialize the library */  
    if (!glfwInit())  
        return -1;  
  
    /* Create a windowed mode window and its OpenGL context */  
    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 */  
  
        /* Swap front and back buffers */  
        glfwSwapBuffers(window);  
  
        /* Poll for and process events */  
        glfwPollEvents();  
    }  
  
    glfwTerminate();  
    return 0;  
}  




你可能感兴趣的:(Ubuntu下glfw的安装与使用)