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


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

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


在下文中一共展示了Image::Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Import

Resource* BLPImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
	WoW::BLPFile        blpFile;
	WoW::BLPFileReader  blpFileReader( blpFile );

	blpFileReader.Read( pFilename );

	Image::Format format;
	if( blpFile.mHeader.mCompression == 2 )
	{
		if( blpFile.mHeader.mAlphaBits == 0 )
			format = Image::Format_DXT1;
		else if( blpFile.mHeader.mAlphaBits == 8 )
			format = Image::Format_DXT3;
		else
			format = Image::Format_DXT5;
	}
	else
	{
		format = Image::Format_R8G8B8A8;
	}

	Image img;
	img.Create( blpFile.mHeader.mSizeX, blpFile.mHeader.mSizeY, format, blpFile.mMipmapCount );

	memcpy( img.GetData(), &blpFile.mData[0], blpFile.mData.size() );

	Texture2D* tex2D = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( pFilename ));
	tex2D->Create( img );
	
	return tex2D;	
}
开发者ID:SebastienLussier,项目名称:Gamedesk,代码行数:32,代码来源:WoWImporter.cpp

示例3: if

void GLTexture2D::Upload() {
	
	arx_assert(tex != GL_NONE);
	
	glBindTexture(GL_TEXTURE_2D, tex);
	renderer->GetTextureStage(0)->current = this;
	
	GLint internal;
	GLenum format;
	if(flags & Intensity) {
		internal = GL_INTENSITY8, format = GL_RED;
	} else if(mFormat == Image::Format_L8) {
		internal = GL_LUMINANCE8, format = GL_LUMINANCE;
	} else if(mFormat == Image::Format_A8) {
		internal = GL_ALPHA8, format = GL_ALPHA;
	} else if(mFormat == Image::Format_L8A8) {
		internal = GL_LUMINANCE8_ALPHA8, format = GL_LUMINANCE_ALPHA;
	} else if(mFormat == Image::Format_R8G8B8) {
		internal = GL_RGB8, format = GL_RGB;
	} else if(mFormat == Image::Format_B8G8R8) {
		internal = GL_RGB8, format = GL_BGR;
	} else if(mFormat == Image::Format_R8G8B8A8) {
		internal = GL_RGBA8, format = GL_RGBA;
	} else if(mFormat == Image::Format_B8G8R8A8) {
		internal = GL_RGBA8, format = GL_BGRA;
	} else {
		arx_assert(false, "Unsupported image format: %ld", long(mFormat));
		return;
	}
	
	if(storedSize != size) {
		flags &= ~HasMipmaps;
	}
	
	if(hasMipmaps()) {
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
	} else {
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
	}
	
	// TODO handle GL_MAX_TEXTURE_SIZE
	
	if(storedSize != size) {
		Image extended;
		extended.Create(storedSize.x, storedSize.y, mImage.GetFormat());
		extended.extendClampToEdgeBorder(mImage);
		glTexImage2D(GL_TEXTURE_2D, 0, internal, storedSize.x, storedSize.y, 0, format,
		             GL_UNSIGNED_BYTE, extended.GetData());
	} else {
		glTexImage2D(GL_TEXTURE_2D, 0, internal, size.x, size.y, 0, format,
		             GL_UNSIGNED_BYTE, mImage.GetData());
	}
	
	if(renderer->getMaxAnisotropy() >= 1.f) {
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, renderer->getMaxAnisotropy());
	}
}
开发者ID:Drakesinger,项目名称:ArxLibertatis,代码行数:57,代码来源:GLTexture2D.cpp

示例4: CopyToImage

Image Texture::CopyToImage() const
{
    // Easy case: empty texture
    if (!myTexture)
        return Image();

    EnsureGlContext();

    // Make sure that the current texture binding will be preserved
    priv::TextureSaver save;

    // Create an array of pixels
    std::vector<Uint8> pixels(myWidth * myHeight * 4);

    if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight) && !myPixelsFlipped)
    {
        // Texture is not padded nor flipped, we can use a direct copy
        GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
        GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
    }
    else
    {
        // Texture is either padded or flipped, we have to use a slower algorithm

        // All the pixels will first be copied to a temporary array
        std::vector<Uint8> allPixels(myTextureWidth * myTextureHeight * 4);
        GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
        GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0]));

        // Then we copy the useful pixels from the temporary array to the final one
        const Uint8* src = &allPixels[0];
        Uint8* dst = &pixels[0];
        int srcPitch = myTextureWidth * 4;
        int dstPitch = myWidth * 4;

        // Handle the case where source pixels are flipped vertically
        if (myPixelsFlipped)
        {
            src += srcPitch * (myHeight - 1);
            srcPitch = -srcPitch;
        }

        for (unsigned int i = 0; i < myHeight; ++i)
        {
            std::memcpy(dst, src, dstPitch);
            src += srcPitch;
            dst += dstPitch;
        }
    }

    // Create the image
    Image image;
    image.Create(myWidth, myHeight, &pixels[0]);

    return image;
}
开发者ID:ChrisJansson,项目名称:Graphics,代码行数:56,代码来源:Texture.cpp

