I've a problem with opengl shader compiling. The problem is that when I run the program, I obtain this error:
Vertex info
0(1) : error c0000: syntax error, unexpected '' at token ''
the same message is for the fragment object. At the end I obtain a 'program not validated' error. here's my initialization shader code:
struct ShadeState { int gl_program_id = 0; // OpenGL program handle int gl_vertex_shader_id = 0; // OpenGL vertex shader handle int gl_fragment_shader_id = 0; // OpenGL fragment shader handle }; // initialize the shaders void init_shaders(ShadeState* state) { // load shader code from files auto vertex_shader_code = load_text_file("shade_vertex.glsl"); auto fragment_shader_code = load_text_file("shade_fragment.glsl"); auto vertex_shader_codes = (char *)vertex_shader_code.c_str(); auto fragment_shader_codes = (char *)fragment_shader_code.c_str(); //devono essere costanti altrimenti glShaderSource non li accetta //auto vertex_codes = (const GLchar*)vertex_shader_codes; //auto fragment_codes = (const GLchar*)fragment_shader_codes; //GLint const vert_size = vertex_shader_code.size(); //GLint const frag_size = fragment_shader_code.size(); // create shaders state->gl_vertex_shader_id = glCreateShader(GL_VERTEX_SHADER); //come da documentazione state->gl_fragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER); //come da documentazione // load shaders code onto the GPU //glShaderCode non esiste! glShaderSource(state->gl_vertex_shader_id, 1, (const GLchar**)&vertex_shader_codes, NULL); glShaderSource(state->gl_fragment_shader_id, 1, (const GLchar**)&fragment_shader_codes, NULL); // compile shaders glCompileShader(state->gl_vertex_shader_id); glCompileShader(state->gl_fragment_shader_id); // check if shaders are valid //funzione presente in glcommon.h error_if_glerror(); error_if_shader_not_valid(state->gl_vertex_shader_id); error_if_shader_not_valid(state->gl_fragment_shader_id); // create program state->gl_program_id = glCreateProgram(); // attach shaders glAttachShader(state->gl_program_id, state->gl_vertex_shader_id); glAttachShader(state->gl_program_id, state->gl_fragment_shader_id); // bind vertex attributes locations //faccio il bind delle variabili in input del vertex shader glBindAttribLocation(state->gl_program_id, 0, "vertex_pos"); // primo attributo in shade_vertex glBindAttribLocation(state->gl_program_id, 1, "vertex_norm"); //secondo attributo in shade_vertex // link program glLinkProgram(state->gl_program_id); // check if program is valid //funzione presente in glcommon.h error_if_glerror(); error_if_program_not_valid(state->gl_program_id); } How ca I resolve?
EDIT
shade_vertex.glsl
#version 120 attribute vec3 vertex_pos; // vertex position (in mesh coordinate frame) attribute vec3 vertex_norm; // vertex normal (in mesh coordinate frame) uniform mat4 mesh_frame; // mesh frame (as a matrix) uniform mat4 camera_frame_inverse; // inverse of the camera frame (as a matrix) uniform mat4 camera_projection; // camera projection varying vec3 pos; // [to fragment shader] vertex position (in world coordinate) varying vec3 norm; // [to fragment shader] vertex normal (in world coordinate) // main function void main() { // compute pos and normal in world space and set up variables for fragment shader (use mesh_frame) // project vertex position to gl_Position using mesh_frame, camera_frame_inverse and camera_projection } shade_fragment.glsl
#version 120 varying vec3 pos; // [from vertex shader] position in world space varying vec3 norm; // [from vertex shader] normal in world space (need normalization) uniform vec3 camera_pos; // camera position (center of the camera frame) uniform vec3 ambient; // scene ambient uniform int lights_num; // number of lights uniform vec3 light_pos[16]; // light positions uniform vec3 light_intensity[16]; // light intensities uniform vec3 material_kd; // material kd uniform vec3 material_ks; // material ks uniform float material_n; // material n // main void main() { // re-normalize normals // use faceforward to ensure the normals points toward us // accumulate ambient vec3 c = vec3(0,0,0) // foreach light // compute point light color at pos // compute light direction at pos // compute view direction using camera_pos and pos // compute h // accumulate blinn-phong model // output final color by setting gl_FragColor gl_FragColor = vec4(c,1); }
shade_vertex.glslandshade_fragment.glslload_text_file()implemented?