Environment configuration for OpenGL 4 under windows7+vs2012

Source: Internet
Author: User

System environment

Windows 7 Ultimate x64,visual Studio Ultimate Update 4, and a piece of video card that supports OpenGL 4.x.

Preparatory work

First, use the GPU Caps Viewer to check the maximum supported OpenGL and GLSL versions of the machine. For example, my machine can support OpenGL 4.5 and GLSL 4.5:

Download the source code for Glew and GLFW. The Glew is used to manage and load OpenGL's various extension libraries, GLFW used to create Windows and control the interaction of the mouse and keyboard. The versions I used were glew-1.12.0 and glfw-3.1.1. The following were:

Https://sourceforge.net/projects/glew/files/glew/1.12.0/glew-1.12.0.zip/download

Http://sourceforge.net/projects/glfw/files/glfw/3.1.1/glfw-3.1.1.zip/download

Download and install CMake. Used to assist in compiling GLFW. The version I am using is cmake-3.2.1. For:

Http://www.cmake.org/files/v3.2/cmake-3.2.1-win32-x86.exe

Compiling GLFW

Open CMake. Click "BROWSW Source ..." To select the root directory of GLFW and click "Browse build ..." To choose a new folder as the output directory. Click "Configure":

In the pop-up window, select "Visual Studio 11 2012" and click "Finish":

Keep the default configuration. If you want to use the header file +.dll call GLFW, you can check the "build_shared_links", do not tick the default header file +.lib method call. Select a new location for "Cmake_install_prefix" to hold the result of compiling the output with VS2012. Then click "Generate", the VS2012 project file will be generated.

Open the build directory that you just specified, and open the GLFW.sln file with Visual Studio 2012. For the sake of insurance, first compile Zero_check with debug, if there is no error, then compile the all_build with release, and then compile the install.

If the compilation is successful, there will be two more folders included and Lib in the previously specified GLFW folder, which contains the header files and the link library files we will use:

Copy the GLFW folder in the include to a location that you find convenient, such as "E:\dev-lib\opengl4\include":

Copy the Glfw3.lib file in Lib to a new location, such as "E:\dev-lib\opengl4\lib":

Compiling Glew

Open the Build\vc10\glew.sln file in the Glew directory with Visual Studio 2012, and the first time you open it, you will be prompted to convert the VS2010 project to a VS2012 project and select Yes. Select release mode, click Build, Build Solution:

If the compilation is successful, you will find 3 new files in the Bin\release\win32 directory. Copy the Glew32.dll file to the C:\Windows\SysWOW64 directory.

Glewinfo.exe and Visualinfo.exe can be used to see how the system supports OpenGL features, such as:

Copy the glew32.lib from the Lib\release\win32 directory to the previous "E:\dev-lib\opengl4\lib". Copy the GL folder in the Include directory to the previous "E:\dev-lib\opengl4\include".

New Project

Open Visual Studio 2012, click File-New, Project ..., select Visual C + + Win32 Console application. For example, named "Ogl4-test":

Right-click the project name and click Properties. In the configuration Properties, VC + + directories, add "E:\dev-lib\opengl4\include;" for include directories ; add "E:\dev-lib\opengl4\lib;" For library directories. Note for both debug and release to be added:

In configuration Properties, Linker, input, add "glew32.lib;glfw3.lib;opengl32.lib;" For additional dependencies. Note for both debug and release to be added:

Copy the following code into the 0gl4-test.cpp file. Code from Anton ' s OpenGL 4 tutorials

#include"stdafx.h"#include<GL/glew.h>//#define Glfw_dll#include <GLFW/glfw3.h>intMainintARGC, _tchar*argv[]) {    //start GL context and O/S window using the GLFW helper library    if(!Glfwinit ()) {fprintf (stderr,"error:could not start glfw3\n"); return 1; } Glfwwindow* Window = Glfwcreatewindow ( -, -,"Hello Triangle", NULL, NULL); if(!window) {fprintf (stderr,"error:could not open window with glfw3\n");        Glfwterminate (); return 1;                                      } glfwmakecontextcurrent (window); //start Glew Extension HandlerGlewexperimental =gl_true;    Glewinit (); //Get version Info    Constglubyte* renderer = glgetstring (gl_renderer);//Get renderer string    Constglubyte* Version = Glgetstring (gl_version);//version as a stringprintf ("Renderer:%s\n", renderer); printf ("OpenGL version supported%s\n", version); //Tell GL to only draw onto a pixel if the shape is closer to the viewerGlenable (gl_depth_test);//Enable Depth-testingGldepthfunc (gl_less);//Depth-testing interprets a smaller value as "Closer"        floatPoints[] = {        0.0f,0.5f,0.0f,        0.5f, -0.5f,0.0f,        -0.5f, -0.5f,0.0f    }; Gluint Vbo=0; Glgenbuffers (1, &VBO);    Glbindbuffer (Gl_array_buffer, VBO); Glbufferdata (Gl_array_buffer,9*sizeof(float), points, Gl_static_draw); Gluint Vao=0; Glgenvertexarrays (1, &Vao);    Glbindvertexarray (VAO); Glenablevertexattribarray (0);    Glbindbuffer (Gl_array_buffer, VBO); Glvertexattribpointer (0,3, Gl_float, Gl_false,0, NULL); Const Char* Vertex_shader ="#version 400\n"        "In vec3 VP;"        "void Main () {"        "gl_position = VEC4 (VP, 1.0);"        "}"; Const Char* Fragment_shader ="#version 400\n"        "Out vec4 frag_colour;"        "void Main () {"        "Frag_colour = VEC4 (0.5, 0.0, 0.5, 1.0);"        "}"; Gluint vs=Glcreateshader (Gl_vertex_shader); Glshadersource (VS,1, &Vertex_shader, NULL);    Glcompileshader (VS); Gluint FS=Glcreateshader (Gl_fragment_shader); Glshadersource (FS,1, &Fragment_shader, NULL);    Glcompileshader (FS); Gluint Shader_programme=Glcreateprogram ();    Glattachshader (Shader_programme, FS);    Glattachshader (Shader_programme, VS);    Gllinkprogram (Shader_programme); //Loop until the user closes the window     while(!glfwwindowshouldclose (window)) {        //wipe the drawing surface clearGlclear (Gl_color_buffer_bit |gl_depth_buffer_bit);        Gluseprogram (Shader_programme);        Glbindvertexarray (VAO); //Draw points 0-3 from the currently bound VAO with current in-use shaderGldrawarrays (Gl_triangles,0,3); //Update other events like input handlingglfwpollevents (); //put the stuff we ' ve been drawing onto the displayglfwswapbuffers (window); }    //Close GL Context and any other GLFW resourcesglfwterminate (); return 0;}

Click "Local Windows Debugger" to see the following effects:

Another example

This is an example of using synthetic gerstner waves to draw the surface of the water, according to the "simple rendering of water surface –gerstner wave" modified. Full code: HTTP://PAN.BAIDU.COM/S/1GDZOE4B, required configuration file: Http://pan.baidu.com/s/1pJ81kyZ. Project Escrow Address: Https://github.com/johnhany/OpenGLProjects/tree/master/GerstnerWave.

The effect is as follows:

Original link: environment configuration for OpenGL 4 under windows7+vs2012

Environment configuration for OpenGL 4 under windows7+vs2012

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.