This article is reproduced the original address http://blog.csdn.net/qq821869798/article/details/45247241
I was just beginning to learn OpenGL, bought an OpenGL Red Book eighth edition,
The first example studies a period of time finally can run, do not know if there is no child heel I encountered the same problem.
Let's talk about how I configured it:
First go to http://www.opengl-redbook.com/download Red Book source code, unzip to get this
Then open vs2013 to create a new empty Win32 console project,
Then click on the Item Right button property, tap VC + + Directory
Include directory--edit, add include folder in red Book source directory
Library Directory--edit, add Lib folder in Red Book source directory
Add and source files in the project, paste Red Book code for the first example
///////////////////////////////////////////////////////////////////////////Triangles.cpp/////////////////////////////////////////////////////////////////////////#include <iostream>using namespacestd; #include"vgl.h"#include"LoadShaders.h"enumvao_ids {triangles, numvaos};enumbuffer_ids {ArrayBuffer, numbuffers};enumattrib_ids {vposition =0 }; Gluint Vaos[numvaos]; Gluint Buffers[numbuffers];ConstGluint numvertices =6;//---------------------------------------------------------------------////Init//voidInitvoid) {glgenvertexarrays (Numvaos, Vaos); Glbindvertexarray (Vaos[triangles]); Glfloat vertices[numvertices][2] = { { -0.90, -0.90},//Triangle 1{0.85, -0.90 }, { -0.90,0.85 }, { 0.90, -0.85},//Triangle 2{0.90,0.90 }, { -0.85,0.90 } }; Glgenbuffers (numbuffers, buffers); Glbindbuffer (Gl_array_buffer, Buffers[arraybuffer]); Glbufferdata (Gl_array_buffer,sizeof(vertices), vertices, gl_static_draw); Shaderinfo shaders[]={{Gl_vertex_shader,"Triangles.vert"}, {gl_fragment_shader,"Triangles.frag"}, {Gl_none, NULL}}; Gluint Program=loadshaders (shaders); Gluseprogram (program); Glvertexattribpointer (Vposition,2, Gl_float, Gl_false,0, Buffer_offset (0)); Glenablevertexattribarray (vposition);}//---------------------------------------------------------------------////Display//voidDisplayvoid) {glclear (gl_color_buffer_bit); Glbindvertexarray (Vaos[triangles]); Gldrawarrays (Gl_triangles,0, numvertices); Glflush ();}//---------------------------------------------------------------------////Main//intMainintargcChar**argv) {Glutinit (&argc, argv); Glutinitdisplaymode (Glut_rgba); Glutinitwindowsize ( +, +); Glutinitcontextversion (4,3); Glutinitcontextprofile (Glut_core_profile); Glutcreatewindow (argv[0]); if(Glewinit ()) {Cerr<<"Unable to initialize Glew ... exiting"<<Endl; Exit (Exit_failure); } init (); Glutdisplayfunc (display); Glutmainloop ();}
Compile the discovery does not pass, will report unable to parse the external command error,
This is because I can't find LoadShaders.cpp.
In the Red Book source code directory, there is a Lib folder, there are LoadShaders.cpp
Right-click on the project's source file to add the existing item and add it in
Now compile again, find or error, said there is a libcmtd.lib library and other libraries have conflicts, we can go to ignore it
Click the project right--Properties--linker--Enter to add it in ignoring a specific default library
Now in the compilation once the discovery can be passed out
But it's a white triangle, not blue, you need to create two new text in the project catalog
Renamed to Triangles.vert and Triangles.frag
The code is as follows:
Triangles.vert
4300 in vec4 vposition; void Main () { = vposition;}
Triangles.frag
430 Core out VEC4 Fcolor; void Main () { = vec4 (0.00.01.01.0);}
And then compile and run, and a blue triangle appears.
"Reprint" about configuring the OpenGL Red Book Eighth edition environment in vs2013