Jump to content

  • Log In with Google      Sign In   
  • Create Account

GLSL weird '<' syntax error in vertex shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 SetsudanHana   Members   -  Reputation: 119

Like
1Likes
Like

Posted 11 April 2014 - 07:05 AM

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.



Sponsor:

#2 Ectara   Crossbones+   -  Reputation: 3058

Like
0Likes
Like

Posted 11 April 2014 - 07:20 AM

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, 11 April 2014 - 07:24 AM.


#3 SetsudanHana   Members   -  Reputation: 119

Like
0Likes
Like

Posted 11 April 2014 - 07:32 AM

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


#4 Ectara   Crossbones+   -  Reputation: 3058

Like
0Likes
Like

Posted 11 April 2014 - 07:40 AM

Does your file have a null terminator?



#5 SetsudanHana   Members   -  Reputation: 119

Like
0Likes
Like

Posted 11 April 2014 - 07:44 AM

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



#6 Ectara   Crossbones+   -  Reputation: 3058

Like
1Likes
Like

Posted 11 April 2014 - 07:53 AM

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.



#7 mhagain   Crossbones+   -  Reputation: 8277

Like
0Likes
Like

Posted 11 April 2014 - 07:58 AM

Is your project set to use unicode?


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#8 SetsudanHana   Members   -  Reputation: 119

Like
0Likes
Like

Posted 11 April 2014 - 08:05 AM

@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, 11 April 2014 - 08:48 AM.


#9 Ectara   Crossbones+   -  Reputation: 3058

Like
0Likes
Like

Posted 11 April 2014 - 09:03 AM

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.



#10 SetsudanHana   Members   -  Reputation: 119

Like
0Likes
Like

Posted 11 April 2014 - 09:17 AM

Yeah, it is faster to ask on few sites.

 

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



#11 Ectara   Crossbones+   -  Reputation: 3058

Like
0Likes
Like

Posted 11 April 2014 - 09:23 AM

Can you show your entire manager.loadTextFile() function? It may be in entirety up above, but it is best to show the whole thing, function header and all, so we can be confident that there are no lines that we aren't seeing.

 

Also, what does 

std::cout << vertex_shader;

output?


Edited by Ectara, 11 April 2014 - 09:24 AM.


#12 mhagain   Crossbones+   -  Reputation: 8277

Like
0Likes
Like

Posted 11 April 2014 - 09:31 AM

@mhagain

 

yes it is set up to unicode

 

Try switching to multibyte and see if the problem reproduces.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#13 SetsudanHana   Members   -  Reputation: 119

Like
0Likes
Like

Posted 11 April 2014 - 09:32 AM

loadTextFile function:

std::string ResourceManager::loadTextFile(const std::string& path)
{
	std::ifstream file(path);

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

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

	file.close();

	return stream.str();
}

i cant use cout, becuase i dont have console, but OutputDebugStringA on each of them gives this:

 

 

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

 

last line dont have '\n', thats why they looked merged

 

EDIT:

 

changing to multibyte, didnt do anything


Edited by SetsudanHana, 11 April 2014 - 09:35 AM.


#14 Ectara   Crossbones+   -  Reputation: 3058

Like
0Likes
Like

Posted 11 April 2014 - 09:38 AM

 

@mhagain

 

yes it is set up to unicode

 

Try switching to multibyte and see if the problem reproduces.

 

 

I looked again, and using OutputDebugStringA() with UTF-16 flags defined for Windows seems dubious, but I'll leave that be since that's a different topic.

 

Also, check the info for #5: http://en.cppreference.com/w/cpp/string/basic_string/basic_string
Return nullptr as a string is undefined behavior, since passing an invalid pointer to basic_string's constructor is undefined behavior.

 

I'll try to think of other troubleshooting steps in the meantime.



#15 Ectara   Crossbones+   -  Reputation: 3058

Like
3Likes
Like

Posted 11 April 2014 - 09:42 AM

OH!

    container = manager.loadTextFile(file + ".vs");
    const char* vertex_shader = container.c_str();
    container = manager.loadTextFile(file + ".fs");
    const char* fragment_shader = container.c_str();

You're returning a pointer to a string's contents, then overwriting its contents! Try putting them in separate strings, or interleave loading and compiling them.



#16 SetsudanHana   Members   -  Reputation: 119

Like
1Likes
Like

Posted 11 April 2014 - 09:52 AM

it works, i knew that it is something so simple... I'm just dumb






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS