[英]GLSL Compiler Error error C0000: syntax error, unexpected identifier, expecting “::” at token <var>
My system configuration is as follows: SDL2, Fedora 21, Nvidia GTX Drivers. 我的系统配置如下: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
After the shader is created with glCreateShader
and the following sources are passed into glCompileShader
I am getting the same error for both vertex and fragment shaders: 使用
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;}
Where the error I am getting is: 我得到的错误是:
Vertex shader compilation: 0(1) : error C0000: syntax error, unexpected identifier, expecting "::" at token "frag_color"
顶点着色器编译:0(1):错误C0000:语法错误,意外的标识符,在标记“ frag_color”处期望“ ::”
Frament shader compilation: 0(1) : error C0000: syntax error, unexpected identifier, expecting "::" at token "frag_color"
Frament着色器编译:0(1):错误C0000:语法错误,意外的标识符,在标记“ frag_color”处期望“ ::”
The code that leads up to this error is identical between the two classes, but the sequence of calls that produce the output below are: 导致此错误的代码在两个类之间是相同的,但是产生以下输出的调用顺序是:
// 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
To see if it might be a version issue I have tried to change the context creation to various versions, using SDL2's API. 为了查看是否可能是版本问题,我尝试使用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);
You haven't specified a type for "varying frag_color" in the Vertex shader. 您尚未在“顶点”着色器中为“ variable frag_color”指定类型。 I assume you meant "varying vec4 frag_color".
我假设您的意思是“变化vec4 frag_color”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.