本文整理汇总了C++中ProgramPtr::setUniform方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramPtr::setUniform方法的具体用法?C++ ProgramPtr::setUniform怎么用?C++ ProgramPtr::setUniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgramPtr
的用法示例。
在下文中一共展示了ProgramPtr::setUniform方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zOffset
void GlUtils::draw3dGrid() {
using namespace gl;
GL_CHECK_ERROR;
static GeometryPtr g;
if (!g) {
Mesh m;
for (int i = 0; i < 5; ++i) {
float offset = ((float) i * 0.2f) + 0.2f;
glm::vec3 zOffset(0, 0, offset);
glm::vec3 xOffset(offset, 0, 0);
m.addVertex(-X_AXIS + zOffset);
m.addVertex(X_AXIS + zOffset);
m.addVertex(-X_AXIS - zOffset);
m.addVertex(X_AXIS - zOffset);
m.addVertex(-Z_AXIS + xOffset);
m.addVertex(Z_AXIS + xOffset);
m.addVertex(-Z_AXIS - xOffset);
m.addVertex(Z_AXIS - xOffset);
}
m.addVertex(X_AXIS);
m.addVertex(-X_AXIS);
m.addVertex(Z_AXIS);
m.addVertex(-Z_AXIS);
g = m.getGeometry(GL_LINES);
}
ProgramPtr program = getProgram(Resource::SHADERS_SIMPLE_VS, Resource::SHADERS_COLORED_FS);
GL_CHECK_ERROR;
program->use();
GL_CHECK_ERROR;
program->setUniform("Color", glm::vec4(Colors::gray,1));
GL_CHECK_ERROR;
renderGeometry(g, program);
GL_CHECK_ERROR;
}
示例2: renderBunny
void GlUtils::renderBunny() {
static GeometryPtr bunnyGeometry =
getMesh(Resource::MESHES_BUNNY2_CTM).getGeometry();
ProgramPtr program = GlUtils::getProgram(
Resource::SHADERS_LITCOLORED_VS,
Resource::SHADERS_LITCOLORED_FS);
program->use();
program->setUniform("Color", glm::vec4(1));
renderGeometry(bunnyGeometry, program);
}
示例3: renderArtificialHorizon
void GlUtils::renderArtificialHorizon(float alpha) {
static GeometryPtr geometry;
if (!geometry) {
Mesh mesh;
MatrixStack & m = mesh.getModel();
m.push();
{
m.top() = glm::translate(glm::mat4(), glm::vec3(0, 0, 1.01));
mesh.getColor() = Colors::yellow;
mesh.addQuad(0.5, 0.05f);
mesh.fillColors(true);
mesh.getColor() = Colors::lightGray;
glm::vec2 bar(0.5, 0.025);
glm::vec2 smallBar(0.3, 0.015);
for (int i = 1; i <= 4; ++i) {
float angle = i * (TAU / 18.0f);
m.identity().rotate(angle, GlUtils::X_AXIS).translate(
GlUtils::Z_AXIS);
mesh.addQuad(bar);
m.identity().rotate(HALF_TAU, GlUtils::Y_AXIS).rotate(angle,
GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
mesh.addQuad(bar);
m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(angle,
GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
mesh.addQuad(bar);
m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(HALF_TAU,
GlUtils::Y_AXIS).rotate(angle, GlUtils::X_AXIS).translate(
GlUtils::Z_AXIS);
mesh.addQuad(bar);
angle -= (TAU / 36.0f);
m.identity().rotate(angle, GlUtils::X_AXIS).translate(
GlUtils::Z_AXIS);
mesh.addQuad(smallBar);
m.identity().rotate(HALF_TAU, GlUtils::Y_AXIS).rotate(angle,
GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
mesh.addQuad(smallBar);
m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(angle,
GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
mesh.addQuad(smallBar);
m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(HALF_TAU,
GlUtils::Y_AXIS).rotate(angle, GlUtils::X_AXIS).translate(
GlUtils::Z_AXIS);
mesh.addQuad(smallBar);
}
}
m.pop();
mesh.fillNormals(true);
const Mesh & hemi = getMesh(Resource::MESHES_HEMI_CTM);
m.top() = glm::rotate(glm::mat4(), -QUARTER_TAU, GlUtils::X_AXIS);
mesh.getColor() = Colors::cyan;
mesh.addMesh(hemi, true);
m.top() = glm::rotate(glm::mat4(), QUARTER_TAU, GlUtils::X_AXIS);
mesh.getColor() = Colors::orange;
mesh.addMesh(hemi);
{
set<int> poleIndices;
for (size_t i = 0; i < mesh.positions.size(); ++i) {
const glm::vec4 & v = mesh.positions[i];
if (abs(v.x) < EPSILON && abs(v.z) < EPSILON) {
poleIndices.insert(i);
}
}
for (size_t i = 0; i < mesh.indices.size(); i += 3) {
bool black = false;
for (size_t j = i; j < i + 3; ++j) {
if (poleIndices.count(mesh.indices[j])) {
black = true;
break;
}
}
if (black) {
for (size_t j = i; j < i + 3; ++j) {
mesh.colors[mesh.indices[j]] = Colors::grey;
}
}
}
}
geometry = mesh.getGeometry();
}
ProgramPtr program = getProgram(
Resource::SHADERS_LITCOLORED_VS,
Resource::SHADERS_LITCOLORED_FS);
program->use();
program->setUniform("ForceAlpha", alpha);
renderGeometry(geometry, program);
}