当前位置: 首页>>代码示例>>C++>>正文


C++ Image::Clear方法代码示例

本文整理汇总了C++中Image::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::Clear方法的具体用法?C++ Image::Clear怎么用?C++ Image::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::Clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateFor

Texture* SolidColorTextureCache::CreateFor(const Color &color, Texture *existing)
{
	LOG_INFO(LOGCAT_ASSETS, "SolidColorTextureCache: creating texture for color 0x%8x.\n", color.ToInt());

	Image *img = new Image();
	bool imageCreateSuccess = img->Create(8, 8, IMAGE_FORMAT_RGBA);
	ASSERT(imageCreateSuccess == true);

	Texture *texture;
	if (existing != NULL)
	{
		texture = existing;
		texture->Release();
	}
	else
		texture = new Texture();

	img->Clear(color);	
	bool success = texture->Create(m_graphicsDevice, img);
	SAFE_DELETE(img);

	if (!success)
	{
		// if we allocated the texture ourselves, we should free it
		if (existing != NULL)
		{
			SAFE_DELETE(texture);
		}
	}

	return texture;
}
开发者ID:gered,项目名称:MyGameFramework,代码行数:32,代码来源:solidcolortexturecache.cpp

示例2: InsertImage

bool PackedTexture::InsertImage(const Image & pImg, int & pOffsetU, int & pOffsetV, unsigned int & pTextureIndex) {
	
	// Validate image size
	if(pImg.GetWidth() > mTexSize || pImg.GetHeight() > mTexSize) {
		return false;
	}
	
	// Copy to one of the existing image
	TextureTree::Node * node = NULL;
	unsigned int nodeTree = 0;
	
	for(unsigned int i = 0; i < mTexTrees.size(); i++) {
		node = mTexTrees[i]->InsertImage( pImg );
		nodeTree = i;
	}
	
	// No space found, create a new tree
	if(!node) {
		
		mTexTrees.push_back(new TextureTree(mTexSize));
		
		Image* newPage = new Image();
		newPage->Create(mTexSize, mTexSize, mTexFormat);
		newPage->Clear();
		
		mImages.push_back(newPage);
		
		node = mTexTrees[mTexTrees.size() - 1]->InsertImage(pImg);
		nodeTree = mTexTrees.size() - 1;
	}
	
	// A node must have been found.
	arx_assert(node);
	
	// Copy texture there
	if(node) {
		
		mImages[nodeTree]->Copy( pImg, node->mRect.left, node->mRect.top );
		
		// Copy values back into info structure.
		pOffsetU = node->mRect.left;
		pOffsetV = node->mRect.top;
		pTextureIndex = nodeTree;
	}
	
	return node != NULL;
}
开发者ID:lemmel,项目名称:ArxLibertatis,代码行数:47,代码来源:PackedTexture.cpp

示例3: InitTexture

