示例#1
0
static void on_font_load_clicked(int id, void* user) {

  KankerApp* app = static_cast<KankerApp*>(user);
  if (NULL == app) {
    RX_ERROR("error: cannot cast to KankerApp* in on_file_selected().");
    return;
  }

  std::vector<std::string> files;
  if (0 != app->getFontFiles(files)) {
    RX_ERROR("error: cannot load font, file not found.");
    return;
  }

  if (app->selected_font_dx >= files.size()) {
    RX_ERROR("error: selected font dx is too big: %d, files.size() = %lu.", app->selected_font_dx, files.size());
    return;
  }

  std::string filepath = rx_to_data_path("fonts/" +files[app->selected_font_dx]);
  if (!rx_file_exists(filepath)) {
    RX_ERROR("error: cannot load file; file seems to be removed?");
    return;
  }
  
  if (0 != app->kanker_font.load(filepath)) {
    RX_ERROR("error: font failed to load: %s\n", filepath.c_str());
    return;
  }

  app->font_filename = files[app->selected_font_dx];

  app->switchState(KSTATE_CHAR_OVERVIEW);
}
示例#2
0
GLuint Water::createTexture(std::string filename) {
 
  int w, h, n;
  unsigned char* pix;
 
  if(!rx_load_png(rx_to_data_path(filename), &pix, w, h, n)) {
    printf("Error: cannot find: %s\n", filename.c_str());
    return 0;
  }
 
  GLuint tex;
  GLenum format = GL_RGB;
 
  if(n == 4) {
    format = GL_RGBA;
  }
 
  glGenTextures(1, &tex);
  glBindTexture(GL_TEXTURE_2D, tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, format, GL_UNSIGNED_BYTE, pix);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
  delete[] pix;
  pix = NULL;
  return tex;
}
bool HTTPFile::setFile(std::string fname, bool datapath) {
  filepath = fname;
  filename = fname;
  if(datapath) {
    filepath = rx_to_data_path(fname);
  }
  return exists();
}
int main() {

  // get necessary config
  // -----------------------------------------------
  Jansson j;
  if(!j.load("youtube.cfg", true)) {
    RX_ERROR("Make sure that you created the youtube.cfg; we're using that config to authorize ourself");
    return EXIT_FAILURE;
  }
  
  std::string client_id;
  std::string client_secret;
  std::string auth_code;

  j.getString("/client_id", client_id);
  j.getString("/client_secret", client_secret);
  j.getString("/auth_code", auth_code);

  if(!client_id.size() || !client_secret.size() || !auth_code.size()) {
    RX_ERROR("One of the configuration options is empty! Did you set the auth code? See html/index.html and readme.");
    return EXIT_FAILURE;
  }

  // test an upload with some garbage json 
  // -----------------------------------------------
  YouTube yt;
  if(!yt.setup(client_id, client_secret)) {
    RX_ERROR("Cannot setup the youtube API handler");
    return EXIT_FAILURE;
  }

  if(!yt.hasAccessToken()) {
    RX_VERBOSE("Fetching access token");
    if(!yt.exchangeAuthCode(auth_code)) {
      RX_ERROR("Cannot update the access token");
      return EXIT_FAILURE;
    }
  }

  YouTubeVideo video;
  video.title = "some title";
  video.filename = rx_to_data_path("test.mov");
  video.datapath = false;
  video.video_resource_json = "_invalid_json_"; 
  video.bytes_total = rx_get_file_size(video.filename);

  YouTubeUploadStart uploader;
  if(uploader.start(video, yt.getAccessToken())) {
    RX_ERROR("TEST FAILED, uploader should return false on error");
  }
  else {
    RX_ERROR("TEST SUCCEEDED!");
  }

  return EXIT_SUCCESS;
}
示例#5
0
static void on_abb_load_settings_clicked(int id, void* user) {

  KankerApp* app = static_cast<KankerApp*>(user);
  if (NULL == app) {
    RX_ERROR("Failed to cast to KankerApp");
    return;
  }

  if (0 != app->kanker_abb.loadSettings(rx_to_data_path("abb_settings.xml"))) {
    RX_ERROR("Failed to load the settings.");
  }
}
// create the request string
bool HTTPRequest::toString(std::string& result) {

  // create the content string
  std::string http_body;
  if(!createBody(http_body)) {
    RX_ERROR("Cannot create request body");
    return false;
  }

  // create the headers.
  addDefaultHTTPHeaders();
  addHeader(HTTPHeader("Content-Length", http_body.size()));

  // construct the request
  result = getHTTPString() +"\r\n";

  result += headers.join();
  result += "\r\n";

#if 1
  printf("%s", result.c_str());
  for(size_t i = 0; i < http_body.size(); ++i) {
    if(i > 40) {
      break;
    }
    printf("%c", http_body[i]);
  }
  printf("\n");
  for(size_t i = 0; i < http_body.size(); ++i) {
    if(i > 40) {
      break;
    }
    printf("%02X ", (unsigned char)http_body[i]);
  }
  printf("\n");
#endif

  result += http_body;

#if 0 
  std::ofstream ofs(rx_to_data_path("out.raw").c_str(), std::ios::binary | std::ios::out);
  if(!ofs.is_open()) {
    RX_ERROR("Cannot open output file");
  }
  else {
    ofs.write(result.c_str(), result.size());
    ofs.close();
  }
#endif

  return true;
}
示例#7
0
bool JPG::load(std::string filename, bool datapath) {
  if(datapath) {
    filename = rx_to_data_path(filename);
  }

  struct jpeg_error_mgr jerr;
  struct jpeg_decompress_struct cinfo;
  FILE* fp;
  JSAMPARRAY buffer;
  
  if( (fp = fopen(filename.c_str(), "rb")) == NULL ) {
    RX_ERROR(ERR_JPG_FILE_NOT_OPENED, filename.c_str());
    return false;
  }

  cinfo.err = jpeg_std_error(&jerr);

  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, fp);
  jpeg_read_header(&cinfo, TRUE);
  jpeg_start_decompress(&cinfo);

  stride = cinfo.output_width * cinfo.output_components;
  num_channels = cinfo.output_components;
  width = cinfo.output_width;
  height = cinfo.output_height;
  bit_depth = 8;
  num_bytes = width * height * num_channels;

  pixels = new unsigned char[num_bytes];
  if(!pixels) {
    RX_ERROR(ERR_JPG_CANNOT_ALLOC);
    jpeg_finish_decompress(&cinfo);
    jpeg_destroy_decompress(&cinfo);
    fclose(fp);
    return false;
  }

  size_t dest_row = 0;
  buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1);
  while(cinfo.output_scanline < cinfo.output_height) {
    jpeg_read_scanlines(&cinfo, buffer, 1);
    memcpy(pixels + (dest_row * stride), buffer[0], stride);
    dest_row++;
  }

  jpeg_finish_decompress(&cinfo);
  jpeg_destroy_decompress(&cinfo);
  fclose(fp);
  
  return true;
}
示例#8
0
/* Returns 0 when we found some font files, otherwise < 0. */
int KankerApp::getFontFiles(std::vector<std::string>& files) {

  std::vector<std::string> full_paths;
  full_paths = rx_get_files(rx_to_data_path("fonts"), "xml");
  if (0 == full_paths.size()) {
    return -1;
  }

  for (size_t i = 0; i < full_paths.size(); ++i) {
    files.push_back(rx_strip_dir(full_paths[i]));
  }

  return 0;
}
示例#9
0
static void on_font_save_clicked(int id, void* user) {

  KankerApp* app = static_cast<KankerApp*>(user);
  if (NULL == app) {
    RX_ERROR("error: cannot cast to KankerApp* in on_save_clicked().");
    return;
  }

  if (0 == app->font_filename.size()) {
    RX_ERROR("No filename entered. Cannot save.");
    return;
  }

  RX_VERBOSE("Saving file: %s, origin_x: %f", app->font_filename.c_str(), app->kanker_font.origin_x);
  
  app->kanker_font.save(rx_to_data_path("fonts/" +app->font_filename));
}
示例#10
0
bool Mist::setup() {
  vert = rx_create_shader(GL_VERTEX_SHADER, MIST_VS);
  frag = rx_create_shader(GL_FRAGMENT_SHADER, MIST_FS);
  prog = rx_create_program(vert, frag);
  glBindAttribLocation(prog, 0, "a_pos");
  glBindAttribLocation(prog, 1, "a_tex");
  glLinkProgram(prog);
  rx_print_shader_link_info(prog);

  glUseProgram(prog);
  glUniform1i(glGetUniformLocation(prog, "u_tex"), 0);
  u_time = glGetUniformLocation(prog, "u_time");
  u_perc = glGetUniformLocation(prog, "u_perc");

  assert(u_time >= 0);
  assert(u_perc >= 0);

  glGenVertexArrays(1, &vao);
  glBindVertexArray(vao);
  glEnableVertexAttribArray(0);
  glEnableVertexAttribArray(1);

  glGenBuffers(1, &vbo);
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT3), (GLvoid*)0);
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT3), (GLvoid*)12);

  createRing(effects.win_w * 0.5, effects.win_h * 0.5, 20.0f, 450.0);

  MistShape shape;
  shape.reset();
  shape.offset = offsets.back();
  shape.count = counts.back();
  shape.x = 1024 * 0.5;
  shape.y = 768 * 0.5;
  shapes.push_back(shape);

  mist_tex = rx_create_texture(rx_to_data_path("images/mist.png")); // , GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
  if(!mist_tex) {
    printf("Error: cannot create the mist texture.\n");
    return false;
  }
  printf("mist.mist_tex: %d\n", mist_tex);
  return true;
}
示例#11
0
文件: MP3Writer.cpp 项目: roxlu/roxlu
MP3FileWriter::MP3FileWriter(std::string filename, bool datapath) 
  :cb_open(NULL)
  ,cb_data(NULL)
  ,cb_close(NULL)
{
  if(datapath) {
    filename = rx_to_data_path(filename);
  }

  ofs.open(filename.c_str(), std::ios::binary);

  if(!ofs.is_open()) {
    RX_ERROR(MP3_WRERR_FILE_OPEN, filename.c_str());
  }
  else {
    cb_open = mp3_writer_default_open;
    cb_close = mp3_writer_default_close;
    cb_data = mp3_writer_default_data;
  }
}
int main() {

  glfwSetErrorCallback(error_callback);
 
  if(!glfwInit()) {
    printf("Error: cannot setup glfw.\n");
    exit(EXIT_FAILURE);
  }
 
  glfwWindowHint(GLFW_SAMPLES, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  
  GLFWwindow* win = NULL;
  int w = 1280;
  int h = 720;
 
  win = glfwCreateWindow(w, h, "~`` Image Loader - Copy Images Into data/test/ ``~", NULL, NULL);
  if(!win) {
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
 
  glfwSetFramebufferSizeCallback(win, resize_callback);
  glfwSetKeyCallback(win, key_callback);
  glfwSetCharCallback(win, char_callback);
  glfwSetCursorPosCallback(win, cursor_callback);
  glfwSetMouseButtonCallback(win, button_callback);
  glfwMakeContextCurrent(win);
  glfwSwapInterval(1);

  if (!gladLoadGL()) {
    printf("Cannot load GL.\n");
    exit(1);
  }

  // ----------------------------------------------------------------
  // THIS IS WHERE YOU START CALLING OPENGL FUNCTIONS, NOT EARLIER!!
  // ----------------------------------------------------------------
  rx_log_init();

  mos::ImageLoader loader;
  if (0 != loader.init()) {
    exit(EXIT_FAILURE);
  }
  loader.on_loaded = on_loaded;

  mos::DirWatcher watcher;
  if (0 != watcher.init(rx_to_data_path("test"), on_dir_change, &loader)) {
    exit(EXIT_FAILURE);
  }

  Painter painter;

  while(!glfwWindowShouldClose(win)) {
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    watcher.update();

    GLenum fmt = GL_NONE;
    if (must_recreate || must_update) {
      if (1 == tex_channels) {
        fmt = GL_RED;
      }
      else if (2 == tex_channels) {
        fmt = GL_RG;
      }
      else if (3 == tex_channels) {
        fmt = GL_RGB;
      }
      else if (4 == tex_channels) {
        fmt = GL_RGBA;
      }
      else {
        RX_ERROR("Unsupported number of channels: %d", tex_channels);
      }
    }

    if (must_recreate) {
      RX_VERBOSE("Create texture, width: %d, height: %d, channels: %d", tex_width, tex_height, tex_channels);
      if (0 != tex_id) {
        glDeleteTextures(1, &tex_id);
      }

      if (GL_NONE != fmt) {
        glGenTextures(1, &tex_id);
        glBindTexture(GL_TEXTURE_2D, tex_id);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, fmt, GL_UNSIGNED_BYTE, pixels);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      }
      must_recreate = false;
      must_update = false;
    }

    if (must_update && GL_NONE != fmt) {
      RX_VERBOSE("Updating pixels");
      glBindTexture(GL_TEXTURE_2D, tex_id);
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, tex_width, tex_height, 0, fmt, GL_UNSIGNED_BYTE, pixels);
      must_update = false;
    }

    if (0 != tex_id) {
      int x = MAX(0, (w/2) - (tex_width/2));
      int y = 0;

      painter.clear();
      painter.texture(tex_id, x, y, tex_width, tex_height);
      painter.draw();
    }

    glfwSwapBuffers(win);
    glfwPollEvents();
  }
 
  loader.shutdown();

  glfwTerminate();
 
  return EXIT_SUCCESS;
}
示例#13
0
bool JPG::save(std::string filename, bool datapath) {

  if(!width || !height) {
    RX_ERROR("Invalid width or height: %d x %d", width, height);
    return false;
  }
  
  if(!stride) {
    RX_ERROR("Invalid stride: %d", stride);
    return false;
  }
  
  if(!pixels) {
    RX_ERROR("No pixels set to save");
    return false;
  }

  if(!bit_depth) {
    RX_ERROR("Invalid bit_depth: %d", bit_depth);
    return false;
  }

  if(datapath) {
    filename = rx_to_data_path(filename);
  }

  FILE* fp = fopen(filename.c_str(), "wb");
  if(!fp) {
    RX_ERROR("Cannot open the file: `%s`", filename.c_str());
    fp = NULL;
    return false;
  }

  struct jpeg_compress_struct cinfo;
  struct jpeg_error_mgr jerr;
  JSAMPROW row_pointer[1];

  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_compress(&cinfo);
  
  jpeg_stdio_dest(&cinfo, fp);

  // compression parameters
  cinfo.image_width = width;
  cinfo.image_height = height;
  cinfo.input_components = num_channels;
  cinfo.in_color_space = color_space;
  
  jpeg_set_defaults(&cinfo); // after setting the default we can set our custom settings
  
  // @todo > set compression level, dither, dct

  jpeg_set_quality(&cinfo, quality, TRUE /* limit to jpeg baseline values */);

  jpeg_start_compress(&cinfo, TRUE /* write complete data stream */); 

  while(cinfo.next_scanline < cinfo.image_height) {
    row_pointer[0] = &pixels[cinfo.next_scanline * stride];
    jpeg_write_scanlines(&cinfo, row_pointer, 1);
  }

  jpeg_finish_compress(&cinfo);

  fclose(fp);
  fp = NULL;

  jpeg_destroy_compress(&cinfo);
    
  return true;
}
示例#14
0
int KankerApp::init() {
  
  /* title font */
  std::string font = "appfont.otf";
  if (0 != title_font.open(rx_to_data_path(font), 60)) {
    RX_ERROR("error: cannot load the font.");
    exit(EXIT_FAILURE);
  }

  title_font.color(1.0f, 1.0f, 1.0f, 1.0f);
  title_font.alignCenter();

  /* info font */
  if (0 != info_font.open(rx_to_data_path(font), 16)) {
    RX_ERROR("error: cannot load the font.");
    exit(EXIT_FAILURE);
  }
  info_font.color(1.0f, 1.0f, 1.0f, 1.0f);

  /* verbose font */
  if (0 != verbose_font.open(rx_to_data_path(font), 16)) {
    RX_ERROR("error: cannot load the font.");
    exit(EXIT_FAILURE);
  }
  verbose_font.color(0.0f, 0.7f, 0.1f, 1.0f);

  switchState(KSTATE_HOME);

  /* create the GUI. */
  if (0 != createGui()) {
    RX_ERROR("error: failed to create the gui.");
    exit(EXIT_FAILURE);
  }

  /* init the drawer. */
  painter.init();
  if (0 != tiny_drawer.init(1024, 768, painter.width(), painter.height())) {
    RX_ERROR("error: failed to initialize the drawer.");
    return -1;
  }
  
  int pw = 1024;
  int ph = 768;
  if (0 != preview_drawer.init(pw, ph, painter.width(), painter.height())) {
    RX_ERROR("error: failed to initialize the preview drawer.");
    return -1;
  }

  /* TEST LOAD FONT */
  kanker_font.setOrigin(origin_x, origin_y);

  std::string test_font = rx_to_data_path("fonts/roxlu.xml");
  if (0 != kanker_font.load(test_font)) {
    RX_ERROR("Cannot load: %s", test_font.c_str());
  }

  /* Init the ABB interface. */
  //  kanker_abb.range_width = 500;
  //  kanker_abb.range_height = 500;

  /* Setup the controller that we use to test the ABB communication */
  KankerAbbControllerSettings cfg;
  cfg.font_file = rx_to_data_path("fonts/roxlu.xml");
  cfg.settings_file = rx_to_data_path("abb_settings.xml");
  if (0 != controller.init(cfg, this)) {
    RX_ERROR("Cannot initialize the controller.");
  }

  test_message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ac fermentum ";
  //test_message = "roger abb";
  //test_message = "ik sta op tegen kanker ik sta op tegen kanker.";
  //test_message = "He Martin, gefeliciteerd met je verjaardag!";
  //test_message = "Dearest Tina, we both have a lot of emotions for you";
  //test_message = "Keez Duyves";
  //test_message = "i love ";
  //test_message = "diederick";
  //test_message = "Martin gefeliciteerd!";
  //test_message = "ipsum";
  //test_message = "d d d a a";
  //test_message = "aaaaaa";
  //test_message = "bbbbbb";
  //test_message = "x";
  //test_message = "a";
  //test_message = "Lieve papa, we denken aan je.";
  //test_message = "Ik sta op tegen kanker voor mijn lieve schoonvader";
  test_message = "Mijn, mijn, Lieve papa, we denken aan je.";


  /* Force a load for the settings. */
  on_abb_load_settings_clicked(0, this);

  return 0;
}
示例#15
0
bool Water::setup(int w, int h) {
  assert(w && h);

  win_w = w;
  win_h = h;

  // create shader
  vert = rx_create_shader(GL_VERTEX_SHADER, WATER_VS);
  frag = rx_create_shader(GL_FRAGMENT_SHADER, WATER_FS);
  prog = rx_create_program(vert, frag);
  glBindAttribLocation(prog, 0, "a_tex");
  glLinkProgram(prog);
  rx_print_shader_link_info(prog);
  glUseProgram(prog);
  glUniform1i(glGetUniformLocation(prog, "u_tex_pos"),            0);  // VS
  glUniform1i(glGetUniformLocation(prog, "u_tex_norm"),           1);  // VS
  glUniform1i(glGetUniformLocation(prog, "u_tex_texcoord"),       2);  // VS
  //  glUniform1i(glGetUniformLocation(prog, "u_tex_tang"),       3);  // VS
  glUniform1i(glGetUniformLocation(prog, "u_tex_gradient"),       3);  // VS
  glUniform1i(glGetUniformLocation(prog, "u_noise_tex"),          4);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_norm_tex"),           5);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_flow_tex"),           6);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_diffuse_tex"),        7);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_foam_tex"),           8);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_color_tex"),          9);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_extra_flow_tex"),     10);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_foam_delta_tex"),     11);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_foam_colors"),        12);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_foam_ramp"),          13);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_vortex_tex"),         14);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_sand_tex"),           15);  // FS
  glUniform1i(glGetUniformLocation(prog, "u_depth_ramp_tex"),           16);  // FS

  //GLint texture_units = 0;
  //glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &texture_units);
  //printf("Max units: %d\n", texture_units);

  glUniformMatrix4fv(glGetUniformLocation(prog, "u_pm"), 1, GL_FALSE, height_field.pm.ptr());
  glUniformMatrix4fv(glGetUniformLocation(prog, "u_vm"), 1, GL_FALSE, height_field.vm.ptr());

  // load textures
  normals_tex = createTexture("images/water_normals.png");
  flow_tex = createTexture("images/water_flow.png");
  noise_tex = createTexture("images/water_noise.png");
  diffuse_tex = createTexture("images/water_diffuse.png");
  foam_tex = createTexture("images/water_foam.png");
  force_tex0 = createTexture("images/force.png");
  foam_colors_tex = createTexture("images/foam_densities.png");
  foam_ramp_tex = createTexture("images/foam_ramps.png");
  vortex_tex = createTexture("images/vortex.png");
  sand_tex = createTexture("images/sand.png");
  depth_ramp_tex = createTexture("images/depth_ramp.png");
  
  glBindTexture(GL_TEXTURE_2D, foam_colors_tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  glBindTexture(GL_TEXTURE_2D, foam_ramp_tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  glBindTexture(GL_TEXTURE_2D, depth_ramp_tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


  unsigned char* img_pix = NULL;
  int img_w, img_h,img_channels = 0;  

  // load diffuse color ramp
  if(!rx_load_png(rx_to_data_path("images/water_color.png"), &img_pix, img_w, img_h, img_channels)) {
    printf("Error: cannot load the water_color.png image.\n");
    return false;
  }

  glGenTextures(1, &color_tex);
  glBindTexture(GL_TEXTURE_1D, color_tex);
  glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, img_w, 0, GL_RGB, GL_UNSIGNED_BYTE, img_pix);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  delete[] img_pix;
  printf("water.color_tex: %d\n", color_tex);
  
  glBindTexture(GL_TEXTURE_2D, flow_tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


  // FBO we used for rendering extra diffuse colors to the water
  glGenFramebuffers(1, &fbo); 
  glBindFramebuffer(GL_FRAMEBUFFER, fbo);

  glGenTextures(1, &extra_flow_tex);
  glBindTexture(GL_TEXTURE_2D, extra_flow_tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, win_w, win_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, extra_flow_tex, 0);

  if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    printf("Cannot create the framebuffer for the water diffuse capture.\n");
    return false;
  }
  glBindFramebuffer(GL_FRAMEBUFFER, 0);

  return true;
}
// @todo - we need to construct the correct video resource json
bool YouTubeModel::addVideoToUploadQueue(YouTubeVideo video) {

  if(!video.filename.size()) {
    RX_ERROR("Cannot add a video which has no filename set");
    return false;
  }

  std::string filepath = video.filename;
  if(video.datapath) {
    filepath = rx_to_data_path(video.filename);
  }

  size_t fsize = rx_get_file_size(filepath);
  if(!fsize) {
    RX_ERROR("Filesize of %s returned %ld", filepath.c_str(), fsize);
    return false;
  }

#if USE_JSON_PACK
  // @todo - libjansson is used as DLL, and json_dumps
  // is supposed to free() the memory; this is icky and 
  // libjansson should free() any allocated mem as it's used
  // as a dll
  std::string video_json;
  char* video_resource = NULL;
  json_t* body = NULL;
  
  if(!video.video_resource_json.size()) {
    body = json_pack("{ s: {s:s}, s: { s:s, s:i, s:s, s:s } }",
                             "status", "privacyStatus", "private", 
                             "snippet", "tags", video.tags.c_str(), 
                             "categoryId", video.category,  
                             "description", video.description.c_str(), 
                             "title", video.title.c_str());
 
    video_resource = json_dumps(body, JSON_INDENT(0));
    json_decref(body);

    video_json.assign(video_resource, strlen(video_resource));

    if(!video_resource) {
      RX_ERROR("Cannot create JSON video resource string");
      return false;
    }
  }
  else {
    video_json = video.video_resource_json;
  }
#else
  std::string video_json;

  if(!video.video_resource_json.size()) {
    std::stringstream ss;

    ss << "{ \"status\": { \"privacyStatus\" : \"private\" }, "
       <<   "\"snippet\": {"
       <<       "\"title\":\"" << video.title << "\", "
       <<       "\"tags\":\"" << video.tags << "\", "
       <<       "\"categoryId\":" << video.category << ", "
       <<       "\"description\":\"" << video.description << "\""
       <<    "}"
       << "}";

    video_json = ss.str();
  }
  else {
    video_json = video.video_resource_json;
  }

#endif

  bool r = db.insert("videos")
    .use("filename", video.filename)
    .use("state", YT_VIDEO_STATE_NONE)
    .use("bytes_total", fsize)
    .use("video_resource_json", video_json)
    .use("datapath", (video.datapath) ? 1 : 0)
    .use("title", video.title)
    .use("description", video.description)
    .use("tags", video.tags)
    .use("privacy_status", video.privacy_status)
    .use("category", video.category)
    .execute();

#if USE_JSON_PACK
  if(video_resource) {
    free(video_resource);  
    video_resource = NULL;
  }
#endif

  if(r) {
    RX_VERBOSE("Added video to the queue: %s", video.filename.c_str());
  }
  else {
    RX_ERROR("Error while trying to add: %s to the video upload queue", video.filename.c_str());
  }

  return r;
}
示例#17
0
bool WaterBallDrawer::setup(int w, int h) {
  assert(w && h);
  win_w = w;
  win_h = h;
  pm.ortho(0, w, h, 0, 0.0f, 100.0f);

  // create basic shader 
  const char* atts[] = { "a_pos", "a_size" } ;
  const char* frags[] = { "out_normals", "out_alpha" };
  basic_prog.create(GL_VERTEX_SHADER, rx_to_data_path("shaders/waterdrop_basic.vert"));
  basic_prog.create(GL_FRAGMENT_SHADER, rx_to_data_path("shaders/waterdrop_basic.frag"));
  basic_prog.link(2, atts, 2, frags);
  glUseProgram(basic_prog.id);
  glUniformMatrix4fv(glGetUniformLocation(basic_prog.id, "u_pm"), 1, GL_FALSE, pm.ptr());
  glUniform1i(glGetUniformLocation(basic_prog.id, "u_normals_tex"), 0);
  glUniform1i(glGetUniformLocation(basic_prog.id, "u_alpha_tex"), 1);

  // create water render shader
  water_prog.create(GL_VERTEX_SHADER, rx_to_data_path("shaders/waterdrop_water.vert"));
  water_prog.create(GL_FRAGMENT_SHADER, rx_to_data_path("shaders/waterdrop_water.frag"));
  water_prog.link();
  glUseProgram(water_prog.id);
  glUniform1i(glGetUniformLocation(water_prog.id, "u_normals_tex"), 0);
  glUniform1i(glGetUniformLocation(water_prog.id, "u_alpha_tex"), 1);
  glUniform1i(glGetUniformLocation(water_prog.id, "u_background_tex"), 2);

  glGenVertexArrays(1, &water_vao);

  glGenVertexArrays(1, &basic_vao);
  glBindVertexArray(basic_vao);
  glGenBuffers(1, &basic_vbo);
  glBindBuffer(GL_ARRAY_BUFFER, basic_vbo);
  
  glEnableVertexAttribArray(0); // pos
  glEnableVertexAttribArray(1); // size
  glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(WaterDrop), (GLvoid*) 0);
  glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, sizeof(WaterDrop), (GLvoid*) 32);

  glVertexAttribDivisor(0, 1);
  glVertexAttribDivisor(1, 1);

  normals_tex = rx_create_texture(rx_to_data_path("images/waterdrop_normals.png"));
  alpha_tex = rx_create_texture(rx_to_data_path("images/waterdrop_alpha.png"));
  background_tex = rx_create_texture(rx_to_data_path("images/waterdrop_background.png"));
  glBindTexture(GL_TEXTURE_2D, background_tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  // fbo
  glGenFramebuffers(1, &fbo);
  glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  
  glGenTextures(1, &scene_normals_tex);
  glBindTexture(GL_TEXTURE_2D, scene_normals_tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, win_w, win_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, scene_normals_tex, 0);

  glGenTextures(1, &scene_alpha_tex);
  glBindTexture(GL_TEXTURE_2D, scene_alpha_tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, win_w, win_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, scene_alpha_tex, 0);

  if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    printf("Framebuffer not complete.\n");
    return false;
  }

  glBindFramebuffer(GL_FRAMEBUFFER, 0);

  return true;
}