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;
    }

    最后的效果:

  • 相关阅读:
    移动web性能优化从入门到进阶
    授权保存到相册
    授权通讯地址
    windows putty 链接到 linux 免密码
    my docker note
    docker run -i -t --rm
    Command Not Found
    firewall-cmd 笔记
    vim 插件 Tabularize
    vim :find
  • 原文地址:https://www.cnblogs.com/fuhang/p/10002016.html
Copyright © 2011-2022 走看看