/// Initialize the texture.
void GLViewer::InitTexture(const char * aFileName)
{
  Image image;

  // Load texture from a file
  if(aFileName)
  {
    // Check if file exists, and determine actual file name (relative or absolute)
    bool fileExists = false;
    string name = string(aFileName);
    FILE * inFile = fopen(name.c_str(), "rb");
    if(inFile)
      fileExists = true;
    else if(mFilePath.size() > 0)
    {
      // Try the same path as the mesh file
      name = mFilePath + string(aFileName);
      inFile = fopen(name.c_str(), "rb");
      if(inFile)
        fileExists = true;
    }
    if(inFile)
      fclose(inFile);

    if(fileExists)
    {
      cout << "Loading texture (" << aFileName << ")..." << endl;
      try
      {
        image.LoadFromFile(name.c_str());
      }
      catch(exception &e)
      {
        cout << "Error loading texture: " << e.what() << endl;
        image.Clear();
      }
    }
  }

  // If no texture was loaded
  if(image.IsEmpty())
  {
    cout << "Loading texture (dummy)..." << endl;

    // Create a default, synthetic texture
    image.SetSize(256, 256, 1);
    for(int y = 0; y < image.mHeight; ++ y)
    {
      for(int x = 0; x < image.mWidth; ++ x)
      {
        if(((x & 0x000f) == 0) || ((y & 0x000f) == 0))
          image.mData[y * image.mWidth + x] = 192;
        else
          image.mData[y * image.mWidth + x] = 255;
      }
    }
  }

  // Upload the texture to OpenGL
  if(!image.IsEmpty())
    glGenTextures(1, &mTexHandle);
  else
    mTexHandle = 0;
  if(mTexHandle)
  {
    // Determine the color format
    GLuint format;
    if(image.mComponents == 3)
      format = GL_RGB;
    else if(image.mComponents == 4)
      format = GL_RGBA;
    else
      format = GL_LUMINANCE;

    glBindTexture(GL_TEXTURE_2D, mTexHandle);

    if(GLEW_VERSION_1_4)
    {
      // Generate mipmaps automatically and use them
      glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    }
    else
    {
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexImage2D(GL_TEXTURE_2D, 0, image.mComponents, image.mWidth, image.mHeight, 0, format, GL_UNSIGNED_BYTE, (GLvoid *) &image.mData[0]);
  }
}
开发者ID:mbitsnbites,项目名称:openctm,代码行数:94,代码来源:ctmviewer.cpp

示例4: CreateHalo

bool TextureContainer::CreateHalo() {
	
	Image srcImage;
	if(!srcImage.LoadFromFile(m_pTexture->getFileName())) {
		return false;
	}
	
	// Allocate and add the texture to the linked list of textures;
	res::path haloName = m_texName.string();
	haloName.append("_halo");
	TextureHalo = new TextureContainer(haloName, NoMipmap | NoColorKey);
	if(!TextureHalo) {
		return false;
	}
	
	TextureHalo->m_pTexture = GRenderer->CreateTexture2D();
	if(!TextureHalo->m_pTexture) {
		return true;
	}
	
	Image im;
	
	int width = m_size.x + HALO_RADIUS * 2;
	int height = m_size.y + HALO_RADIUS * 2;
	im.Create(width, height, srcImage.GetFormat());
	
	// Center the image, offset by radius to contain the edges of the blur
	im.Clear();
	im.Copy(srcImage, HALO_RADIUS, HALO_RADIUS);
	
	// Keep a copy of the image at this stage, in order to apply proper alpha masking later
	Image copy = im;
	
	// Convert image to grayscale, and turn it to black & white
	im.ToGrayscale(Image::Format_L8A8);
	im.ApplyThreshold(0, ~0);

	// Blur the image
	im.Blur(HALO_RADIUS);

	// Increase the gamma of the blur outline
	im.QuakeGamma(10.0f);

	// Set alpha to inverse of original image alpha
	copy.ApplyColorKeyToAlpha();
	im.SetAlpha(copy, true);
	
	TextureHalo->m_pTexture->Init(im, 0);
	
	TextureHalo->m_size.x = TextureHalo->m_pTexture->getSize().x;
	TextureHalo->m_size.y = TextureHalo->m_pTexture->getSize().y;
	
	Vec2i storedSize = TextureHalo->m_pTexture->getStoredSize();
	TextureHalo->uv = Vec2f(
		float(TextureHalo->m_size.x) / storedSize.x,
		float(TextureHalo->m_size.y) / storedSize.y
	);
	TextureHalo->hd = Vec2f(.5f / storedSize.x, .5f / storedSize.y);
	
	return true;
}
开发者ID:Dimoks,项目名称:ArxLibertatis_fork,代码行数:61,代码来源:TextureContainer.cpp

示例5: Render

    void Render(Image &dest) const {
        dest.Clear();

        for (PolyList::const_iterator it = poly_.begin(); it != poly_.end(); ++it)
            it->Render(dest);
    }
开发者ID:isadorasophia,项目名称:genetic_cu,代码行数:6,代码来源:genetic.cpp

示例6: main


//.........这里部分代码省略.........
  XStoreName(display, window, "V4L RGB Test");

  XGetWindowAttributes(display, window, &windowAttributes);

  if (((windowAttributes.depth == 8) && (windowAttributes.visual->c_class != PseudoColor)) ||
      ((windowAttributes.depth > 8) && (windowAttributes.visual->c_class != TrueColor))) {
    printf("Error: Visual not supported\n");
    exit(1);
  } // end if

  // Create PseudoColor HI240 colormap, if needed

  if (windowAttributes.depth == 8) {
    colormap = XCreateColormap(display, window, windowAttributes.visual, AllocAll);
    paletteInfo.display = display;
    paletteInfo.colormap = colormap;
    Hi240BuildPalette((ulong) 0x10000, (Hi240StorePaletteEntry *) StoreColormapEntry, &paletteInfo);
    XSetWindowColormap(display, window, colormap);
  } // end if

  // Create image

  if (image.Create(
    display,
    window, // Defines visual, depth
    MaxImageWidth,
    MaxImageHeight,
    True // MITSHM
    ) < 0) {
    printf("Error: image.Create() failed\n");
    exit(1);
  } // end if

  image.Clear();

#if (1)
  printf("\nDisplay:\n");
  printf("Image byte order = %s\n", ByteOrderName(ImageByteOrder(display)));
  printf("Bitmap unit      = %i\n", BitmapUnit(display));
  printf("Bitmap bit order = %s\n", ByteOrderName(BitmapBitOrder(display)));
  printf("Bitmap pad       = %i\n", BitmapPad(display));

  printf("\nWindow:\n");
  printf("Depth            = %i\n", windowAttributes.depth);
  printf("Visual ID        = 0x%02x\n", windowAttributes.visual->visualid);
  printf("Visual class     = %s\n", VisualClassName(windowAttributes.visual->c_class));
  printf("Red mask         = 0x%08lx\n", windowAttributes.visual->red_mask);
  printf("Green mask       = 0x%08lx\n", windowAttributes.visual->green_mask);
  printf("Blue mask        = 0x%08lx\n", windowAttributes.visual->blue_mask);
  printf("Bits per R/G/B   = %i\n", windowAttributes.visual->bits_per_rgb); // log2 # colors

  xImage = image.X();
  printf("\nImage:\n");
  printf("Image byte order = %s\n", ByteOrderName(xImage->byte_order));
  printf("Bitmap unit      = %i\n", xImage->bitmap_unit);
  printf("Bitmap bit order = %s\n", ByteOrderName(xImage->bitmap_bit_order));
  printf("Bitmap pad       = %i\n", xImage->bitmap_pad);
  printf("Depth            = %i\n", xImage->depth);
  printf("Red mask         = 0x%08lx\n", xImage->red_mask);
  printf("Green mask       = 0x%08lx\n", xImage->green_mask);
  printf("Blue mask        = 0x%08lx\n", xImage->blue_mask);
  printf("Bits per pixel   = %i\n", xImage->bits_per_pixel); // ZPixmap
  printf("Bytes per line   = %i\n", xImage->bytes_per_line);
  printf("IsShared         = %s\n", image.IsShared() ? "True" : "False");
  printf("HasSharedPixmap  = %s\n", image.HasSharedPixmap() ? "True" : "False");
#endif
开发者ID:jeez,项目名称:iqr,代码行数:67,代码来源:vidrgb.cpp


注:本文中的Image::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。