How to use glut library in Qt project

1. The installation of
Qt itself does not include the glut tool library. If you want to use the glut library, here is a brief description of how to install the glut library under Qt:

1) First, you need to download the glut library from the OpenGL website:
http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

2) After decompression, copy the two files glut32.lib and glut.lib to the ./lib folder under the qt directory;

3) Copy the two dynamic link libraries glut.dll and glut32.dll to C:\windows\system32;

4) Copy the glut.h file to \include\QtOpenGL under the qt directory, and create a glut file [content #include "glut.h"], and save it as a file without a suffix;

5) Switch to your own program and add in the **.pro file:
LIBS += -lgut32
-lglut

6) Add "#include" or "#include<glut.h>" in main.cpp so that the functions in glut can be used.


2. Use case

void display(void)
{
    
    
    // clear all pixels
    glClear(GL_COLOR_BUFFER_BIT);
    
    glColor3f(0.5, 0.1, 1.0);
    glBegin(GL_POLYGON);
    glVertex3f(0.20, 0.20, 0.0);
    glVertex3f(0.80, 0.20, 0.0);
    glVertex3f(0.80, 0.80, 0.0);
    glVertex3f(0.20, 0.80, 0.0);
    glEnd();                            
    glFlush();
}

void init(void)
{
    
    
    // select clearing color: blue
    glClearColor(0.0, 1.0, 0.0, 0.0);

    // initialize viewing values
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char *argv[])
{
    
    
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(248, 248);
    glutInitWindowPosition(480, 320);
    glutCreateWindow("polyon");
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

Operation effect:
Insert picture description here
3. Exception handling
If it fails to start during operation, or the following error message pops up, copy the two dynamic link libraries glut.dll and glut32.dll to the running directory and restart.
Insert picture description here

Guess you like

Origin blog.csdn.net/locahuang/article/details/110197828