1、下载GLEW
地址:http://glew.sourceforge.net/index.html
点击 Windows 32-bit and 64-bit
2、下载GLFW
地址:http://www.glfw.org/download.html
点击 32-bit Windows binaries
3、解压这两个压缩包,然后把glew-2.0.0-win32\glew-2.0.0\bin\Release\Win32中的glew32.dll拷贝到
C:\Windows\System32和C:\Windows\SysWOW64中
4、把glfw-3.2.1.bin.WIN32\glfw-3.2.1.bin.WIN32\lib-vc2010中的glfw3.dll拷贝到
5、把glew-2.0.0-win32\glew-2.0.0\lib\Release\Win32中的glew32.lib和glew32s.lib拷贝到
...\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib中
6、把glfw-3.2.1.bin.WIN32\glfw-3.2.1.bin.WIN32\lib-vc2010中的glfw3.lib和glfw3dll.lib拷贝到
...\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib中
7、新建一个文件夹OpenGL,再建子文件夹include,然后把glew-2.0.0-win32\glew-2.0.0\include中的GL文件夹拷贝到新建的include中
再把glfw-3.2.1.bin.WIN32\glfw-3.2.1.bin.WIN32\include中的GLFW文件夹拷贝到新建的include中
8、创建一个新的控制台空项目,添加.cpp文件
9、修改项目属性——》VC++目录——》包含目录
添加刚才创建的include文件夹的路径,比如我的是D:\OpenGL\include
10、修改链接器——》输入——》附加依赖项
添加opengl32.lib
glfw3.lib
glew32s.lib
glew32.lib
11、将如下代码拷贝到刚创建的.cpp中:
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
// Function prototypes
void
key_callback
(
GLFWwindow
*
window
,
int
key
,
int
scancode
,
int
action
,
int
mode
);
// Window dimensions
const
GLuint
WIDTH
=
800
,
HEIGHT
=
600
;
// Shaders
const
GLchar
*
vertexShaderSource
=
"#version 330 core
\n
"
"layout (location = 0) in vec3 position;
\n
"
"void main()
\n
"
"{
\n
"
"gl_Position = vec4(position.x, position.y, position.z, 1.0);
\n
"
"}
\0
"
;
const
GLchar
*
fragmentShaderSource
=
"#version 330 core
\n
"
"out vec4 color;
\n
"
"void main()
\n
"
"{
\n
"
"color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
\n
"
"}
\n\0
"
;
// The MAIN function, from here we start the application and run the game loop
int
main
()
{
std
::
cout
<<
"Starting GLFW context, OpenGL 3.3"
<<
std
::
endl
;
// Init GLFW
glfwInit
();
// Set all the required options for GLFW
glfwWindowHint
(
GLFW_CONTEXT_VERSION_MAJOR
,
3
);