OpenGL Little Red Book 8th first example Triangles__opengl

Source: Internet
Author: User

Early in the year with QT involved in OpenGL, only according to QT-self-sufficient library use, according to the example of Qt did not appear what problems, but recently contacted computer graphics, try to compile Little Red Book 8th ("OpenGL Programming Guide" (the original book 8th edition) Chinese version) The first example, found that the compilation is not past Start thinking that the compilation environment is not configured, but later found not include and LIB issues, there are many other issues, so do a little record here.

Start from the beginning: I. Compiling the environment configuration.

To Little Red Book's official online download 8th profile (oglpg-8th-edition), if you want to download the latest features or to the Little Red Book website download.

Because to use the original code on the book to Little Red Book official website download Example-master, there is a src folder has some source code, and then use vs new Empty project.

can also go to the Internet to find source code: http://blog.csdn.net/candycat1992/article/details/39676669


Find examples-master/src inside the triangles.cpp, open the discovery contains the

#include "vgl.h"
#include "LoadShaders.h"

and shaderinfo shaders[] =
{
{gl_vertex_shader, "Media/shaders/triangles/triangles.vert"},
{gl_fragment_shader, "Media/shaders/triangles/triangles.frag"},
{Gl_none, NULL}
};

Because there is also a LoadShaders.cpp need to find vgl.h, Loadshaders.h/.cpp, Triangles.vert, Triangles.frag these five files, search in the folder.

Finally, put these files into the same directory.

As shown in figure


Then add the 5 (2 header files, 3 source files) to the project.

Note that the source file "Gl/glew.h" cannot be loaded in vgl.h because we have not set up an additional include file. Then add include and Lib.

Select the triangles solution >> right key >> Properties >>C/C++>> General, modify the additional include directory as shown in the figure:


Select Triangles solution >> right key >> Properties >> linker >> General, modify the additional include directory.



Then compile and run the project and find that there are errors in generating the solution, but the hint that the error is caused by the default library "LIBCMTD.lib" and other library conflicts, so we have to ignore this library.


Select Triangles solution >> right key >> Properties >> linker >> Input, ignore specific default library, fill in LIBCMT; LIBCMTD, so you can ignore this library in debug or release compilation mode.


The compiler then succeeds, but starts executing (but not debugging) and the program crashes.

The breakpoint is then found to be crashing when it encounters the glgenvertexarrays call, and the solution is given online: The following settings were not set before the call to Glewinit:
Glewexperimental = Gl_true. (Reference address)

That's how it works.

It was later found that the color set was blue but the display was white.


And the Debug box prompts "Incorrect GLSL vesion:430" to indicate that there is a problem with the version number, but Little Red Book 8th does provide the latest features of OpenGL4.3, so the library is definitely supported, so that only possible my hardware is not supported.

Later on the internet to look at the footprints of many pioneers, found that Little Red Book 8th initial introduction of OpenGL is indeed slightly simpler, so that we have overlooked some problems. the relationship between OpenGL and the Windows operating system


OpenGL is an application programming interface (API) and a software library that can access the characteristics of a graphics hardware device. As a matter of fact, OpenGL is actually closer to the graphics card and the OpenGL library is available for graphics cards that support OpenGL.
Because OpenGL is related to the video card (hardware) and therefore to the operating system, Windows is self OpenGL, so Windows contains the standard library for OpenGL, which is not available on the OpenGL website.
When we have the compiler installed (for example, VS2012), the compiler copies the associated header file and class library of OpenGL into the relevant folder of the compiler.
For example, the header file is placed in C:\Program files (x86) \ Windows KITS\8.0\INCLUDE\UM\GL
Library files are placed in C:\Program files (x86) \ Windows Kits\8.0\lib (here may be different win locations and VS versions Inconsistent, author here is win7+vs2012)

What if the version of OpenGL in Windows is too low.
Don't worry about it, it's enough with Windows with OpenGL. The OpenGL version is actually limited to the OpenGL version supported by the graphics card rather than the version of your OpenGL library.


How do you view the OpenGL version supported by your hardware? This openglextension viewer can help you.


Here my notebook's OpenGL4.0 can only support to the

So I changed the version of the. Vert and. Frag to a statement glutinitcontextversion (4,3) in 4.0,triangles.cpp, and the version of OPENGGL was 4.3, also modified for 4.0.

After recompiling, the final display of the ideal blue result.


Thanks to the forerunner's footsteps here.


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.