VisualStudio中配置OpenGL环境并制作模板
本教程来自:sumantaguha
Install Visual Studio
- Download Microsoft Visual Studio Community 2019 from https://my.
visualstudio.com/Downloads?q=visual%20studio%202019&wt.mc_
id=omsftvscom~older-downloads and follow the installation steps.
On the tool bar of the MSVS page click Project → OpenGLPro
jectTemplate Properties to bring up the Property Pages. Select All
Configurations from the dropdown menu to the right of “Configura
tion:”.
Install Helper Libraries
-
Create a folder called OpenGLwrappers in the C: drive, so this folder is C:\OpenGLwrappers. This particular name and location is so that all our programs in ExperimenterSource run out of the box.
The version numbers below of the libraries we ask you to download
may not be the latest but they are the ones we have installed in
our environment. There are sometimes little things that differ with
versions. To be sure, we have not yet heard of a problem in upgrading to a newer version. Still, to avoid any issues at all while you are learning we suggest you install the exact versions below. -
FreeGLUT:Downloadandunzipthe file http://files.transmissionzero.
co.uk/software/development/GLUT/older/freeglut-MSVC-2.8.1-1.
mp.zip and save the folder freeglut-MSVC-2.8.1-1.mp in OpenGLwrappers. -
GLEW: Download and unzip the file https://sourceforge.net/
projects/glew/files/glew/1.10.0/glew-1.10.0-win32.zip/ download
and save the folder glew-1.10.0-win32 in OpenGLwrappers. -
GLM: Download and unzip the file https://github.com/g-truc/
glm/releases/download/0.9.7.5/glm-0.9.7.5.zip and save the
folder glm-0.9.7.5 in OpenGLwrappers. -
Copy freeglut.dll from C:\OpenGLwrappers
freeglut-MSVC-2.8.1-1.mp\freeglut\bin to C:\Windows\SysWOW64. -
Copy glew32.dll from C:\OpenGLwrappers\glew-1.10.0-win32
glew-1.10.0\bin\Release\Win32 to C:\Windows\SysWOW64. -
Check if glu32.dll is already in C:\Windows\SysWOW64. Normally,
it should be. If not, search resources on the web to reinstall it there.
Create and Use an OpenGL Project Template
- Open Visual Studio 2019 from the Start Menu. Click “Create a new
project” and in the next page search for “C++” in the templates search
box and select C++ Console App. Click Next. In the “Configure
your new project” page enter OpenGLProjectTemplate for Project
name and for Location any convenient folder. Check the box “Place
solution and project in the same directory”. Click Create.
- The MSVS page of OpenGLProjectTemplate comes up. On the tool
bar click View → Solution Explorer to open the Solution Explorer pane.
Under the Source Files item you will find OpenGLProjectTemplates.cpp.
Double click it to open it in another pane.
3.On the tool bar of the MSVS page click Project → OpenGLPro
jectTemplate Properties to bring up the Property Pages. Select All
Configurations from the dropdown menu to the right of “Configura
tion:”.
4.Expand Configuration Properties and click Configuration Properties
→C/C++ →General → Additional Include Directories → ⟨Edit…⟩
(in the drop-down menu) to open the Additional Include Directories
dialog box. Click the New Line icon successively to create a new line
to add each of the following folders (order doesn’t matter; you can
click the box with “…” at the right of the empty new line to navigate
to the folder):
(1) C:\OpenGLwrappers\freeglut-MSVC-2.8.1-1.mp\freeglut
include
(2) C:\OpenGLwrappers\glew-1.10.0-win32\glew-1.10.0
include
(3) C:\OpenGLwrappers\glm-0.9.7.5\glm
Click OK to confirm.
添加包含目录
5.Click Configuration Properties → Linker → General → Additional
Library Directories → ⟨Edit…⟩ (in the drop-down menu) to open the
Additional Library Directories dialog box. Click the New Line icon
successively to create a new line to add each of the following folders
(order doesn’t matter; you can click the box with “…” at the right of
the empty new line to navigate to the folder):
(1) C:\OpenGLwrappers\freeglut-MSVC-2.8.1-1.mp\freeglut
lib
(2) C:\OpenGLwrappers\glew-1.10.0-win32\glew-1.10.0
lib\Release\Win32
Click OK to confirm.
6.Click Configuration Properties → Linker → Input → Additional
Dependencies → ⟨Edit…⟩ (in the drop-down menu) to open the
Additional Dependencies dialog box. Manually enter the following file
names one per line in the window at the top (order doesn’t matter):
(a) glew32.lib
(b) opengl32.lib
Click OK to confirm.
删除源文件后创建模板
7.On the MSVS toolbar click File → Save All. Next click Project
→ Export Template. In the Export Template Wizard choose the
Project template radio button and click Next. Name the template
OpenGLProjectTemplate and check the box “Automatically import
the template into Visual Studio” and uncheck the box “Display an
explorer window on the output files folder”. Click Finish. The
template OpenGLProjectTemplate has been created and you can, in
fact, now delete the project OpenGLProjectTemplate from the folder
you created it in.
)
)
)
To use the template, open Visual Studio 2019 from the Start Menu
to bring up the MSVS Start Page. Click Create a new project and
search for and select the template OpenGLProjectTemplate. Click
Next. Name the project and select an appropriate folder for its
location and click Create. The new project comes up. Right click on
Source Files in the Solution Explorer to add a New Item. Choose
C++ File for the type of this item, give a Name, and Add. A .cpp
file pops up in a pane in which you can now write C++/OpenGL
code.
以此为模板建立自己的源文件