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


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

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


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

示例1: PostLoad

	void SpriteAnimationTest::PostLoad()
	{
		App::PostLoad();

		GameObject* playerGameObject = scene->AddGameObject(new GameObject("player"));

		AnimationController* animationController = new AnimationController();
		animationController->dataTypes.emplace_back(new AInt(20));

		//-----------------------------------------------------------------------------------------------------------------------------------

		for (size_t i = 0; i < 8; i++)
			walkingLeftKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 0, 32, 48)));
		
		for (size_t i = 0; i < 6; i++)
			walkingRightKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 48, 32, 48)));

		sequence->emplace_back(walkingLeftKeyframes);
		sequence->emplace_back(walkingRightKeyframes);

		AnimationData data("../Sandbox/Assets/Textures/player.png", sequence);
		data.filePath = "../Sandbox/Assets/Textures/player.png";

		Texture2D* texture = new Texture2D();
		texture->Create(ResourceManager::Load<TextureData>(data.textureName), Texture::Format::R8G8B8A8);

		BF::Graphics::Animation::Animation* walkingLeftAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[0], true);
		BF::Graphics::Animation::Animation* walkingRightAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[1], true);

		//-----------------------------------------------------------------------------------------------------------------------------------

		AnimationNode* walkingLeftAnimationNode = new AnimationNode();
		walkingLeftAnimationNode->animation = walkingLeftAnimation;

		AnimationNode* walkingRightAnimationNode = new AnimationNode();
		walkingRightAnimationNode->animation = walkingRightAnimation;

		//-----------------------------------------------------------------------------------------------------------------------------------

		Transition* startingNodeTransition = new Transition(walkingLeftAnimationNode, true);
		Condition* startingCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10));
		startingNodeTransition->conditions.emplace_back(startingCondition);

		animationController->startingAnimationNode->transition = startingNodeTransition;

		//-----------------------------------------------------------------------------------------------------------------------------------

		Transition* walkingLeftTransition = new Transition(walkingRightAnimationNode, true);
		Condition* walkingLeftCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10));
		walkingLeftTransition->conditions.emplace_back(walkingLeftCondition);

		walkingLeftAnimationNode->transitions.emplace_back(walkingLeftTransition);

		//-----------------------------------------------------------------------------------------------------------------------------------

		Animator* animator = (Animator*)playerGameObject->AddComponent(new Animator(animationController));
		//animator->gameObject->GetTransform()->SetScale(Vector3f(3, 3, 3));

		App::RunScene(*scene);
	}
开发者ID:Vault16Software,项目名称:Blue-Flame-Engine,代码行数:60,代码来源:SpriteAnimationTest.cpp

示例2: VInitialize

ABOOL GBufferOne::VInitialize()
{
	//==
	//Define properties for textures
	//==
	Texture2DParams * pParams = new Texture2DParams();
	pParams->Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, TEX_R32G32B32A32_FLOAT, true, false, 
		true, false, 1, 0, 1, true, false, false);
		//==
	//Create textures
	//==
	Texture2D pTex = *m_pPosTex;
	pTex.Create(pParams);
	m_pPosTex->Create(pParams);
	m_pNormalTex->Create(pParams);
	m_pDepthTex->Create(pParams);
	m_pDiffuseTex->Create(pParams);
	m_pSpecularTex->Create(pParams);


	//Define properties for shader resource views
	ShaderResourceViewParams * pSRVParams = new ShaderResourceViewParams();
	pSRVParams->InitForTexture2D(pParams->Format, 1, 0);

	//==
	//Create Shader Resource Views
	//==
	m_pPosTex->CreateShaderResourceView(m_SRVList.GetView(0), pSRVParams);
	m_pNormalTex->CreateShaderResourceView(m_SRVList.GetView(1), pSRVParams);
	m_pDepthTex->CreateShaderResourceView(m_SRVList.GetView(2), pSRVParams);
	m_pDiffuseTex->CreateShaderResourceView(m_SRVList.GetView(3), pSRVParams);
	m_pSpecularTex->CreateShaderResourceView(m_SRVList.GetView(4), pSRVParams);

	//Define properties for shader resource views
	RenderTargetViewParams * pRTVParams = new RenderTargetViewParams();
	pRTVParams->InitForTexture2D(pParams->Format, 0);

	//==
	//Create Render Target Views
	//==
	m_pPosTex->CreateRenderTargetView(m_RTVList.GetView(0), pRTVParams);
	m_pNormalTex->CreateRenderTargetView(m_RTVList.GetView(1), pRTVParams);
	m_pDepthTex->CreateRenderTargetView(m_RTVList.GetView(2), pRTVParams);
	m_pDiffuseTex->CreateRenderTargetView(m_RTVList.GetView(3), pRTVParams);
	m_pSpecularTex->CreateRenderTargetView(m_RTVList.GetView(4), pRTVParams);

	return 1;
}
开发者ID:Solidstatewater,项目名称:Engine,代码行数:48,代码来源:GBuffer.cpp

示例3: Import


//.........这里部分代码省略.........
                ptrTexCoord->x = (x+0.5f) / 8.0f;
                ptrTexCoord->y = (z+0.5f) / 8.0f;

				ptrTexCoordAlpha->x = (x+0.5f+0.125f) / 8.25f;
				ptrTexCoordAlpha->y = (z+0.5f+0.125f) / 8.25f;

                ptrDataHeight++;
                ptrDataNormals += 3;
                
				ptrPosition++;
                ptrNormal++;
				ptrTexCoord++;
                ptrTexCoordAlpha++;

                posX += UNIT_SIZE;
            }
            posZ += 0.5f * UNIT_SIZE;
        }


        WorldTile::TerrainChunk* newChunk = GD_NEW(WorldTile::TerrainChunk, this, "WoW::WorldTile::TerrainChunk");

		for( UInt32 iLayer = 0; iLayer < mapChunk->mTextureLayers.size(); iLayer++ )
        {
			String textureName("Data/");
			textureName += adtFile.mTextureNames[mapChunk->mTextureLayers[iLayer].mTextureID];
			HTexture2D texture(textureName);

            Texture2D* alpha = NULL;

            if( iLayer != 0 )
            {
                alpha = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( "AlphaMap" ));
                alpha->Create( mapChunk->mAlphaMaps[iLayer-1], true );
                alpha->Init();
                alpha->SetWrapMode( Texture::Wrap_S, Texture::Wrap_Clamp );
                alpha->SetWrapMode( Texture::Wrap_T, Texture::Wrap_Clamp );
                alpha->SetMinFilter( Texture::MinFilter_Linear );
                alpha->SetMagFilter( Texture::MagFilter_Linear );
            }

			newChunk->AddTextureLayer( texture, alpha );
		}

        UInt32 detailedStripSize = (16*18 + 7*2 + 8*2);
        UInt32 normalStripSize   = 158;

        // Build index buffer
        newChunk->GetHiResTriangles().Allocate( TriangleBatch::TriangleStrip, detailedStripSize );
        newChunk->GetLowResTriangles().Allocate( TriangleBatch::TriangleStrip, normalStripSize );
        UInt16* ptrHiIndices = newChunk->GetHiResTriangles().GetIndices();
        UInt16* ptrLoIndices = newChunk->GetLowResTriangles().GetIndices();
        
        for( int row = 0; row < 8; row++ )
        { 
            UInt32 topRow       = verticesOffset + row*(9+8);
            UInt32 detailrow    = verticesOffset + row*(9+8) + 9;
            UInt32 nextRow      = verticesOffset + (row+1)*(9+8);
            
            if( row > 0 )
            {
                *ptrHiIndices++ = topRow + 0;     // jump end
                *ptrLoIndices++ = topRow + 0;
            }
            
            for( int col = 0; col < 8; col++ )
开发者ID:SebastienLussier,项目名称:Gamedesk,代码行数:67,代码来源:WoWImporter.cpp

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


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