Tag Archives: OpenGL programming guide

On the configuration of OpenGL Red Book eighth edition environment in vs2013

I just started learning OpenGL, bought a copy of OpenGL Red Book 8,
The first example has been studied for a while and is finally ready to run. I wonder if there are any children’s shoes that have the same problem as me.
Here’s how I configured it:
First go to http://www.opengl-redbook.com/ and download the source code of the Little Red Book. Unzip it to get this

Then open VS2013 and create an empty Win32 console project.
Then right-click on the project properties and click on the VC ++ directory

Include directory – Edit and add the include folder in the Red Book source directory

Library directory – Edit and add the lib folder
in the Red Book source directory

Add and source files to the project, and paste the code from the first example of the Little Red Book

///
//
// 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]);
	if (glewInit()) {
		cerr << "Unable to initialize GLEW ... exiting" << endl;
		exit(EXIT_FAILURE);
	}
	init();
	glutDisplayFunc(display);
	glutMainLoop();
}

compile once found not through, will quote cannot resolve external command error,

This is because loadShaders.cpp could not be found
In the Little Red Book source directory there is a lib folder with LoadShaders
Right-click on the project’s source file to add an existing item

The libcmtd.lib library is in conflict with other libraries, so we can ignore it
Right-click on the project — Properties — Linker — Enter and add it in Ignore the specific default library

Now in the compilation once found can pass out

But it’s a white triangle, not a blue triangle, and you need to create two new texts in the project directory
Renamed Triangles. Vert and Triangles. Frag

The code is as follows:

triangles.vert

#version 430 core
layout(location = 0) in vec4 vPosition;
void
main()
{
	gl_Position = vPosition;
}

triangles.frag

#version 430 core
out vec4 fColor;
void
main()
{
	fColor = vec4(0.0, 0.0, 1.0, 1.0);
}

>
>

OpenGL Programming Guide 8th Edition 9th Edition vs2015 vs2017 configuration method

“OpenGL Programming Guide” 8th Edition 9th Edition VS2015 VS2017 configuration method
“OpenGL programming guide” source download and source code in VS2015 VS2017 configuration method
directory
“OpenGL programming guide” version 8 version 9 environment configuration VS2015
1. Source download:
2. Cmake build configuration
3. VS2015 configuration
4. Run the example
5. Special Settings


1. Source download:
Version 9 can be downloaded from the official website: http://www.opengl-redbook.com/
Making the source address: https://github.com/openglredbook/examples

Note, direct source code downloaded from making, using CMake build VS2015 always appear a lot of mistakes, later on the issue of https://github.com/openglredbook/examples/issues/2, found that has successfully solved the great god, therefore, recommended directly download the source code of the lot:
https://github.com/elmindreda/examples

For the convenience of everyone to use, here I have configured the VS2015 to provide everyone to download, save you to build:
https://download.csdn.net/download/guyuealian/10878513 (direct download decompression, opened by VS2015/VS2017 my_build/vermilion9 SLNS, detected and then you can happy to run the example la la la la la)


2. Cmake build configuration
Install Cmake in Windows and set the following Settings:

If you click “Configure” :, the compiler will be selected, and you can select Visual Studio 14 2015 for VS2015


“Configuring Done” indicates that the configuration is OK. Forget the warnings that appear in red
Click “Generate” : “Generate done” will be displayed.
Finally, “Open Project” will be opened by default with VS2015


3. VS2015 configuration
Mouse select “ALL_BUILD” → Recompile
Select “Install” → Recompile with the mouse


4. Run the example
If you want to test running an example from a book, just select the example, like “01-triangles,” set it to “Set as Start Project,” and you’ll be ready to go

A triangular window will appear after successful operation:


5. Special Settings
Some examples, such as “12-imageprocessing,” will show a black window with nothing at all. This is because some of the shaders are not set to the correct file paths. Many of the resource files in the book are in: examples, bin, media.
A simple way to do this is to set up the working directory so that the relevant resource files can be found at runtime:

The working directory is: $(projectDir).. \bin