示例5: Load

bool AVI :: Load(std :: string fname,bool loopflag,Texture *tex)				// Opens An AVI File
{
	// copy over looping flag
	loop=loopflag;

	// do we have a texture manager?
	if(!tex)
		return false;
	// copy it over
	tman=tex;

	hdc=CreateCompatibleDC(0);									// Get a compatible DC
	hdd = DrawDibOpen();										// Grab A Device Context For Our Dib


	AVIFileInit();												// Opens The AVIFile Library

	// Opens The AVI Stream
	if (AVIStreamOpenFromFile(&pavi, fname.c_str(), streamtypeVIDEO, 0, OF_READ, NULL) !=0)
		return false;

	AVIStreamInfo(pavi, &psi, sizeof(psi));						// Reads Information About The Stream Into psi
	width=psi.rcFrame.right-psi.rcFrame.left;					// Width Is Right Side Of Frame Minus Left
	height=psi.rcFrame.bottom-psi.rcFrame.top;					// Height Is Bottom Of Frame Minus Top

	lastframe=AVIStreamLength(pavi);							// The Last Frame Of The Stream

	mpf=AVIStreamSampleToTime(pavi,lastframe)/lastframe;		// Calculate Rough Milliseconds Per Frame

	bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	bmih.biPlanes = 1;											// Bitplanes	
	bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	bmih.biWidth = 256;											// Width We Want (256 Pixels)
	bmih.biHeight = 256;										// Height We Want (256 Pixels)
	bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	hBitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
	SelectObject (hdc, hBitmap);								// Select hBitmap Into Our Device Context (hdc)

	pgf=AVIStreamGetFrameOpen(pavi, NULL);						// Create The PGETFRAME	Using Our Request Mode
	if (pgf==NULL)
		return false;

	// create the texture
	Image img;
	img.Create(256,256,false);									// set dimensions of texture
	img.SetImage(data);											// set the texture information
	texid=tman->Create(&img);									// create the texture

	// clear the time position 
	pos=0;

	// success
	return true;
}
开发者ID:2013chengguo,项目名称:geometrytest,代码行数:55,代码来源:avi.cpp

示例6: getSnapshot

bool OpenGLRenderer::getSnapshot(Image & image) {
	
	Vec2i size = mainApp->getWindow()->getSize();
	
	image.Create(size.x, size.y, Image::Format_R8G8B8);
	
	glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, image.GetData()); 
	
	image.FlipY();
	
	return true;
}
开发者ID:HerculesCE,项目名称:ArxLibertatis,代码行数:12,代码来源:OpenGLRenderer.cpp

示例7: SetPalette

void CTextureCtrl::SetPalette(DC2_ENTRY_GFX *gfx_entry, u16 *gfx_data, int depth, int cx, int cy)
{
	Image img;

	switch(depth)
	{
	case 0: depth=4; break;		// 4 bpp, get 16 colors
	case 1: depth=8; break;		// 8 bpp, get 256 colors
	case 2:		// 15 bpp, no palette needed here
		texture.w=texture.h=0;
		Invalidate();
		return;
	}

	u16* clut=new u16[1<<depth];
	// create greyscale clut
	if(!gfx_entry && !gfx_data)
	{
		SetGreyscale(depth);
		for(int i=0; i<(1<<depth); i++)
			clut[i]=TIMRGB(palette[i].rgbRed,palette[i].rgbGreen,palette[i].rgbBlue);
	}
	// otherwise copy section
	else
		for(int i=0; i<(1<<depth); i++)
			clut[i]=GetClutColor(gfx_entry,gfx_data,i+cx,cy);

	// determine client size
	CRect rect;
	GetClientRect(&rect);

	// create canvas
	img.Create(rect.Width()/COLOR_CELL*COLOR_CELL,rect.Height(),24,NULL);
	// draw clut to bitmap
	for(int i=0; i<(1<<depth); i++)
	{
		RGBQUAD pixel=ClutToRgb(clut[i],0);

		int x=(i%(rect.Width()/COLOR_CELL))*COLOR_CELL;
		int y=(i/(rect.Width()/COLOR_CELL))*COLOR_CELL;
		// set color
		for(int xi=0; xi<COLOR_CELL; xi++)
			for(int yi=0; yi<COLOR_CELL; yi++)
				img.SetPixelAt(x+xi,y+yi,*((u32*)&pixel));
	}

	texture.LoadBitmap(img);
	Invalidate();

	delete[] clut;
}
开发者ID:Gemini-Loboto3,项目名称:Dino-Clasher,代码行数:51,代码来源:TextureCtrl.cpp

