Advertisement Jump to content
Sign in to follow this  
SetsudanHana

OpenGL GLSL weird '<' syntax error in vertex shader

This topic is 1748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Edited by Ectara

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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
Edited by SetsudanHana

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!