OGRE3D

[OGRE3D] 수동으로 객체 그리고, 텍스쳐 입히는 방법

炫's 2013. 1. 30. 14:49
택스쳐 생성
Ogre::TexturePtr texture;
texture = TextureManager::getSingleton().createManual(
		"TextureName",		⁄⁄ 텍스쳐의 이름입니다.
		"ResourceGroup",	⁄⁄ 텍스쳐가 생성될 리소스 그룹입니다.
		TEX_TYPE_2D,		⁄⁄ 텍스쳐 타입
		width,				⁄⁄ 폭
		height,				⁄⁄ 높이
		1,					⁄⁄ 깊이(2차원 텍스쳐는 반듯이 1로 설정해야만 합니다.)
		0,					⁄⁄ 밉맵의 갯수
		PF_A8R8G8B8,		⁄⁄ 픽셀 포멧
		TU_STATIC			⁄⁄ 사용법
	);

Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("TextureName", "ResourceGroup");
material->getTechnique(0)->getPass(0)->createTextureUnitState(iter2->c_str());
material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
material->getTechnique(0)->getPass(0)->setAlphaRejectSettings(CompareFunction::CMPF_GREATER, Ogre::StringConverter::parseInt("128"));
material->setCullingMode(Ogre::CULL_NONE );

수동으로 객체 그림
ManualObject* manual = pSceneMgr->createManualObject((*iter2));
manual->begin("ObjectName", RenderOperation::OT_TRIANGLE_LIST);
for(int i=0; i<nSize; i++)
{
	manual->position(x, y, z);
	manual->normal(z, y, z);
	manual->textureCoord(u, v);
}
manual->end();
이미지 픽셀데이터를 텍스쳐 버퍼에 복사
Ogre::HardwarePixelBufferSharedPtr pxBuffer = texture->getBuffer();
pxBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& pixelBox = pxBuffer->getCurrentLock();
Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);

for(int i=height-1; i >= 0; i--)
{    
	for(int j=0; j < width; j++)
	{
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 0)];		⁄⁄ B
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 1)];		⁄⁄ G
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 2)];		⁄⁄ R
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 3)];		⁄⁄ A
	}
}

pxBuffer->unlock();