示例8: 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

示例9: getSnapshot

bool OpenGLRenderer::getSnapshot(Image & image, size_t width, size_t height) {
	
	// TODO handle scaling on the GPU so we don't need to download the whole image
	
	Image fullsize;
	
	getSnapshot(fullsize);
	
 	image.Create(width, height, Image::Format_R8G8B8);
	
	GLint ret = gluScaleImage(GL_RGB, fullsize.GetWidth(), fullsize.GetHeight(), GL_UNSIGNED_BYTE,
	                          fullsize.GetData(), width, height, GL_UNSIGNED_BYTE, image.GetData());
	
	if(ret) {
		LogWarning << "Failed to scaled down screen capture: " << ret << " = " << gluErrorString(ret);
		return false;
	}
	
	return true;
}
开发者ID:lemmel,项目名称:ArxLibertatis,代码行数:20,代码来源:OpenGLRenderer.cpp

示例10: Capture

Image RenderWindow::Capture() const
{
    Image image;
    if (SetActive())
    {
        int width = static_cast<int>(GetWidth());
        int height = static_cast<int>(GetHeight());

        // copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top)
        std::vector<Uint8> pixels(width * height * 4);
        for (int i = 0; i < height; ++i)
        {
            Uint8* ptr = &pixels[i * width * 4];
            GLCheck(glReadPixels(0, height - i - 1, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, ptr));
        }

        image.Create(width, height, &pixels[0]);
    }

    return image;
}
开发者ID:ChrisJansson,项目名称:Graphics,代码行数:21,代码来源:RenderWindow.cpp

示例11: 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

示例12: Import

Resource* DevILImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    ILuint  imageName;

    // Load the image. DevIL will guess the type of the image file using it's extension and if needed it's header.
    ilGenImages( 1, &imageName );
    ilBindImage( imageName );

    // Load the image.
    if( !ilLoadImage( const_cast<char*>(pFilename.c_str()) ) )
        throw ResourceImportException( ToString(ilGetError()), Here );

    // Get the image params.
    ILint bytesPerPixel   = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
    ILint imgFormat       = ilGetInteger( IL_IMAGE_FORMAT );
    ILint imgWidth        = ilGetInteger( IL_IMAGE_WIDTH );
    ILint imgHeight       = ilGetInteger( IL_IMAGE_HEIGHT );

    // We do not support palettized texture currently, so un-palettize them!
    if( imgFormat == IL_COLOR_INDEX )
    {
        switch( ilGetInteger( IL_PALETTE_TYPE ) )
        {
        case IL_PAL_RGB24:
        case IL_PAL_RGB32:
            imgFormat = IL_RGB;
            break;
        case IL_PAL_BGR24:
        case IL_PAL_BGR32:
            imgFormat = IL_BGR;
            break;
        case IL_PAL_RGBA32:
            imgFormat = IL_RGBA;
            break;
        case IL_PAL_BGRA32:
            imgFormat = IL_BGRA;
            break;
        default:
            debugBreak();
        }

        ilConvertImage( imgFormat, IL_UNSIGNED_BYTE );
        bytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
        imgFormat     = ilGetInteger( IL_IMAGE_FORMAT );
    }

    // Find what is the gamedesk internal image format that will be used.
    Image::Format gdImgFormat = GetImageFormat( imgFormat, bytesPerPixel );

    Image newImage;
    newImage.Create( imgWidth, imgHeight, gdImgFormat );
    memcpy( newImage.GetData(), ilGetData(), imgWidth*imgHeight*bytesPerPixel );

    Texture* newTexture = NULL;

    // Allocate and create using image.
    if( imgWidth == 1 || imgHeight == 1 )
    {
        Texture1D* tex = Cast<Texture1D>(Texture1D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }
    else
    {
        Texture2D* tex = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }

    // The DevIL copy of the image is not needed anymore, so destroy it.
    ilDeleteImages( 1, &imageName );

    return newTexture;
}
开发者ID:SebastienLussier,项目名称:Gamedesk,代码行数:74,代码来源:DevILImporter.cpp

