本文整理汇总了C++中TextureUnitState::setID方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureUnitState::setID方法的具体用法?C++ TextureUnitState::setID怎么用?C++ TextureUnitState::setID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextureUnitState
的用法示例。
在下文中一共展示了TextureUnitState::setID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}