Sign in to follow this  
SetsudanHana

OpenGL GLSL weird '<' syntax error in vertex shader

Recommended Posts

SetsudanHana    119

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
Ectara    3097

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
SetsudanHana    119

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
Ectara    3097

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
SetsudanHana    119

@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
Ectara    3097

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

Share this post


Link to post
Share on other sites
SetsudanHana    119

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

Share this post


Link to post
Share on other sites
Ectara    3097

 

@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.

Share this post


Link to post
Share on other sites
Ectara    3097

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now