示例13: insertGlyph

bool Font::insertGlyph(u32 character) {
	
	FT_Error error;
	FT_UInt glyphIndex = FT_Get_Char_Index(m_FTFace, character);
	if(!glyphIndex) {
		insertPlaceholderGlyph(character);
		return false;
	}
	
	error = FT_Load_Glyph(m_FTFace, glyphIndex, FT_LOAD_FORCE_AUTOHINT);
	if(error) {
		insertPlaceholderGlyph(character);
		return false;
	}
	
	error = FT_Render_Glyph(m_FTFace->glyph, FT_RENDER_MODE_NORMAL);
	if(error) {
		insertPlaceholderGlyph(character);
		return false;
	}
	
	// Fill in info for this glyph.
	Glyph & glyph = m_Glyphs[character];
	glyph.size.x = m_FTFace->glyph->bitmap.width;
	glyph.size.y = m_FTFace->glyph->bitmap.rows;
	glyph.advance.x = m_FTFace->glyph->linearHoriAdvance / 65536.0f;
	glyph.advance.y = m_FTFace->glyph->linearVertAdvance / 65536.0f;
	glyph.lsb_delta = m_FTFace->glyph->lsb_delta;
	glyph.rsb_delta = m_FTFace->glyph->rsb_delta;
	glyph.draw_offset.x = m_FTFace->glyph->bitmap_left;
	glyph.draw_offset.y = m_FTFace->glyph->bitmap_top - m_FTFace->glyph->bitmap.rows;
	glyph.uv_start = Vec2f::ZERO;
	glyph.uv_end = Vec2f::ZERO;
	glyph.texture = 0;
	
	// Some glyphs like spaces have a size of 0...
	if(glyph.size.x != 0 && glyph.size.y != 0) {
		
		Image imgGlyph;
		imgGlyph.Create(glyph.size.x, glyph.size.y, Image::Format_A8);
		
		FT_Bitmap * srcBitmap = &m_FTFace->glyph->bitmap;
		arx_assert(srcBitmap->pitch == srcBitmap->width);
		
		// Copy pixels
		unsigned char * src = srcBitmap->buffer;
		unsigned char * dst = imgGlyph.GetData();
		memcpy(dst, src, glyph.size.x * glyph.size.y);
		
		Vec2i offset;
		m_Textures->insertImage(imgGlyph, glyph.texture, offset);
		
		// Compute UV mapping for each glyph.
		const float textureSize = m_Textures->getTextureSize();
		glyph.uv_start.x = offset.x / textureSize;
		glyph.uv_start.y = offset.y / textureSize;
		glyph.uv_end.x = (offset.x + glyph.size.x) / textureSize;
		glyph.uv_end.y = (offset.y + glyph.size.y) / textureSize;
	}
	
	return true;
}
开发者ID:fourks,项目名称:ArxLibertatis,代码行数:62,代码来源:Font.cpp

示例14: main

int main(int argc, char *argv[])
{
// For detecting memory leaks
#ifdef _MSVC
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif

    //// Seed the random number generator
    //srand( (unsigned int)time( 0 ) );

    // Display license
    std::cout
        << "RayWatch - A simple cross-platform RayTracer."                  << std::endl
        << "Copyright (C) 2008"                                             << std::endl
        << "  Angelo Rohit Joseph Pulikotil,"                               << std::endl
        << "  Francis Xavier Joseph Pulikotil"                              << std::endl
        << "This program comes with ABSOLUTELY NO WARRANTY."                << std::endl
        << "This is free software, and you are welcome to redistribute it"  << std::endl
        << "under certain conditions; see <http://www.gnu.org/licenses/>."  << std::endl << std::endl;

    if( argc < 3 )
    {
        std::cout << "Insufficient arguments" << std::endl << std::endl;
        std::cout << "Syntax (to render a Scene file):" << std::endl << argv[0] << " <input scene filename> <output bitmap filename> [width] [height]" << std::endl << std::endl;
        std::cout << "Syntax (to generate a sample file): " << std::endl << argv[0] << " --gen:<sample name> <output scene filename>" << std::endl << std::endl;
        std::cout << "Currently supported samples are CornellBox, Example1, Example2" << std::endl;
        return -1;
    }

    // If we're supposed to generate a sample file
    if( Utility::String::CaseInsensitiveCompare( std::string( argv[1] ).substr(0, 6), "--gen:" ) == 0 )
    {
        const std::string sampleName = std::string( argv[1] ).substr( 6 );

        bool bResult = false;
        if( Utility::String::CaseInsensitiveCompare( sampleName, "CornellBox" ) == 0 )
        {
            bResult = Examples::CornellBox( argv[2] );
        }
        else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example1" ) == 0 )
        {
            bResult = Examples::Example1( argv[2] );
        }
        else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example2" ) == 0 )
        {
            bResult = Examples::Example2( argv[2] );
        }
        else  // We don't have this sample
            std::cout << "Error: Unknown sample name: " << sampleName << std::endl;

        if( !bResult )
            return -1;

        std::cout << "Sample '" << sampleName << "' written to file: " << argv[2] << std::endl;
        return 0;
    }

    // Get the required width
    int width = 500;
    if( argc > 3 )
    {
        if( !Utility::String::FromString(width, argv[3]) || (width < 1) )
        {
            std::cout << "Error: Invalid integer specified for width: " << argv[3] << std::endl;
            return -1;
        }
    }

    // Get the required height
    int height = 500;
    if( argc > 4 )
    {
        if( !Utility::String::FromString(height, argv[4]) || (height < 1) )
        {
            std::cout << "Error: Invalid integer specified for height: " << argv[4] << std::endl;
            return -1;
        }
    }

    // Create a Camera
    Camera camera;
    camera._position    .Set( 0, 0, 0 );
    camera._hFov        = 45 * (width / (float)height);
    camera._vFov        = 45;

    // Create an Image
    Image image;
    if( !image.Create( width, height ) )
    {
        std::cout << "Error: Failed to create Image of size " << width << "x" << height << std::endl;
        return -1;
    }

    // Open the input scene file
    std::fstream stream;
    stream.open( argv[1], std::ios_base::in );
    if( !stream.is_open() )
    {
        std::cout << "Error: Failed to open input scene file: " << argv[1] << std::endl;
//.........这里部分代码省略.........
开发者ID:angelorohit,项目名称:raywatch,代码行数:101,代码来源:Main.cpp

示例15: main

int main(int argc, char **argv)

{
  Atom                atomWMDeleteWindow;
  int	              screenNumber;
  Screen              *screen;
  Window              window;
  XWindowAttributes   windowAttributes;
  Colormap            colormap;
  PaletteInfo         paletteInfo;
  Image               image;
  XImage              *xImage;
  int                 x, y;
  int                 captureFrame;
  XEvent              event;
  bool                sizeChanged;


  // ProgramExit initialization

  display = NULL;
  v4l = -1;
  captureBuf = NULL;

  on_exit(ProgramExit, NULL);

  // Get command line options

  magnification = 1;

  if (argc > 1) {
    magnification = atoi(argv[1]);
  } // end if

  magnification = max(1, magnification);

  printf("Magnification is %i\n", magnification);

  // Open display

  if ((display = XOpenDisplay(NULL)) == NULL) { // NULL for DISPLAY
    printf("Error: XOpenDisplay() failed\n");
    exit(1);
  } // end if

  screenNumber = DefaultScreen(display);

  screen = XScreenOfDisplay(display, screenNumber);

  // Obtain WM protocols atom for ClientMessage exit event

  if ((atomWMDeleteWindow = XInternAtom(display, AtomWMDeleteWindowName, True)) == None) {
    printf("Error: %s atom does not exist\n", AtomWMDeleteWindowName);
    exit(1);
  } // end if

  // Create window, inheriting depth and visual from root window

  window = XCreateSimpleWindow(
    display,
    RootWindowOfScreen(screen),
    0, // x
    0, // y
    640, // width
    480, // height
    0,                          // border width
    BlackPixelOfScreen(screen), // border
    BlackPixelOfScreen(screen)  // background
    );

  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");
//.........这里部分代码省略.........
开发者ID:jeez,项目名称:iqr,代码行数:101,代码来源:vidrgb.cpp


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