Vs2013 + glfw + glew configure OpenGL development environment

Transfer: http://blog.csdn.net/u011926277/article/details/50912638

Recently found a very good learning OpenGL basics website, click open the link. Since the configuration environment section is not very detailed, after many days of struggle, the development environment was successfully configured, for the record.
1. Download GLFW. The URL is: Click the open link. Because still have over the wall, so use the github download.
2. Download cMake. The URL is: Click the open link. The download is the version used by the author of this site, the Win32 Installer.
3. Download Glew. The URL is: Click the open link. Download the zip package, because the method used here is native compilation.

1> After the tool is prepared, a folder is set up in a directory to place the source code and library. OpenGL folder is set up on the machine, and include and libs folders are set up under it to place the source code and library respectively. The screenshot is shown below.

2> Since glew does not use cMake, glew is compiled first to get the required libraries.
A. Unpack Glew’s zip package, enter the build directory, and open the corresponding project with the corresponding version of VS (select the project under VS12 directory). VS2013 is used for this machine.
B. Open glew.sln with VS2013 or later and compile the project (right-click ->; Generate the solution).
C. Open glew-2.0.0\lib\Debug\Win32 and copy glew32sd.lib to OpenGL/libs.
D. Copy the GL folder from glew-2.0.0\include folder to the OpenGL/include folder.

3> To prepare the GLFW library, use the CMake tool to first generate the project and then compile it. The process is as follows.
A. After installing cMake, open cMake (cmake-gui) and click Browse Source to set the directory to the GLFW directory.
B. Click Browse Build and set the directory to the GLFW/Build folder. (The Build folder here needs to be created by yourself) as follows.

C. Click Configure in the lower left corner and select the target platform. Since this is VS2013, select Visio Studio 12 2013 and click OK.
D. Then click Configure again, and click Generate to build the project. The selection status is as follows.

E. Close cMake. Open the project in vs2013, compile it, and generate glfw3.lib after success.
F. Build \ SRC \Debug directory has just compiled the project generated glfw3.lib library, copy this library to the OpenGL/libs directory.
G. Copy the GLFW folder under GLFW-master /include to the OpenGL/include folder.
H. The files in the finally generated OpenGL folder are as follows:

4> At this point the basic environment is configured, and the next step is to link the libraries to the source code in a newly created, empty project, and import some libraries manually. The specific process is as follows.
A. Create an empty project. (C ++ project)
B. Right-click item ->; Property – & gt; Configure properties ->; Vc + + directories – & gt; Include the directory, add the path to OpenGL/include.
C. Right-click item ->; Property – & gt; Configure properties ->; Vc + + directories – & gt; Add the path to OpenGL/libs. The screenshot is shown below.

D. Right-click item ->; Property – & gt; Configure properties ->; The linker – & gt; Input – & gt; Attach dependencies to which to add
, the screenshot is as follows.

E. After saving the configuration in turn, you can enter the code in the Main class and test it. If no error is reported, that is, the environment is configured successfully, the test code can be tested from the beginning of the website or, or copy the code below.

#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;

// 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  
	// Set all the required options for GLFW  

	// Create a GLFWwindow object that we can use for GLFW's functions  
	GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
	if (window == nullptr)
		std::cout << "Failed to create GLFW window" << std::endl;
		return -1;
	// Set the required callback functions  
	glfwSetKeyCallback(window, key_callback);

	// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions  
	glewExperimental = GL_TRUE;
	// Initialize GLEW to setup the OpenGL Function pointers  
	if (glewInit() != GLEW_OK)
		std::cout << "Failed to initialize GLEW" << std::endl;
		return -1;

	// Define the viewport dimensions  
	glViewport(0, 0, WIDTH, HEIGHT);

	// Game loop  
	while (!glfwWindowShouldClose(window))
		// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions  

		// Render  
		// Clear the colorbuffer  
		glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

		// Swap the screen buffers  

	// Terminate GLFW, clearing any resources allocated by GLFW.  
	return 0;

// Is called whenever a key is pressed/released via GLFW  
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
	std::cout << key << std::endl;
	if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
		glfwSetWindowShouldClose(window, GL_TRUE);


F. After compilation and running, the following window appears on behalf of successful environment configuration.

At this point, the environment configuration is complete.

Thanks again for sharing, the environment is finally matched!!

Read More: