I'm trying to compile simple shader on my linux machine with Radeon HD 5470 video card and fglrx AMD driver.
My vertex shader code
#version 330 core layout(location = 0) in vec3 vertexPosition_modelspace; void main() { gl_Position.xyz = vertexPosition_modelspace; gl_Position.w = 1.0; } Read code from file
void Shader::load_from_file(const std::string& file) { std::ifstream is(file, std::ios_base::in); if (is.is_open()) { std::string line{""}; while(std::getline(is, line)) { // program_code_ is a std::string member program_code_ += "\n" + line; } is.close(); } else { throw Exception("Could not open shader source code file"); } } Try to compile
void Shader::build_shader() { const GLchar* tmp = program_code_.c_str(); const GLint tmplen = program_code_.length(); std::cout << "Shader code: " << tmp << std::endl; glShaderSource(shader_handler_, 1, &tmp, &tmplen); CHECK_ERR(); glCompileShader(shader_handler_); CHECK_ERR(); //... } And have error from glGetShaderInfoLog
Exception caught: 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 But before I calling glShaderSource, I print to stdout value of tmp pointer and it seems to valid shader code:
Shader code: #version 330 core layout(location = 0) in vec3 vertexPosition_modelspace; void main() { gl_Position.xyz = vertexPosition_modelspace; gl_Position.w = 1.0; } My code doesn't read garbage from memory, but I can't understand what's wrong.
Also
% glxinfo | grep vertex_program % GL_ARB_vertex_program
line + "\n"instead of"\n" + line. (It probably won't fix the error though.)load_from_fileis called multiple times, or some other reason why the member might contain data before the call?program_code_defined?