How to run the first chapter of the eighth edition of the OpenGL Programming Guide using VS2015 in Win7 (64-bit)
Preface: The first time I used vs2015 to realize the first program of the eighth edition of the OpenGL Programming Guide, I did spend a lot of time, according to the online tutorial, tried various methods, finally spent two morning plus an afternoon time,
The successful running of the program, spent so much time, really annoying, and now the steps to run the program to record, in order to review.
1. First step, download Oglpg-8th-edith.
If you go to the official website of the book to download, the download is the Nineth edition, and not the eighth version of the source code.
to other sites to download, download the package does not have the first chapter of the source code, you can paste on-line other people's codes, suggested under the eighth version of the source, download URL: Link: Http://pan.baidu.com/s/1kVpv1MR
File name: oglpg-8th-edition.7z
If the download link fails, go to another webpage to download it. This package contains the Freeglut and Glew libraries, so there is no need to download the Freeglut and Glew libraries.
2. Install vs2015, install it Yourself
3. Next New project
3.1. Open VS2015, click New Project, and create a new visual C++→win32 Console application project named: OpenGLRedBook03. Click OK
3.2. Click Resource Files
Right-click Resourse files, create a new C + + file,
Name triangles, then click Add
3.3 The main program code triangles added to the book, where the red line is not part of the book, you need to add in,
///////////////////////////////////////////////////////////////////////
//
Triangles.cpp
//
///////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace Std;
#include "vgl.h"
#include "LoadShaders.h"
Enum Vao_ids {triangles, numvaos};
Enum Buffer_ids {ArrayBuffer, numbuffers};
Enum Attrib_ids {vposition = 0};
Gluint Vaos[numvaos];
Gluint Buffers[numbuffers];
Const Gluint numvertices = 6;
//---------------------------------------------------------------------
//
Init
//
void init (void)
{
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
//
void display (void)
{
Glclear (Gl_color_buffer_bit);
Glbindvertexarray (Vaos[triangles]);
Gldrawarrays (gl_triangles, 0, numvertices);
Glflush ();
}
//---------------------------------------------------------------------
//
Main
//
int main (int argc, char** argv)
{
Glutinit (&ARGC, argv);
Glutinitdisplaymode (Glut_rgba);
Glutinitwindowsize (512, 512);
Glutinitcontextversion (4, 3);
Glutinitcontextprofile (Glut_core_profile);
Glutcreatewindow (Argv[0]);
Glewexperimental = gl_true;//not in source code
if (Glewinit ()) {
Cerr << "Unable to initialize Glew ... exiting" << Endl;
Exit (Exit_failure);
}
Init ();
Glutdisplayfunc (display);
Glutmainloop ();
}
After adding a lot of errors will be displayed, it doesn't matter, the next steps will be resolved
Add two additional files Triangles.frag and Triangles.vert in the Resourse file in the same way
///////////////////////////////////////////////////////////////////////
//
Triangles.frag
//
///////////////////////////////////////////////////////////////////////
#version 430 Core
Out VEC4 Fcolor;
void
Main ()
{
Fcolor = VEC4 (0.0, 0.0, 1.0, 1.0);
}
///////////////////////////////////////////////////////////////////////
//
Triangles.vert
//
///////////////////////////////////////////////////////////////////////
#version 430 Core
Layout (location = 0) in Vec4 vposition;
void
Main ()
{
Gl_position = vposition;
}
Use the same method to add LoadShaders.cpp to this directory in the package oglpg-8th-edition\lib you just downloaded
Four files were added under Resourse files so far
3.3 Click the header files file, add LoadShaders.h and vgl.h two headers under Oglpg-8th-edition\include
After the add is complete, such as
At this point, the file is added complete.
4. Click Vgl.h to see the code error
Here's how to solve the problem with the above code
4.1 Select Openglredbook03>> Right >> properties >>c/c++>>general>>additional Include directories, Modify the attached include directory,
Include directory is C:\Users\vr633-02\Desktop\oglpg-8th-edition\include
4.2 Similarly, add select Openglredbook03>> right >> properties >>linker>>general>>aditional Library Directories
4.3.openglredbook03>> Right-click >> properties >>linker>>input>>ignore specific Default Libraries> > Input
, fill in LIBCMT; LIBCMTD, this can be ignored in debug or rrelease compilation mode LIBCMTD.lib this library
5. Finally we run triangles.cpp this file, but there are still errors, what is the reason?
Because we use VS2015, this version of the pen VS2013 not the same, the specific reason is not Qin Chu, but there is a way to solve
We openglredbook03>> right-click >> properties >>general>>platform toolset>>visual Studio (v100)
6. Then run Triangles.cpp, as shown in
At this point, the program finishes running.
Concluding remarks: This step is to summarize the articles of each netizen, thank them for their selfless pay. The road long its repair far XI, I will go up and down and quest.
Reference website:
[1] Link: http://pan.baidu.com/s/1kVpv1MR.
[2] http://blog.csdn.net/outtt/article/details/50771057 (Red Book website OpenGL and Red Book eighth edition of the first program configuration).
How to run the first chapter of the eighth edition of the OpenGL Programming Guide using VS2015 in Win7 (64-bit)