示例#1
0
文件: texture.cpp 项目: mpk/ppgso
Texture::Texture(const std::string &raw, unsigned int width, unsigned int height) : width(width), height(height) {
  framebuffer.reserve(width * height * sizeof(Pixel));

  // Open file stream
  std::ifstream image_stream(raw, std::ios::binary);

  if (!image_stream.is_open())
    std::cerr << "Could not open texture " << raw << std::endl;

  // Load the
  image_stream.read((char *)framebuffer.data(), framebuffer.capacity()*sizeof(Pixel));
  image_stream.close();
  initGL();
  Update();
}
ReadResult readImageStream(const std::string &filename, const osgDB::ReaderWriter::Options *options) const
{
    OSG_INFO << "ReaderWriterDirectShow::readImage " << filename << std::endl;
    const std::string path = osgDB::containsServerAddress(filename) ?
                             filename :
                             osgDB::findDataFile(filename, options);

    osg::ref_ptr<DirectShowImageStream> image_stream(new DirectShowImageStream);

    if (path.empty())     // try with capture
    {
        std::map<std::string, std::string> map;
        if (options)
        {
            map["captureWantedWidth"]           = options->getPluginStringData("captureWantedWidth");
            map["captureWantedHeight"]          = options->getPluginStringData("captureWantedHeight");
            map["captureWantedFps"]             = options->getPluginStringData("captureWantedFps");
            map["captureVideoDevice"]           = options->getPluginStringData("captureVideoDevice");
            map["captureSoundDevice"]           = options->getPluginStringData("captureSoundDevice");
            map["captureSoundDeviceNbChannels"] = options->getPluginStringData("captureSoundDeviceNbChannels");
        }

        if (filename != "capture")
        {
            if (!options || (options && options->getPluginStringData("captureVideoDevice").empty()))
                map["captureVideoDevice"] = filename;
        }

        image_stream->setOptions(map);

        if (!image_stream->openCaptureDevices())
            return ReadResult::FILE_NOT_HANDLED;

        return image_stream.release();
    }

    if (!image_stream->openFile(filename))
        return ReadResult::FILE_NOT_HANDLED;

    return image_stream.release();
}
示例#3
0
// Load a new image from a raw RGB file directly into OpenGL memory
GLuint LoadImage(const std::string &image_file, unsigned int width, unsigned int height) {
  // Create new texture object
  GLuint texture_id;
  glGenTextures(1, &texture_id);
  glBindTexture(GL_TEXTURE_2D, texture_id);

  // Set mipmaps
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

  // Read raw data
  std::ifstream image_stream(image_file, std::ios::binary);

  // Setup buffer for pixels (r,g,b bytes), since we will not manipulate the image just keep it as char
  std::vector<char> buffer(width*height*3);
  image_stream.read(buffer.data(), buffer.size());
  image_stream.close();

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer.data());

  return texture_id;
}