本文整理汇总了C++中ShaderProgram::bindShaderParameters方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::bindShaderParameters方法的具体用法?C++ ShaderProgram::bindShaderParameters怎么用?C++ ShaderProgram::bindShaderParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::bindShaderParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
Bool init()
{
int width = WINDOW_W, height = WINDOW_H;
//int texid;
Entity *entity;
int texUnitId1 = 0;
int texUnitId2 = 1;
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();
if( !shaderProgram->loadShaderSource (SHADER_VERT_FILE, SHADER_FRAG_FILE) )
{
TOY3D_TIPS("Error: loadShaderSource failed.\n");
return FALSE;
}
//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, "a_position");
params->setNamedAttrConstant(TOY3D_ATTR_UV, "a_texCoord");
//shader custom constant
params->setNamedCustUniformConstant(TOY3D_CUST_SAMPLER2D, "s_baseMap", texUnitId1);
params->setNamedCustUniformConstant(TOY3D_CUST_SAMPLER2D, "s_lightMap", texUnitId2);
shaderProgram->bindShaderParameters(params);
Texture *tex_back = TextureManager::getInstance()->createTextureByFile(TEXTURE_FILE_BACK);
Texture *tex_light = TextureManager::getInstance()->createTextureByFile(TEXTURE_FILE_LIGHT);
Material *mat = MaterialManager::getInstance()->createMaterial();
mat->setShaderProgram (shaderProgram);
//mat->setSceneBlending(T3D_SRC_ALPHA, T3D_ONE_MINUS_SRC_ALPHA, T3D_ADD);
//create tex unit 1 for back.tga
TextureUnitState *texUS_back;
texUS_back = mat->createTextureUnitState("TexUnit_back");
if(!texUS_back)
{
TOY3D_TIPS("Error: createTextureUnitState failed.\n");
return FALSE;
}
texUS_back->setID (texUnitId1);
texUS_back->setTexture(tex_back);
texUS_back->setTextureType(T3D_TEXTURE_2D);
texUS_back->setTextureParameter(T3D_LINEAR, T3D_LINEAR, T3D_CLAMP_TO_EDGE, T3D_CLAMP_TO_EDGE);
//create tex unit 2 for light.tga
TextureUnitState *texUS_light;
texUS_light = mat->createTextureUnitState("TexUnit_light");
if(!texUS_light)
{
TOY3D_TIPS("Error: createTextureUnitState failed.\n");
return FALSE;
}
texUS_light->setID (texUnitId2);
texUS_light->setTexture(tex_light);
texUS_light->setTextureType(T3D_TEXTURE_2D);
texUS_light->setTextureParameter(T3D_LINEAR, T3D_LINEAR, T3D_CLAMP_TO_EDGE, T3D_CLAMP_TO_EDGE);
//mat->addTextureUnitState (texUS_back);
//mat->addTextureUnitState (texUS_light);
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;
}
示例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;
}