zoukankan      html  css  js  c++  java
  • QT_OPENGL-------- 1. WINDOW

    opengl学习第一步,首先来实现一个显示窗口。

    1.首先要下载配置glfw,我在前面的文章中也提到过,具体作用可以另行百度。配置出现无法引用可参考ubuntu 使用glfw.h 出现函数无法调用

    2.构建qt空项目,新建-》Non-Qt Project-》Plain C++ Application-》工程名-》下一步。(创建一个只有一个main.cpp 和.pro文件)

    3.在.pro文件中添加glfw的动态链接

    LIBS+=-L/usr/local/lib -lglfw3 -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lpthread -ldl

    4.添加如下代码到main.cpp中

    #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(480, 320, "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))
        {
            /* Draw a triangle */
            glBegin(GL_TRIANGLES);
    
            glColor3f(1.0, 0.0, 0.0);    // Red
            glVertex3f(0.0, 1.0, 0.0);
    
            glColor3f(0.0, 1.0, 0.0);    // Green
            glVertex3f(-1.0, -1.0, 0.0);
    
            glColor3f(0.0, 0.0, 1.0);    // Blue
            glVertex3f(1.0, -1.0, 0.0);
    
            glEnd();
    
            /* Swap front and back buffers */
            glfwSwapBuffers(window);
    
            /* Poll for and process events */
            glfwPollEvents();
        }
    
        glfwTerminate();
        return 0;
    }

    最后的效果:

  • 相关阅读:
    经典分水岭算法的 C++ 实现
    一个简易的键盘按键测试程序
    工程优化方法中的“最速下降法”和“DFP拟牛顿法”的 C 语言实现
    基于哈夫曼编码的压缩解压程序(C 语言)
    博客选择:博客园 or CSDN
    Spring总结
    CSS总结
    EL表达式总结
    Jdbc总结
    hibernate总结
  • 原文地址:https://www.cnblogs.com/fuhang/p/10002016.html
Copyright © 2011-2022 走看看