Example #1
0
  void setup_graphics(Device *device, int w, int h) {
    device->render_state().SetWinSize(w, h);
    depth_fbo.Init(w, h);

    LOGI("Version : %s", RendererEnv::Version().c_str());
    LOGI("Vendor : %s", RendererEnv::Vender().c_str());
    LOGI("Renderer : %s", RendererEnv::Renderer().c_str());
    LOGI("Extensions List");
    auto ext_list = RendererEnv::ExtensionList();
    auto ext_it = ext_list.begin();
    auto ext_endit = ext_list.end();
    for( ; ext_it != ext_endit ; ++ext_it) {
      LOGI("%s", ext_it->c_str());
    }

    {
      //create shader
      string simple_vs_path = Filesystem::GetAppPath("shader/simple.vs");
      string simple_fs_path = Filesystem::GetAppPath("shader/simple.fs");
      simple_shader.LoadFromFile(simple_vs_path, simple_fs_path);

      string color_vs_path = Filesystem::GetAppPath("shader/const_color.vs");
      string color_fs_path = Filesystem::GetAppPath("shader/const_color.fs");
      color_shader.LoadFromFile(color_vs_path, color_fs_path);
    }
    {
      //post effect
      string vs_path = Filesystem::GetAppPath("posteffect/shared.vs");
      string to_grayscale_fs_path = Filesystem::GetAppPath("posteffect/to_grayscale.fs");
      string null_fs_path = Filesystem::GetAppPath("posteffect/null.fs");
      grayscale_post_effect.InitFromFile(vs_path, to_grayscale_fs_path);
      null_post_effect.InitFromFile(vs_path, null_fs_path);
    }
    //lodepng
    const char *texture_table[][2] = {
      { "sora", "texture/sora.png" },
      { "sora2", "texture/sora2.png" }, 
    };

    int tex_count = sizeof(texture_table) / sizeof(texture_table[0]);
    for(int i = 0 ; i < tex_count ; i++) {
      std::string tex_path = sora::Filesystem::GetAppPath(texture_table[i][1]);
      sora::MemoryFile tex_file(tex_path);
      tex_file.Open();
      Texture tex(texture_table[i][0]);
      tex.Init();

      Image img;
      img.LoadPNG(tex_file.start, tex_file.end - tex_file.start);
      tex.LoadTexture(img);
      device->tex_mgr()->Add(tex);
    }
  }