Since OpenGL shader aspect, C ++ does not look the wrong way corresponding to briefly summarize in this correction method, method, we hope to help newcomers:
- 1. The detector can successfully compiled shader, i.e. can not pass on the syntax.
Be used here to glGetShaderiv () function, used as follows, can be used to detect a compiled state.
int success1 = 0;
glGetShaderiv(vertexShader,GL_COMPILE_STATUS,&success1);
if(!success1)
{
cout << "failed to compile VertexShader" << endl;
}
But sometimes knowing that a shader compiler did not pass, but just do not know where to go wrong, this can be used when glGetShaderInfoLog:
int success1 = 0;
glGetShaderiv(vertexShader,GL_COMPILE_STATUS,&success1);
if(!success1)
{
cout << "failed to compile VertexShader" << endl;
char log[512];
glGetShaderInfoLog(vertexShader,512,NULL,log);
cout << log << endl;
}
For example, such fragmentShader write:
#version 330 core
out vec4 ourColor;
void main()
{
ourColor=vec4(0.2f,0.5f,0.6f,1.0f);s
}
Will this error:
here 0: 5, 5 is the number of rows, so it is easy to find the error location.
-
2. Another mistake is two shaders are compiled successfully, but in the end there is no color, or linkProgram fail, what it needs to pay attention to it?
(1) Check the engaging portion between the shader, the variable name is passed between the note must be exactly the same shaders.
(2) the color does not appear much, fragment shader is a problem, can check the fragment shader.
Finally, you can still use glGetProgramiv and glGetProgramInfoLog to find the error. -
3 There's a mistake to rely on their own to find
such an error: Fragment shader Function already has a body : main ERROR:
check your glGetShaderSource did wrong,
or stupid mistake like me committed:
the original program wrote a 10-line, but the drop-down scroll was found in 98 rows inexplicably has a main function
delete it on the line. -
There are 3 cases to rely on fate, for example, I have only once appeared in the window, see the graphs drawn, and finally found his glSwapBuffer and glDarwArrays function to write backwards, remember
the Loop inside, glSwapBuffer certain functions to call back the draw call! !
PS
If Vs studio use, you can install the following text tool, to achieve the following color effect, help yourself Code:
Specific methods are as follows:
1. Click Tools ----> expand and update
2. Select Network -----> Enter GLSL, download and install the search, after the restart visual studio on the line.