Beispiel #1
0
static void material_generate_programs(material* m) {
  
  for(int i = 0; i < m->num_entries; i++) {
  
    material_entry* me = m->entries[i];
    me->program = shader_program_new();
    
    bool attached = false;
    for(int j = 0; j < me->num_items; j++) {
      
      if (me->types[j] == mat_item_shader) {
        asset_hndl ah = me->items[j].as_asset;
        
        shader_program_attach_shader(me->program, asset_hndl_ptr(&ah));
        attached = true;
      }
      
    }
    
    if (attached) { shader_program_link(me->program); }
    
  }
  
  SDL_GL_CheckError();
    
}
Beispiel #2
0
int init_shader(void)
{
	// открываем файл шейдера из буфера
	if(!shader_program_file_create_from_buffer(&pfile, main_shader_source))
		return 0;
	
	// получаем шейдерную программу
	shader_program_file_get_program(&pfile, &program);
	
	// линкуем её
	if(!shader_program_link(&program))
		return 0;
	
	shader_program_bind(&program);
	
	// получаем юниформы
	uniform_modelmat = shader_program_get_uniform_loc(&program, "model");
	uniform_viewmat = shader_program_get_uniform_loc(&program, "view");
	uniform_projectionmat = shader_program_get_uniform_loc(&program, "projection");
	uniform_model_inv = shader_program_get_uniform_loc(&program, "model_inv");
	uniform_light_pos = shader_program_get_uniform_loc(&program, "light_position");
	uniform_viewer_pos = shader_program_get_uniform_loc(&program, "viewer_position");
	uniform_volume_texture = shader_program_get_uniform_loc(&program, "volume_texture");
	uniform_volume_step = shader_program_get_uniform_loc(&program, "volume_step");

	uniform_material_front_color = shader_program_get_uniform_loc(&program, "material_front_color");
	uniform_material_back_color = shader_program_get_uniform_loc(&program, "material_back_color");
	uniform_light_color = shader_program_get_uniform_loc(&program, "light_color");
	uniform_light_spec_color = shader_program_get_uniform_loc(&program, "light_spec_color");
	uniform_material_shininess = shader_program_get_uniform_loc(&program, "material_shininess");
	uniform_coef_ambient = shader_program_get_uniform_loc(&program, "coef_ambient");
	uniform_coef_diffuse = shader_program_get_uniform_loc(&program, "coef_diffuse");
	uniform_coef_specular = shader_program_get_uniform_loc(&program, "coef_specular");
	uniform_coef_gamma = shader_program_get_uniform_loc(&program, "coef_gamma");
	
	shader_program_unbind(&program);
	
	return 1;
}
Beispiel #3
0
shader_program* prog_load_file(char* filename) {

  shader_program* sp = shader_program_new();
  
  SDL_RWops* file = SDL_RWFromFile(filename, "r");
  
  if(file == NULL) {
    error("Could not load file %s", filename);
  }
  
  char line[1024];
  while(SDL_RWreadline(file, line, 1024)) {
    
    char type[256];
    char path[1024];
    if (sscanf(line, "%256s : %1024s", type, path) == 2) {
      if(!asset_loaded(path)) {
        load_file(path);
      }
      shader* s = asset_get(path);
      shader_program_attach_shader(sp, s);
    }
  
  }
  
  SDL_RWclose(file);
  
  shader_program_link(sp);
  shader_program_print_log(sp);
  
  int error = 0;
  glGetProgramiv(*sp, GL_LINK_STATUS, &error);
  if (error == GL_FALSE) {
    error("Linking Error on Shader Program %s.", filename);
  }
  
  return sp;
  
}