GLSL编译器错误错误C0000:语法错误,意外标识符,在标记<var>处期望"::"

Mat*_*gan 1 c++ opengl sdl glsl fedora-21

我的系统配置如下:SDL2,Fedora 21,Nvidia GTX驱动程序.

[mhoggan@localhost build]$ glxinfo | grep version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL core profile version string: 4.4.0 NVIDIA 346.47
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL version string: 4.5.0 NVIDIA 346.47
OpenGL shading language version string: 4.50 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.1 NVIDIA 346.47
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
    GL_EXT_shader_implicit_conversions, GL_EXT_shader_integer_mix, 
[mhoggan@localhost build]$ uname -a
Linux localhost.san.rr.com 3.19.3-200.fc21.x86_64 #1 SMP Thu Mar 26 21:39:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

创建着色器后,glCreateShader传入以下源:glCompileShader我得到了顶点和片段着色器的相同错误:

Going to compile vertex source:
attribute vec3 position;attribute vec4 color;varying frag_color;void main() {  gl_Position = vec4(position, 1.0);  frag_color = color;} 

Going to compile fragment source:
varying vec4 frag_color;void main() {  gl_FragColor = frag_color;}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

顶点着色器编译:0(1):错误C0000:语法错误,意外标识符,在标记"frag_color"处期待"::"

Frament shader编译:0(1):错误C0000:语法错误,意外标识符,在标记"frag_color"处期待"::"

导致此错误的代码在两个类之间是相同的,但产生以下输出的调用序列是:

// Note that after each opengl call I call glError thorugh the macro
// GL_CALL. I have verified there are no errors from glError.
_fragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER); GL_CALL 
if(_fragment_shader_id == 0) {           
  compiler_errors = "ERROR: Error to get fragment shader id.";
  return compiler_errors;                
}

const GLchar *source = _fragment_shader_code.data();
printf("Going to compile fragment source: %s\n", source);
GLint source_cnt = 0;                    
glShaderSource(_fragment_shader_id, 1, &source, source_cnt);
GL_CALL                                  
glCompileShader(_fragment_shader_id); GL_CALL
Run Code Online (Sandbox Code Playgroud)

要查看它是否是版本问题,我尝试使用SDL2的API将上下文创建更改为各种版本.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);

//Create window                          
gWindow = SDL_CreateWindow("Project", SDL_WINDOWPOS_UNDEFINED,
  SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
  SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
if(gWindow == NULL) {                    
  printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
  assert(false);                         
} else {                                 
  gContext = SDL_GL_CreateContext(gWindow);     
  if(gContext == NULL) {                 
    printf("OpenGL 2.1 context could not be created! SDL Error: %s\n",
      SDL_GetError());                   
    assert(false);
Run Code Online (Sandbox Code Playgroud)

jPr*_*015 5

您尚未在"顶点"着色器中为"改变frag_color"指定类型.我假设你的意思是"改变vec4 frag_color".