OpenGL installation tutorial

1. Environment introduction

  • Operating system: windows10 home Chinese version
  • System Type: 64-bit OS, x64-based processor
  • vs version: visual studio 2013

Second, opengGL environment configuration

2.1 Here we have three resource files, namely dll, GL and lib folders

write picture description here

  • Dynamic link library dll (dynamic link library)

    write picture description here

  • GL file

    write picture description here

  • lib file

    write picture description here

2.2 Copy the contents of the three folders to the corresponding directory

  • Dynamic link library dll (dynamic link library)

    C:\Windows\System32
    C:\Windows\SysWOW64

  • GL file

    D:\vs\VC\include
    Note: D:\vs is the installation directory of my vs2013

  • lib file

    D:\vs\VC\lib

2.3 Environment configuration in visual studio

  • Right-click the opengGL project created

write picture description here

  • Select Properties at the bottom

write picture description here

  • Find the Additional include Directories option and add the path where the header file resources are located (the GL folder mentioned in section 2.1 is found here)
    write picture description here

    write picture description here

  • Find the Additional Libraries Directories option and add the path where the library file resources are located (the lib folder mentioned in section 2.1 is found here)

write picture description here

write picture description here

  • Add Lib dependencies in Linker/input/Addtional Dependencies
    GLAUX.LIB
    glew32.lib
    glew32mx.lib
    glew32mxs.lib
    glew32s.lib
    OPENGL32.LIB
    glut32.lib
    glut.lib
    GLU32.LIB

    exist

3. Environmental testing


#define GLUT_DISABLE_ATEXIT_HACK
#include <Windows.h>
#include <glut.h>      // (or others, depending on the system in use)

void init(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);  // Set display-window color to white.

    glMatrixMode(GL_PROJECTION);       // Set projection parameters.
    gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}

void lineSegment(void)
{
    glClear(GL_COLOR_BUFFER_BIT);  // Clear display window.

    glColor3f(0.0, 0.4, 0.2);      // Set line segment color to green.
    glBegin(GL_LINES);
    glVertex2i(180, 15);       // Specify line-segment geometry.
    glVertex2i(10, 145);
    glEnd();

    glFlush();     // Process all OpenGL routines as quickly as possible.
}

void main(int argc, char** argv)
{
    glutInit(&argc, argv);                         // Initialize GLUT.
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);   // Set display mode.
    glutInitWindowPosition(50, 100);   // Set top-left display-window position.
    glutInitWindowSize(400, 300);      // Set display-window width and height.
    glutCreateWindow("An Example OpenGL Program"); // Create display window.

    init();                            // Execute initialization procedure.
    glutDisplayFunc(lineSegment);       // Send graphics to display window.
    glutMainLoop();                    // Display everything and wait.
}

4. Operation results

write picture description here

5. Problems and solutions

  • error C2381: "exit" : redefine; __declspec(noreturn) is different

    OpenGL and C++ are not very integrated. When including, the header file of the standard C++ class library should be placed before the GLUT graphics library header file.

#include <Windows.h>
#include <glut.h>    
  • The reason for the lack of OPENGL.DLL when running prompts

    opengl does not know which version of the instruction it should call now, whether it is opengl32.dll or OPENGL.dll, we only put opengl32.dll in the directory, and then add the windows.h header file in the code.

#include <Windows.h>
  • Error 1 error LNK2019: unresolved external symbol imp__
    glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8 D:\c++\openGL\openGL\ch3OGLexample.obj openGL

    Add #define GLUT_DISABLE_ATEXIT_HACK before glut.h header file

#define GLUT_DISABLE_ATEXIT_HACK
#include <Windows.h>
#include <glut.h>    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578955&siteId=291194637