How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017


Many programmers prefer OpenGL for graphics. If you are one of them, you are strongly advised by its producer, to use a window toolkit (such as freeGLUT) and an OpenGL loading libraries (such as GLEW). This guide will help you get over the first challenge of using OpenGL with freeGLUT and GLEW: Installing and setting them up, and creating your first project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017.

This guide will assume your platform is Windows and your IDE is Visual Studio 2017. During Visual Studio installation, check the Desktop development with C++ workload box.

Part 1
Downloading freeGLUT and GLEW

Downloading freeGLUT and GLEW on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

1
In directory (disk) C:, create (by right click > New > Folder) a new folder with name OpenGL.

Downloading freeGLUT and GLEW on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

2
Load up . Below Downloads click Windows 32-bit and 64-bit. Navigate to C: > OpenGL. Drag (or copy and paste) the folder glew-2.1.0 from the window where it is downloaded, into folder OpenGL. Click on name glew-2.1.0 and rename it to glew. If folder glew-2.1.0-win32 is downloaded, double click it to get glew-2.1.0.

Downloading freeGLUT and GLEW on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

3
0.0 MSVC Package. It can be found at . Navigate to C: > OpenGL. Drag (or copy and paste) the freeglut folder from the window where it is downloaded, into folder OpenGL.

Part 2
Creating a Visual Studio Project

Creating a Visual Studio Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

1
In the Visual Studio main menu, click File. Then go to New > Project… In the left part of the new project window, click Visual C++ if it is not selected. In the center of the screen, click Empty Project. Below that, find the Name text box, type Project-0. Next to Location text box, click Browse... and navigate to C: > OpenGL. Click Select a folder. The Location in New Project window is C:\OpenGL\. Make sure the Create directory for solution box is not checked. Click OK.

Creating a Visual Studio Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

2
In the solution explorer window (at the left side of the screen), right click the Source Files folder (the last one). Click Add > New Item… In the Add New Item - Project-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box, type Main.cpp. The Location is C:\OpenGL\Project-0\. Click the Add button. The file will open in the main text editor but leave the file blank for now.

Part 3
Installing freeGLUT and GLEW on a Project

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

1
Open the C/C++ drop-down menu. Click General > Additional Include Directories. Click the down arrow at the right of the field and then Edit in the drop down menu. Add freeglut\include folder: In Additional Include Directories window, click the first icon and then copy and paste, C:\OpenGL\freeglut\include Add glew\include folder: Click again the first icon > copy and paste: C:\OpenGL\glew\include Click OK on Additional Include Directories window.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

2
Click Additional Library Directories entry, and click the down arrow at the right of the field. Click Edit in the drop-down menu. Add the freeglut\lib folder: In the Additional Library Directories window, click the first icon and copy and paste, C:\OpenGL\freeglut\lib Add the glew\lib\Release\Win32 folder: Click the first icon, and copy and paste C:\OpenGL\glew\lib\Release\Win32 Click OK.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

3
Click the Additional Dependencies entry and then the down arrow at the right of the field. Select Edit in the drop-down menu. On the top-most text box of the Additional Dependencies window, copy and paste, freeglut.lib; glew32.lib; opengl32.lib Click OK in the Additional Dependencies window.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

4
Click the down arrow and select Console(/SUBSYSTEM:CONSOLE) from the dropdown menu. Click Apply, then OK on the Project Property Pages window.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

5
dll file and paste to Project-0 folder. Navigate to C: > OpenGL > freeglut > bin. Inside bin folder click freeglut.dll file > right-click > Copy. Navigate to C: > OpenGL > Project-0. Right-click an empty area in Project-0 folder, and select Paste. The freeglut.dll file should now be in your project directory along with your Main.cpp file and a few other files created by Visual Studio.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

6
dll file and paste to Project folder Navigate to C: > OpenGL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy. Navigate to C: > OpenGL > Project-0. Right-click an empty area in Project-0 folder, and select Paste. The glew32.dll file should now be in Project-0 folder along with Main.cpp, freeglut.dll, and a few other files created by Visual Studio.

Installing freeGLUT and GLEW on a Project on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

7
cpp code area. On the VS main menu, click the green arrow Local Windows Debugger, or press Ctr+F5, and wait... If everything went well two windows appear: one black and one with the title title: White Square and inside a white square with black background. If there is any problem try fix the error(s). If you fail, try the above steps again. #include <GL\glew.h> #include <GL\freeglut.h> void displayMe(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f( 0.5, -0.5); glVertex2f( 0.5, 0.5); glVertex2f(-0.5, 0.5); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(800, 800); glutInitWindowPosition(200, 50); glutCreateWindow("White Square"); glutDisplayFunc(displayMe); glutMainLoop(); return ; }

Part 4
Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017

Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017 on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

1
Go to Visual Studio main menu and, while Project-0 is open, click Project > Export Template.... On Export template Wizard check Project Template, if it's not checked. Click Next >. On Select Template Options, in Template name text box type: OpenGL-freeGLUT-GLEW. Click Finish. The Template has been created.

Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017 on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

2
... On the New Project window, click template: OpenGL-freeGLUT-GLEW. In Name text field, type: Project-1. Be sure Create directory for solution is unchecked. Click OK. In the Solution Explorer, double click Source Files. Below that, ++Main.cpp appears, click it. Its code appears in the code area. Run it. If code does not appear, right click ++Main.cpp > click Exclude From Project. Now create new Main.cpp.

Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017 on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

3
dll file to new project-folder Navigate to C: > OpenGL > Project-0 > click file freeglut.dll > right click > click Copy. Navigate to C: > OpenGL > Project-1 > click on empty area > right click > click Paste. Now file freeglut.dll is in folder Project-1 among Main.cpp and other 4 files.

Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017 on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

4
dll file to new project-folder Navigate to C: > OpenGL > Project-0 > click file glew32.dll > right click > click Copy. Navigate to C: > OpenGL > Project-1 > click on empty area > right click > click Paste. Now the file glew32.dll is in the folder Project-1 among freeglut.dll, Main.cpp and other 4 files.

Creating a Project with OpenGL-freeGLUT-GLEW Template in Visual Studio 2017 on How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio 2017

5
Good job!