GLSL weird '<' syntax error in vertex shader

Started by
14 comments, last by SetsudanHana 10 years ago

Ok, so i'm starting my adventure with openGL 4 and shaders. And i occured weird syntax error while compiling vertext shader.

Even when i take simple vertex shader:


#version 400
in vec3 vector_position;
void main()
{
    gl_Position = vec4(vector_position, 1.0);
}

i do get this error:

Vertex shader failed to compile with the following errors: ERROR: 0:1: error(#132) Syntax error: '<' parse error ERROR: error(#273) 1 compilation errors. No code generated

What is weird about this, my fragment shader is compiling without errors:


#version 400
out vec4 color;
void main()
{
    color = vec4(1.0, 0.0, 0.0, 1.0);
}

and gives this message:

compiler_log: Fragment shader was successfully compiled to run on hardware.

I tried testing those shaders by putting them as const char* in code, and they work fine.

To make it easier here are some additional informations:

  • using SDL 2.0
  • initializing OpenGL by SDL2.0
  • using GLEW to load extensions
  • reading text files by this function:


std::ifstream file(path);

if(!file.good())
{
    OutputDebugStringA("File not found");
    return nullptr;
}

std::stringstream stream ;
stream << file.rdbuf();

file.close();

return stream.str();

Thank you for fast answer.

Advertisement

Are you creating the program ( glCreateProgram() ) before trying to compile it?

Also, make sure that there's a null terminator at the end of your file.

i'm getting those errors while compiling shaders, this is code from my ShaderLoadingClass:


        ResourceManager manager;
	std::string container = "Just simple container";
	container = manager.loadTextFile(file + ".vs");
	const char* vertex_shader = container.c_str();
	container = manager.loadTextFile(file + ".fs");
	const char* fragment_shader = container.c_str(); 

	unsigned int vs = glCreateShader (GL_VERTEX_SHADER);
	glShaderSource (vs, 1, &vertex_shader, NULL);
	glCompileShader (vs);
	unsigned int fs = glCreateShader (GL_FRAGMENT_SHADER);
	glShaderSource (fs, 1, &fragment_shader, NULL);
	glCompileShader (fs);

	checkErrors(vs);
	checkErrors(fs);

	unsigned int shader_programme = glCreateProgram ();
	glAttachShader (shader_programme, fs);
	glAttachShader (shader_programme, vs);
	glLinkProgram (shader_programme);

	return new ShaderClass(shader_programme);

Does your file have a null terminator?

length() function is giving me valid value so i do think, they do have null terminator

length() should return strlen(vertex_shader) + 1. You likely have to enter a null terminator yourself; the C++ compiler will insert one for you in a string literal, but reading from a file will not have a terminal unless it exists in the file. The shader compiler needs a null terminator, or else it will read out of bounds, looking for the end.

Is your project set to use unicode?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

@mhagain

yes it is set up to unicode

@Ectara

i added '\0' by myself, and now it throws this one:

compiler_log:

Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: '1.0' parse error
ERROR: error(#273) 1 compilation errors. No code generated
EDIT:
i changed every 1.0 to 1.0f in my shaders, and i'm back to my previous error

http://stackoverflow.com/questions/23011482/glsl-weird-syntax-error-in-vertex-shader

Is that you?

Anyway, have you tried passing the length explicitly, rather than relying on the null terminator? Also, try printing the string on stdout just to make sure that it is correctly read.

Yeah, it is faster to ask on few sites.

Yes, i found this suggestion on stackoverflow, but it changed nothing

This topic is closed to new replies.

Advertisement