本文整理汇总了C++中TextureUnitState::setTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureUnitState::setTexture方法的具体用法?C++ TextureUnitState::setTexture怎么用?C++ TextureUnitState::setTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextureUnitState
的用法示例。
在下文中一共展示了TextureUnitState::setTexture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepareMaterialInstance
//------------------------------------------------------
void MaterialService::prepareMaterialInstance(MaterialPtr &mat,
unsigned int idx, int tag) {
if (tag < 0) // Should not be here if the polygon is sky textured
OPDE_EXCEPT("Non-instanced material instance requested");
mat->setReceiveShadows(true);
Ogre::StringStream lightmapName;
lightmapName << "@lightmap" << tag;
Pass *shadPass = mat->getTechnique(0)->getPass(0);
if (shadPass->getNumTextureUnitStates() <= 1) {
// Lightmap texture is added here
TextureUnitState *tex = shadPass->createTextureUnitState();
tex->setTexture(mLightService->getAtlasTexture(tag));
// Blend
tex->setColourOperation(LBO_MODULATE);
// Use 2nd texture co-ordinate set
tex->setTextureCoordSet(1);
// Clamp
tex->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
// Switch filtering off to see lmap pixels: TFO_NONE
tex->setTextureFiltering(TFO_BILINEAR);
} else {
// There is a definition of the lightmapping pass already, we only
// update that definition
TextureUnitState *tex = shadPass->getTextureUnitState(1);
tex->setTextureName(lightmapName.str());
tex->setTextureCoordSet(1);
}
}
示例2: init
bool init()
{
int width = WINDOW_W, height = WINDOW_H;
//int texid;
int texUnit = 0;
Real limit;
Entity *entity;
world = new World ();
printf("pointer world: %d.\n", world);
world->setSize(width, height);
world->setBackColor (1.0, 1.0, 1.0, 1.0);
camera = world->createCamera ("camera1");
win = world->createRenderWindow ();
win->addViewport (camera, 0, 0, width, height);
//shader
ShaderProgram *shaderProgram = ShaderProgramManager::getInstance()->createShaderProgram();
shaderProgram->loadShaderSource (SHADER_VERT_FILE, SHADER_FRAG_FILE);
printf("shaderProgram id: %d\n", shaderProgram->getShaderProgramID());
ShaderProgramParams *params = ShaderProgramManager::getInstance()->createShaderProgramParams();
//shader auto constant
params->setNamedAutoConstant (TOY3D_ACT_PROJECTION_MATRIX, "proj_mat");
params->setNamedAutoConstant (TOY3D_ACT_VIEW_MATRIX, "view_mat");
params->setNamedAutoConstant (TOY3D_ACT_WORLD_MATRIX, "world_mat");
//shader attributes
params->setNamedAttrConstant(TOY3D_ATTR_VERTEX, "vPosition");
params->setNamedAttrConstant(TOY3D_ATTR_UV, "vTexture");
//shader custom constant
limit = 0.1f;
printf("limit = %f.\n", limit);
params->setNamedCustUniformConstant(TOY3D_CUST_REAL1, "limit", limit);
params->setNamedCustUniformConstant(TOY3D_CUST_SAMPLER2D, "sampler2d", texUnit);
shaderProgram->bindShaderParameters(params);
Texture *tex = TextureManager::getInstance()->createTextureByFile(TEXTURE_FILE);
//unsigned char *temp = generateColorData(64, 64,4);
//Texture *tex = TextureManager::getInstance()->createTexture(temp, 64, 64, 4);
Material *mat = MaterialManager::getInstance()->createMaterial();
mat->setShaderProgram (shaderProgram);
//mat->setSceneBlending(T3D_SRC_ALPHA, T3D_ONE_MINUS_SRC_ALPHA, T3D_ADD);
TextureUnitState *texUS;
texUS = mat->createTextureUnitState("TexUnit1");
if(!texUS)
{
TOY3D_TIPS("Error: createTextureUnitState failed.\n");
return FALSE;
}
texUS->setID(texUnit);
texUS->setTexture(tex);
texUS->setTextureType(T3D_TEXTURE_2D);
texUS->setTextureParameter(T3D_LINEAR, T3D_LINEAR, T3D_CLAMP_TO_EDGE, T3D_CLAMP_TO_EDGE);
//mat->setTexture(tex);
Mesh* mesh = MeshManager::getInstance()->createMesh();
mesh->setRenderMode (TOY3D_TRIANGLE_STRIP);
mesh->setVertices (vertices, VERTEX_COUNT);
mesh->setUVs( uvs, VERTEX_COUNT);
entity = world->createEntity();
entity->setMesh(mesh);
entity->setMaterial (mat);
return true;
}