0%

Setup OpenGL with Visual Studio 2019

Setup OpenGL with Visual Studio 2019

Installation

  1. Download GLUT header, lib, and dll files from OpenGL - GLUT
  2. Paste include->GL in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include
  3. Download https://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
    Paste glut32.lib in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\lib\x86
    and glut.lib in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\lib\x64
  4. Paste glut32.dll in C:\Windows\System32, C:\Windows, and glut.dll in C:\Windows\SysWOW64

Create a project

  1. Open Visual Studio, select create a new project, choose Empty Project.

  2. Go to Project -> Properties (Alt + F7), on the top select All Configurations from Configuration dropdown menu.
    Choose Configuration Properties -> C/C++ -> Precompiled Headers, set Precompiled Header‘s value to Not Using Precompiled Headers.
    Choose Configuration Properties -> Linker -> Input, click Additional Dependencies, and then click Edit, and type:

    opengl32.lib
    glu32.lib
    glut32.lib

    then click OK.

  3. Paste the code I found in Internet to test:

    #include <GL/glut.h>

    void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_POINTS);
    glVertex2f(10.0, 10.0);
    glVertex2f(150.0, 80.0);
    glVertex2f(100.0, 20.0);
    glVertex2f(200.0, 100.0);
    glEnd();
    glFlush();
    }

    void myinit() {
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glColor3f(1.0, 0.0, 0.0);
    glPointSize(5.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 499.0, 0.0, 499.0);
    }

    int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("Points");
    glutDisplayFunc(display);

    myinit();
    glutMainLoop();

    return 0;
    }

    Then Compile and run(x86).

One more thing…

If you upgrade VS, you should re-install OpenGL, since the folder is moved to a higher version one.

Reference

Special thanks to https://www.absingh.com/opengl/