使用glfw建立opengl应用程序

来源:互联网 发布:倾斜摄影数据处理软件 编辑:程序博客网 时间:2024/05/22 06:50

这里有篇答疑的文章

http://stackoverflow.com/questions/17768008/how-to-build-install-glfw-3-and-use-it-in-a-linux-project

不过看得多也没有什么用。

重点是如何编译下面这个源程序

gcc glfw-demo.c -L/usr/local/lib -lglfw3 -lrt -lXrandr -lXinerama -lXi -lXcursor -lGL -lm -ldl -lXrender -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp

是不是超级长,但是这个编译是正确的,会生成a.out程序,运行会有一个窗口。

#include <GLFW/glfw3.h>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 */        glClear(GL_COLOR_BUFFER_BIT);        /* Swap front and back buffers */        glfwSwapBuffers(window);        /* Poll for and process events */        glfwPollEvents();    }    glfwTerminate();    return 0;}


0 0