OpenGL Programming Guide (Red Book eighth edition) sample code configuration issues Summary

Source: Internet
Author: User

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

Code download Environment configuration issues glut and Glew1 Basic header file and library file configuration 2 The following is the body content constantly added in the first Renderer Triangles3 Chapter three 03CH03_DRAWCOMMANDS4

This article is the author himself in the configuration of the problem and solve the original data and their own experience combined with the code to download

can search for environment configuration issues on CSDN (glut and Glew) 1

You can refer to my other post, the process of compiling and configuring Freeglut and Glew source code using CMake and Visual Studio, but may not be a required step. Basic header file and library file configuration 2

If you find large tracts of red lines, you need to add include and Lib:

Click on the Item Right button property, tap VC + + Directory

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

Library Directory – Edit, add the Lib folder in the Red Book source directory


The main errors are: unresolved external symbols _sscanf, ___iob_func, and so on. This problem is very good to solve, mainly VS2015 relative to the previous version of the changes, the specific can be self-Baidu. The workaround is as follows: 1. Right-click Project –> Properties –> linker –> Input –> Additional dependencies: Legacy_stdio_definitions.lib 2. Add the following code to the source file

#if _msc_ver>=1900
#include "stdio.h"
_acrtimp_alt file* __cdecl __acrt_iob_func (unsigned);
#ifdef __cplusplus
extern "C"
#endif
file* __cdecl __iob_func (unsigned i) {
    return __acrt_iob_func (i) ;
}
#endif/* _msc_ver>=1900 */

The compilation passed, but Vaos an access violation occurred:

The reason is that glewinit () does not complete all initialization, so in the front row of Glewinit () add:

Glewexperimental = Gl_true;

See the Code section.

Glewexperimental is quite a general switch, and if it is set to gl_true it will allow Glew to support all the extensions, and Glewinit () will be able to do all the initialization successfully.

The following is the body content, constantly added:





First Render program Triangles3

First, create a new Win32 Console application

The complete code after the modification is as follows:

//triangles.cpp///////////////////////

#include "stdafx.h" #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) {Glgenvertexarr
    Ays (Numvaos, Vaos);
    Glbindvertexarray (Vaos[triangles]); Glfloat Vertices[numvertices][2] = {{ -0.90, -0.90},//Triangle 1 {0.85,-0.90}, {-0.90, 0.8
    5}, {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) {Glclea
    R (Gl_color_buffer_bit);
    Glbindvertexarray (Vaos[triangles]);
    Gldrawarrays (gl_triangles, 0, numvertices);
Glflush (); 
    }//---------------------------------------------------------------------////main//int main (int argc, char** argv) {
    Glutinit (&AMP;ARGC, argv);
    Glutinitdisplaymode (Glut_rgba);
    Glutinitwindowsize (512, 512);
    Glutinitcontextversion (4, 3);
    Glutinitcontextprofile (Glut_core_profile); GlutcreatewindoW (Argv[0]);
    Glewexperimental = Gl_true;
        if (Glewinit ()) {Cerr << "Unable to initialize Glew ... exiting" << Endl;
    Exit (Exit_failure);
    } init ();
    Glutdisplayfunc (display);
Glutmainloop ();
 }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

Second, frequently asked questions

(1) about the "stdafx.h" error

Code header Add or remove #include "stdafx.h"

(2) Compile the discovery does not pass, the report cannot parse the external command error

This could be because LoadShaders.cpp can't be found.
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

(3)
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-property – linker – Enter to add it in the Ignore specific default library

(4)
The compilation passed, but Vaos an access violation occurred:

The reason is that glewinit () does not complete all initialization, so in the front row of Glewinit () add:

Glewexperimental = Gl_true;

See the Code section.

Glewexperimental is quite a general switch, and if it is set to gl_true it will allow Glew to support all the extensions, and Glewinit () will be able to do all the initialization successfully.

(5)
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

Layout (location = 0) in Vec4 vposition;  
void  
Main ()  
{  
    gl_position = vposition;  
}  
1 2 3 4 5 6 1 2 3 4 5 6

Triangles.frag

Out VEC4 Fcolor;  
void  
Main ()  
{  
    Fcolor = vec4 (0.0, 0.0, 1.0, 1.0);  
}  
1 2 3 4

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.