ForwardPositonalLightShader::ForwardPositonalLightShader():Shader(){ //load shader file, complile and link the shader. add_vertex_shader("res/shader/vs_forward_positional_light.glsl"); add_fragment_shader("res/shader/fs_forward_positional_light.glsl"); link_shaders(); //initialize the uniform init_uniform("transformation_mat"); init_uniform("camera_mat"); init_uniform("projection_mat"); init_uniform("normal_mat"); init_uniform("positional_light.light.amb_color"); init_uniform("positional_light.light.diff_color"); init_uniform("positional_light.light.spec_color"); init_uniform("positional_light.atten.constant"); init_uniform("positional_light.atten.linear"); init_uniform("positional_light.atten.exponent"); init_uniform("positional_light.pos"); init_uniform("positional_light.range"); init_uniform("camera_pos"); init_uniform("texture_sampler"); init_uniform("material.amb_refl"); init_uniform("material.diff_refl"); init_uniform("material.spec_refl"); init_uniform("material.emit_col"); init_uniform("material.shininess"); }
/*----------------------------------------------------------------------------*/ void init_shaders(char **shader, int count) { init_shader_vars(); printf("init_shaders has been passed %d shaders in its input param\n", count); if(count ==1) { vert_shader = loadVertShader(shader[0]); checkCompile(vert_shader); } if(count ==2) { assert(shader[1] != NULL); printf("loading second shader"); vert_shader = loadVertShader(shader[0]); checkCompile(vert_shader); frag_shader = loadFragShader(shader[1]); checkCompile(frag_shader); } link_shaders(); check_shader_linkage(); glUseProgram(program); }
ForwardDirectionalShader::ForwardDirectionalShader():Shader(){ //load shader file, complile and link the shader. add_vertex_shader("res/shader/vs_forward_directional_light.glsl"); add_fragment_shader("res/shader/fs_forward_directional_light.glsl"); link_shaders(); //initialize the uniform init_uniform("transformation_mat"); init_uniform("camera_mat"); init_uniform("projection_mat"); init_uniform("normal_mat"); init_uniform("directional_light.light.amb_color"); init_uniform("directional_light.light.diff_color"); init_uniform("directional_light.light.spec_color"); init_uniform("directional_light.direction"); // RimLight init_uniform("directional_light.rim_light.enable"); init_uniform("directional_light.rim_light.color"); init_uniform("directional_light.rim_light.power"); init_uniform("camera_pos"); init_uniform("texture_sampler"); init_uniform("material.amb_refl"); init_uniform("material.diff_refl"); init_uniform("material.spec_refl"); init_uniform("material.emit_col"); init_uniform("material.shininess"); }
GLuint load_shader_program(char *filenameVertex, char *filenameFragment) { GLuint program = 0; char *buffer1; char *buffer2; const GLchar *pSource = 0; long length = 0; GLuint vertShader = 0; GLuint fragShader = 0; FILE* file; if (filenameVertex != NULL) { file = fopen(filenameVertex, "r"); if(!file) { fprintf(stderr, "failed to open vert shader file %s\n", filenameVertex); exit(1); } fseek (file , 0 , SEEK_END); length = ftell (file); rewind (file); buffer1= (char*) malloc(sizeof(char)*length); fread(buffer1,1,length,file); fclose (file); pSource = (const GLchar *)(buffer1); vertShader = complile_shaders(GL_VERTEX_SHADER, pSource, length); } if (filenameFragment != NULL) { file = fopen(filenameFragment, "r"); if(!file) { fprintf(stderr, "failed to open frag shader file %s\n", filenameFragment); exit(1); } fseek (file , 0 , SEEK_END); length = ftell(file); rewind(file); buffer2= (char*) malloc(sizeof(char)*length); fread(buffer2,1,length,file); fclose (file); pSource = (const GLchar *)(buffer2); fragShader = complile_shaders(GL_FRAGMENT_SHADER, pSource, length); } program = link_shaders(vertShader, fragShader); return program; }
void Shader::create(const std::string& name, Owner location){ init(); load_shaders(name,location); compile_shaders(); link_shaders(); get_attributes(); get_uniforms(); }
void init_shaders() { program = glCreateProgram(); create_shaders(); glAttachShader(program, vert); glAttachShader(program, frag); link_shaders(); }
void piglit_init(int argc, char **argv) { unsigned i; /* Parse first param. */ if (argc < 3) print_usage_and_exit(argv[0]); for (i = 0; i < ARRAY_SIZE(tests); i++) { if (strcmp(argv[1], tests[i].name) == 0) { test = &tests[i]; break; } } if (test == NULL) print_usage_and_exit(argv[0]); /* Parse options. */ for (i = 3; i < argc; i++) { if (strcmp(argv[i], "interface") == 0) use_interface_blocks = true; else print_usage_and_exit(argv[0]); } /* Parse second param and setup test */ if (strcmp(argv[2], "error") == 0) { report_result(test_errors()); } else if (strcmp(argv[2], "get") == 0) { link_shaders(true); report_result(test_gets()); } else if (strcmp(argv[2], "run") == 0) { link_shaders(true); /* Testing will occur in piglit_display */ } else if (strcmp(argv[2], "run-no-fs") == 0) { link_shaders(false); report_result(test_xfb(true)); } else { print_usage_and_exit(argv[0]); } }
ForwardAmbientShader::ForwardAmbientShader():Shader(){ //load shader file, complile and link the shader. add_vertex_shader("res/shader/vs_forward_global_ambient.glsl"); add_fragment_shader("res/shader/fs_forward_global_ambient.glsl"); link_shaders(); //initialize the uniform init_uniform("transformation_mat"); init_uniform("camera_mat"); init_uniform("projection_mat"); init_uniform("texture_sampler"); init_uniform("ambient"); }