Getting Freeglut C++

Sid Kraft 46 Reputation points
2026-07-22T23:30:13.08+00:00

I am programming in C++ using Visual Studio. I thought that I had all of the #include<...> directives in my program but after I tried to open a window to output graphic data from OpenGL, still looking for directives or library elements. Went to the OpenGL site and was suggested that I enter the element #include<GL/glut.h>. I subsequently downloaded the file "freeglut" from the OpenGL site. Then entered the #include<GL/glut.h> and the compiler said that the directive could not be found. I suspect that I have to include the location of the GL/glut.h element in the C/C++ Additional Directories and/or the V++ additional directories and the Linker additional directories, not sure which to do. Also, when one enters multiple additional directories does one separate by "," or " " or ";"? Also, not sure that GL/glut.h is in the Freeglut system either. Any help will be appreciated, Sid Kraft

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


5 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 7,745 Reputation points Microsoft External Staff Moderator
    2026-07-23T06:19:09.49+00:00

    Hello @Sid Kraft ,

    Thanks for your question.

    It sounds like the compiler cannot find GL/glut.h because Visual Studio has not been told where the freeglut files are located on your machine. Downloading the package is the first step - the paths still need to be added to the project settings.

    First, please check whether the file actually exists on your machine. After extracting freeglut, you should see:

    <your_freeglut_folder>\include\GL\glut.h
    

    If that file isn't present, you may have downloaded the source package rather than a pre-built version. In that case, you might find the following package easier to use with Visual Studio: freeglut

    Also, make sure the freeglut libraries match the platform you're building for in Visual Studio:

    • x86 build → use the libraries from the lib\x86 folder
    • x64 build → use the libraries from the lib\x64 folder

    Mixing them usually results in linker error LNK1112.

    For the project settings, you'll normally need all three of the following:

    • C/C++ → General → Additional Include Directories. Please add <your_freeglut_folder>\include. This allows the compiler to locate glut.h.
    • Linker → General → Additional Library Directories. Please add <your_freeglut_folder>\lib\x64 (or x86, depending on your build target). This tells Visual Studio where to find the .lib files.
    • Linker → Input → Additional Dependencies. Please add freeglut.lib;opengl32.lib;glu32.lib. This tells the linker which libraries your project needs.

    Regarding your question about separators, Visual Studio expects multiple entries to be separated by semicolons (;). If you're unsure, click Edit... next to the field, and Visual Studio will let you add each entry on a separate line.

    One other thing to watch for: even after the project builds successfully, Windows may report that freeglut.dll is missing when you run the application. If that happens, copy freeglut.dll from the appropriate bin\x64 or bin\x86 folder into the same folder as your compiled .exe.

    While this is a non-Microsoft link, it’s official Nuget documentation and is safe to visit.

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 84,671 Reputation points
    2026-07-23T17:27:47.9+00:00

    create new visual studio c++ project named TestOpenGL. checked that under properties vcpkg:

    • use vcpkg was enabled
    • use vcpkg manifest was enabled

    in the vs powershell terminal (be sure the working folder is the project folder):

    > vcpkg integrate install
    > vcpkg new --application
    > vcpkg add port freeglut
    

    then replace TestOpenGL.cpp text with:

    #include <GL/freeglut.h>
    
    void display() {
        glClear(GL_COLOR_BUFFER_BIT); // Clear the window
    
        // Draw a white triangle
        glBegin(GL_TRIANGLES);
        glVertex2f(0.0f, 0.5f);
        glVertex2f(-0.5f, -0.5f);
        glVertex2f(0.5f, -0.5f);
        glEnd();
    
        glFlush(); // Render now
    }
    
    int main(int argc, char** argv) {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
        glutInitWindowSize(500, 500);
        glutInitWindowPosition(100, 100);
        glutCreateWindow("FreeGLUT Triangle");
    
        glutDisplayFunc(display); // Register the display callback
        glutMainLoop();           // Enter the event loop
    
        return 0;
    }
    
    

    then rebuild & run

    Was this answer helpful?

    0 comments No comments

  3. Alex James 0 Reputation points
    2026-07-23T11:53:28.1266667+00:00

    If you're using freeglut, you should include <GL/freeglut.h>, not GL/glut.h, unless your package provides a compatibility header.

    Also, installing the library isn't enough. Your compiler needs to know where the include and library folders are, and your project must link against the freeglut/OpenGL libraries. If you're using vcpkg, that setup is handled automatically after integrating it with Visual Studio.

    One question: did you install freeglut manually, or through vcpkg? That will determine the easiest fix.

    Was this answer helpful?

    0 comments No comments

  4. Castorix31 91,886 Reputation points
    2026-07-23T08:02:27.5633333+00:00

    Was this answer helpful?

    0 comments No comments

  5. AI answer

    2026-07-22T23:30:34.64+00:00

    For OpenGL on Windows, these headers are the relevant ones:

    1. Core OpenGL: #include <GL\gl.h>
    2. OpenGL Utility Library: #include <GL\glu.h>
    3. WGL and Windows support: #include <windows.h>

    If a header such as GL\glut.h or another OpenGL-related header cannot be found, that means the compiler include search path does not contain the directory where that header exists.

    In Visual Studio, add include paths here:

    1. Open Project Properties.
    2. Go to Configuration Properties > C/C++ > General.
    3. Edit Additional Include Directories.
    4. If adding more than one directory in that property, separate them with a semicolon (;).

    Visual Studio also has VC++ Directories > Include Directories, but for the compiler option itself, C/C++ > General > Additional Include Directories is the documented place to add include directories.

    How include lookup works:

    • #include "file.h" searches the source file’s directory first, then parent include directories, then directories from /I, then INCLUDE.
    • #include <file.h> searches the directories specified by /I first, then INCLUDE.
    • If using a relative path in the include directive, use double quotes, not angle brackets.

    If building inside the Visual Studio IDE, the INCLUDE environment variable is ignored, and the project include directory settings are used instead.

    For command-line builds, /I adds include directories. Example behavior:

    • /I path1 /I path2
    • directories are searched in the order specified

    If the header is physically under a folder structure like ...\GL\glut.h, then the include directory should be the parent folder above GL, and the source should use:

    #include <GL\glut.h>
    

    If the include directory already points directly to the GL folder, then the directive would need to match that layout. The include path and the #include text must be consistent.

    Also check that the file is actually present where expected. A file being part of a project or downloaded separately does not make it automatically discoverable by the compiler unless it is in the include search path.


    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.