Compilation and Installation Instructions for OpenGL on Windows
A. Compilation Steps for Visual C++ (VC++) 20xx
(similar for various VC++ versions; we use Visual Studio/VC++ 2019 below as an example):
-
Start Visual Studio 2019 from the start menu. From "Get
started" on the right, left click "Continue without code" at the
bottom.
-
On the top tool bar of the next window, left click File -> New -> Project.
On the right, left click "All languages" and
select C++. Then left click Empty Project and
click Next. In the next window, give the parent
folder location (e.g., "...\CS6533") as the "Location" and give
a project name (e.g., "Example") as "Project name". Click to
select Place solution and project in the same
directory. Then click Create. A new folder
"...\CS6533\Example" is created for the project.
(If you already have an existing folder "...\CS6533\Example" containing all
source files and you want to use it as the project folder,
first rename it to something else like
"...\CS6533\Example-temp", follow the process in this step (Step 2)
to create "...\CS6533\Example" as the project folder, move all
source files from "...\CS6533\Example-temp" to "...\CS6533\Example"
and then delete the folder "...\CS6533\Example-temp".)
- If you want to open an existing project, instead of Step 2 above,
go to the project folder created before (e.g., "...\CS6533\Example"
mentioned in Step 2) and left-click to open the VC++ solution
(*.sln) file or VC++ project (*.vcxproj) file.
-
Move all source (.c or .cpp) files, header (.h) files, shader (.glsl)
files (if any), and input data files to the project folder (e.g.,
"...\CS6533\Example" mentioned in Step 2).
In the right sub-window of VC++, right click Source Files and
select Add -> Existing Item to include the source (.c or
.cpp) files into the project as source files (you can select multiple
files at once). Similarly include the .h files (if any) as Header
Files. (For shader files *.glsl, just put them to the same
project folder without including them.) You can left click any .c,
.cpp, or .h file already included into the project to show the file in
the main sub-window and edit the file there.
-
On the top tool bar, second row, there are two white windows side by
side with the left one showing "Debug" and the right one showing "x86"
by default. The "x86" means the system is using the 32-bit
version. Left-click this "x86" window and select "x64" to change it
to the 64-bit version (this corresponds to using the 64-bit
version of the *.lib and *.dll files of the FreeGLUT and GLEW
packages; see
B. Installation on Your Own Computer Step (2) below).
Remark: If you use the 32-bit version, then skip this step and
leave the "x86" window unchanged.
-
For OpenGL projects that use GLEW (such as those involving GLSL), it
is necessary to declare the dependencies for the GLEW library
("glew32.lib") being used:
a.
Click on Debug -> [project name] Debug Properties.
b.
(This step can be skipped if the following items already show up as default from step a.)
In the left window, click Configuration Properties to expand it.
On the very top left, the Configuration drop-down, select
All Configurations.
c.
Below Configuration Properties, select Linker -> Input.
d.
In the right window, click Additional Dependencies to
activate this field.
Type in
"glew32.lib;" .
Then click OK.
Remark on step d: Also type in "freeglut.lib;opengl32.lib;glu32.lib" in
case they cannot be automatically found during linking.
-
To compile, click on Build -> Build [project name]
(or Rebuild [project name]).
To run, click on Debug -> Start Without Debugging (or Ctrl+F5).
Additional Notes/Tips:
(1)
In our sample code we may use C functions like "fscanf()" and
"fopen()", but VC++ 2019 would give errors like:
" 'fscanf': / 'fopen': This function or variable may be
unsafe. Consider using fscanf_s / fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for
details."
To fix, use "_CRT_SECURE_NO_WARNINGS" as follows
(this is strongly recommended):
As in Step 6 above, do Debug -> [project name] Debug
Properties, then below Configuration Properties,
click C/C++ -> Preporocessor. In the right window, left
click Preprocessor Definitions to activate it, then copy and
paste in "_CRT_SECURE_NO_WARNINGS;" and click OK.
(2)
(The following was an issue for VC++ 2017 but has been
fixed in VC++ 2019. So just check to make sure that it is set up as
desired.)
In case the console window disappears after the program stops, any
"debugging messages" printed to the console cannot be seen. To fix
and have the console window stay (this is strongly
recommended), do as follows:
As in Step 6 above, do Debug -> [project name] Debug Properties, then
below Configuration Properties, select Linker ->
System. In the right window, left click Subsystem to
activate the field and left click the arrow on the right, and
select Console (/Subsystem:Console), then click OK.
B. Installation on Your Own Computer:
(1) You need to have the VC++ software installed. A free
download version, Visual Studio Community 2019, is available
and can be downloaded directly from the course web
site
here for your
convenience. Save and run it to install.
(2) You also need to get the FreeGLUT package (available
from the course web site
here) and the GLEW
package (available from the course web site
here). After unzipping the FreeGLUT and GLEW packages, get the
following files (for the 64-bit version; the 32-bit version can be
obtained similarly): (1) From FreeGLUT, get bin/x64/freeglut.dll,
lib/x64/freeglut.lib, and include/GL/*.h (they are glut.h, freeglut.h,
freeglut_ext.h, freeglut_std.h). (2) From GLEW, get
bin/Release/x64/glew32.dll, lib/Release/x64/glew32.lib,
include/GL/glew.h, and include/GL/wglew.h. Put these files to the
specified folders as below:
1. glut.h, freeglut.h, freeglut_ext.h, freeglut_std.h, glew.h,
wglew.h:
Search for the folder containing "gl.h" and "glu.h" (some
letters may be in upper case), and put these new *.h files
there.
2. freeglut.lib, glew32.lib:
Search for the folder containing "opengl32.lib" and
"glu32.lib" (some letters may be in upper case), and put these new
*.lib files there.
3. freeglut.dll, glew32.dll:
Search for the folder containing "opengl32.dll" and
"glu32.dll" (some letters may be in upper case), and put these new
*.dll files there.