Example #1
0
/* =============================================================================
 =============================================================================== */
int C3DSceneMgr::createTexture(string strFileName, int &width, int &height, int iTxMode)
{
	if (strFileName == "") //  Return from the function if no file name was passed in
		return -1;
	if (!fileexists(strFileName))
		return -1;

	//  Load the image and store the data
	int textureID = -1;
	if (getExt(strFileName) == ".dds")
	{
		DDS_IMAGE_DATA	*pDDSImageData = NULL;
		if ((pDDSImageData = loadDDSTextureFile(strFileName)) != NULL)
		{
			textureID = createTextureDDS(pDDSImageData);
			height = pDDSImageData->sizeY;
			width = pDDSImageData->sizeX;
		}
		else	//  case where worldwind wraps jpegs in dds files
		{
			Fl_RGB_Image *img = new Fl_JPEG_Image(strFileName.c_str());
			if (img->d() == 0)
				return -1;
			width = img->w();
			height = img->h();
			const unsigned char *pData = (const unsigned char *) img->data()[0];
			textureID = createTexture(pData, width, height, GL_RGB, GL_RGB, iTxMode);
			delete img;
		}
	}
	else
	{
		Fl_Image * img = openTextureFile(strFileName);
		if (img == NULL)
			return -1;
		width = img->w();
		height = img->h();
		const unsigned char *pData = (const unsigned char *) img->data()[0];
		textureID = createTexture(pData, width, height, img->d() == 4 ? GL_RGBA : GL_RGB, GL_RGBA, iTxMode);
		delete img;
	}

	return textureID;
}
Example #2
0
GLuint gmshPopplerWrapper::getTextureForPage(double xres, double yres)
{
  int iPage = _currentPage;
  int numPages = getNumPages();
  if(iPage < 0) iPage = 0;
  if(iPage > numPages - 1) iPage = numPages - 1;
  std::map<int, GLuint>::iterator it = _pages2textures.find(iPage);
  if(it != _pages2textures.end()) return it->second;
  if(!_currentDoc) return 0;

  poppler::page *page = _currentDoc->create_page(iPage);
  poppler::page_renderer pr;
  pr.set_render_hint(poppler::page_renderer::text_antialiasing, true);
  pr.set_render_hint(poppler::page_renderer::antialiasing, true);
  poppler::image im = pr.render_page(page, xres, yres, -1, -1, -1);
  im.save("hop.jpeg", "jpeg");
  Fl_RGB_Image *img = new Fl_JPEG_Image("hop.jpeg");
  //  Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(2048, 2048);
  glPixelStorei(GL_UNPACK_ROW_LENGTH, img->w());
  GLuint texture;
  glGenTextures(1, &texture);
  glBindTexture(GL_TEXTURE_2D, texture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w(), img->h(), 0,
               (img->d() == 4) ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE,
               img->array);
  glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

  _w = img->w();
  _h = img->h();

  delete img;
  //  delete img2;
  _pages2textures[iPage] = texture;
  return texture;
}