本文整理汇总了C++中GLSLProgram::setUniform方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::setUniform方法的具体用法?C++ GLSLProgram::setUniform怎么用?C++ GLSLProgram::setUniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::setUniform方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setMatrices
void setMatrices()
{
mat4 mv = view * model;
prog.setUniform("ModelViewMatrix", mv);
prog.setUniform("NormalMatrix",
mat3( vec3(mv[0]), vec3(mv[1]), vec3(mv[2]) ));
prog.setUniform("MVP", projection * mv);
}
示例2: useMaterial
void PlaneModelData::useMaterial(GLSLProgram const& prog) const
{
prog.setUniform("material.ambient", *reinterpret_cast<glm::vec3 const*>(material.ambient));
prog.setUniform("material.diffuse", *reinterpret_cast<glm::vec3 const*>(material.diffuse));
prog.setUniform("material.specular", *reinterpret_cast<glm::vec3 const*>(material.specular));
prog.setUniform("material.shininess", material.shininess);
glActiveTexture(GL_TEXTURE0 + 5);
glBindTexture(GL_TEXTURE_2D, (GLuint) material.texture1_map.user_ptr);
}
示例3: RenderScene
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mat4 mv = view * model;
prog.setUniform("ModelViewMatrix", mv);
prog.setUniform("NormalMatrix", mat3( vec3(mv[0]), vec3(mv[1]), vec3(mv[2]) ));
prog.setUniform("MVP", projection * mv);
current->render();
}
示例4: drawInstances
void PlaneModelData::drawInstances(GLSLProgram const& prog) const
{
glBindVertexArray(modelVAO);
useMaterial(prog);
BOOST_FOREACH(DrawInstance const& inst, drawInst)
{
prog.setUniform("modelMatrix", inst.modelMatrix);
prog.setUniform("tint", inst.tint);
glDrawElements(GL_TRIANGLE_STRIP, NUM_INDICES, GL_UNSIGNED_BYTE, NULL);
}
示例5: customInit
void OgroInvasion::customInit()
{
filename = g_programName + "/" + "Lenna.png";
try
{
glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "shader.vert");
glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "shader.frag");
}
catch (GLSLProgramException& e)
{
printf("%s\n", e.what());
system("pause");
exit(EXIT_FAILURE);
}
glslProgram.link();
GLint vertexAttribLoc = glslProgram.getAttributeLocation("vVertex");
//quad vertices and indices
glm::vec2 vertices[4];
GLushort indices[6];
vertices[0] = glm::vec2(0.0f, 0.0f);
vertices[1] = glm::vec2(1.0f, 0.0f);
vertices[2] = glm::vec2(1.0f, 1.0f);
vertices[3] = glm::vec2(0.0f, 1.0f);
GLushort* id = indices;
*id++ = 0;
*id++ = 1;
*id++ = 2;
*id++ = 0;
*id++ = 2;
*id++ = 3;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(vertexAttribLoc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vertexAttribLoc);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
mTexture = new Texture(filename);
mTexture->load();
mTexture->activateTexture(0); // GL_TEXTURE0
glslProgram.setUniform("textureMap", 0); // GL_TEXTURE0
}
示例6: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
prog.compileShaderFromFile("phong.vert", GLSLShader::VERTEX);
prog.compileShaderFromFile("phong.frag", GLSLShader::FRAGMENT);
prog.link();
prog.use();
glEnable(GL_DEPTH_TEST);
teapot = new VBOTeapot(13, mat4(1.0f));
//torus = new VBOTorus(0.7f, 0.3f, 50, 50);
torus = new VBOTorus(1.75f, 0.75f, 50, 50);
current = teapot;
model = mat4(1.0f);
model *= glm::translate(vec3(0.0f,0.0f,0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
view = glm::lookAt(vec3(0.0f,3.0f,5.0f), vec3(0.0f,0.75f,0.0f), vec3(0.0f,1.0f,0.0f));
vec4 worldLight = vec4(5.0f,5.0f,2.0f,1.0f);
prog.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f);
prog.setUniform("Light.Position", view * worldLight );
prog.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f);
prog.setUniform("Light.La", 0.4f, 0.4f, 0.4f);
prog.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f);
prog.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例7: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
glEnable(GL_DEPTH_TEST);
prog.compileShaderFromFile("texture.vs", GLSLShader::VERTEX);
prog.compileShaderFromFile("texture.fs", GLSLShader::FRAGMENT);
prog.link();
prog.use();
cube = new VBOCube();
glActiveTexture(GL_TEXTURE0);
GLuint tex_2d = SOIL_load_OGL_texture("brick1.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y);
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
prog.setUniform("Tex1", 0);
view = glm::lookAt(vec3(1.0f,1.25f,1.25f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f));
projection = mat4(1.0f);
prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f) );
prog.setUniform("Light.Intensity", vec3(1.0f,1.0f,1.0f) );
prog.setUniform("Material.Kd", 0.9f, 0.9f, 0.9f);
prog.setUniform("Material.Ks", 0.95f, 0.95f, 0.95f);
prog.setUniform("Material.Ka", 0.1f, 0.1f, 0.1f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例8: drawInstances
void BlockModelData::drawInstances(GLSLProgram const& prog, Frustum const& cullFrustum) const
{
glBindVertexArray(modelVAO);
useMaterial(prog);
BOOST_FOREACH(DrawInstance const& inst, drawInst)
{
if (OrientedBoundingBox(boundingBox, inst.modelMatrix).frustumIntersect(cullFrustum) == IntersectionResult::OUTSIDE)
{
continue;
}
prog.setUniform("modelMatrix", inst.modelMatrix);
prog.setUniform("tint", inst.tint);
glDrawElements(GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_BYTE, NULL);
}
glBindVertexArray(0);
}
示例9: RenderScene
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Time Based animation
static CStopWatch rotTimer;
float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
//model = glm::rotate(mat4(1.0f), yRot, vec3(0.0f, 1.0f, 0.0f));
model = mat4(1.0f);
model *= glm::rotate(-35.0f, vec3(1.0f,0.0f,0.0f));
model *= glm::rotate(yRot, vec3(0.0f, 1.0f, 0.0f));
mat4 mv = view * model;
prog.setUniform("ModelViewMatrix", mv);
prog.setUniform("NormalMatrix", mat3( vec3(mv[0]), vec3(mv[1]), vec3(mv[2]) ));
prog.setUniform("MVP", projection * mv);
torus->render();
}
示例10: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
prog.compileShaderFromFile("subroutine.vert", GLSLShader::VERTEX);
prog.compileShaderFromFile("subroutine.frag", GLSLShader::FRAGMENT);
prog.link();
prog.use();
glEnable(GL_DEPTH_TEST);
plane = new VBOPlane(50.0f, 50.0f, 1, 1);
teapot = new VBOTeapot(14, mat4(1.0f));
view = glm::lookAt(vec3(0.0f,0.0f,10.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f));
prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f));
prog.setUniform("Light.La", 0.4f, 0.4f, 0.4f);
prog.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f);
prog.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f);
prog.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f);
prog.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例11: renderPlane
void renderPlane(const struct aiNode *nd)
{
aiMatrix4x4 m = nd->mTransformation;
m.Transpose();
GLfloat aux[16];
memcpy(aux, &m, sizeof(GLfloat) * 16);
mat4 matrix = mstack.top() * glm::make_mat4(aux);
mstack.push(matrix);
for (GLuint n = 0; n < nd->mNumMeshes; ++n) {
GLuint index = nd->mMeshes[n];
const aiMesh* mesh = scene->mMeshes[index];
d_program.setUniform("ModelView", mstack.top());
d_program.setUniform("Projection", pstack.top());
d_program.setUniform("MVP", pstack.top() * mstack.top());
d_program.setUniform("NormalMatrix",
glm::inverseTranspose(mat3(mstack.top()) * mat3(g_modelview)));
if (mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) {
glBindVertexArray(vaos[index]);
glDrawElements(GL_TRIANGLES, index_count[index], GL_UNSIGNED_INT, 0);
}
else if (mesh->mPrimitiveTypes == aiPrimitiveType_POINT) {
glBindVertexArray(vaos[index]);
glDrawElements(GL_POINTS, index_count[index], GL_UNSIGNED_INT, 0);
}
else if (mesh->mPrimitiveTypes == aiPrimitiveType_LINE) {
glBindVertexArray(vaos[index]);
glDrawElements(GL_LINES, index_count[index], GL_UNSIGNED_INT, 0);
}
}
for (GLuint n = 0; n < nd->mNumChildren; ++n)
renderPlane(nd->mChildren[n]);
mstack.pop();
}
示例12: renderFn
void renderFn()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
g_program.use();
setPerspective();
glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_2D, omap2);
g_program.setUniform("MaxTessLevel", max_tess);
g_program.setUniform("ModelView", g_modelview);
g_program.setUniform("Projection", g_projection);
g_program.setUniform("MVP", g_projection * g_modelview);
g_program.setUniform("NormalMatrix",
glm::inverseTranspose(mat3(g_modelview)));
g_program.setUniform("MousePosition", mouse);
g_program.setUniform("Time", elapsed);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderLand();
d_program.use();
glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &plv);
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &plf);
glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_2D, plane);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
renderPlane(scene->mRootNode);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
d_program.setUniform("FrameTime", clockdiff);
d_program.setUniform("Elapsed", elapsed);
glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &pav);
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &paf);
renderParticles();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
}
示例13: main
//.........这里部分代码省略.........
glClearColor(0.0f,0.0f,0.0f,0.0f);
const float clearColorWhite = 1.0f;
const float clearColorBlack = 0.0f;
// Sampler
GLuint sampler = 0;
glGenSamplers(1, &sampler);
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
check_gl_error();
// Render Loop
while(!window->shouldClose())
{
//glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// Update camera
camera->camControll(window->getWindowHandle());
camera->update();
// Update shader uniforms
model->getCurrentGLSLProgram()->use();
model->getCurrentGLSLProgram()->setUniform("lightPosition", camera->getCamPos());
model->getCurrentGLSLProgram()->setUniform("camPosition", camera->getCamPos());
model->getCurrentGLSLProgram()->setUniform("viewMatrix", camera->getVMatrix());
model->getCurrentGLSLProgram()->setUniform("normalMatrix", camera->getTranspInvMVMatrix()); // Change this!
model->getCurrentGLSLProgram()->setUniform("VPMatrix", camera->getVPMatrix());
opaqueFrameBuffer->clean();
opaqueFrameBuffer->bind();
opaqueFrameBuffer->bindForRenderPass(activeColorAttachmentsOpaque);
model->renderOpaque();
//quad4->render();
//quad5->render();
//opaqueFrameBuffer->unbind();
//// Blitting the opaque scene depth to propperly depth test the transparen against it.
//opaqueFrameBuffer->bindForReading();
//accumFrameBuffer->bindForWriting();
//glBlitFramebuffer(0, 0, window->getWindowWidth(), window->getWindowHeight(), 0, 0, window->getWindowWidth(), window->getWindowHeight(),
// GL_DEPTH_BUFFER_BIT, GL_NEAREST);
//opaqueFrameBuffer->unbind();
//_______________________________________________________________________________________________________________________________________________________________________________
// Acuumulation pass
accumTransparencyRevealageShader->use();
accumTransparencyRevealageShader->setUniform("VPMatrix", camera->getVPMatrix());
model->setGLSLProgram(accumTransparencyRevealageShader);
quad1->setGLSLProgram(*accumTransparencyRevealageShader);
quad2->setGLSLProgram(*accumTransparencyRevealageShader);
示例14: loadAssets
void loadAssets()
{
loadParticles();
loadPlane();
pstack.push(glm::perspective(45.0f,
(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f));
mstack.push(glm::lookAt(vec3(0, 2.7, 7), vec3(0, 2.4, 6), vec3(0, 1, 0)));
// Load terrain shader
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-tc.glsl",
GLSLShader::TESS_CONTROL)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-te.glsl",
GLSLShader::TESS_EVALUATION)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.link()) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
// Load plane shader
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
const char *outputNames[] = { "Position" };
glTransformFeedbackVaryings(d_program.getHandle(), 1, outputNames, GL_SEPARATE_ATTRIBS);
if (!d_program.link()) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
g_program.use();
g_program.setUniform("Viewport", viewport);
g_program.setUniform("MinTessLevel", 1.0f);
g_program.setUniform("MaxTessLevel", max_tess);
//g_program.setUniform("MaxTessLevel", 20.0f);
g_program.setUniform("NearClip", 0.1f);
g_program.setUniform("FarClip", 175.0f);
g_program.setUniform("NearFog", 10.0f);
g_program.setUniform("FarFog", 125.0f);
g_program.setUniform("Light0.position", vec3(L0POSITION));
g_program.setUniform("Light0.La", vec3(L0AMBIENT));
g_program.setUniform("Light0.Ld", vec3(L0DIFFUSE));
GLuint terrainmap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "heightmap-vlarge.png",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint watermap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "watermap.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex1 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "grass.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex2 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "stonesnow.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex3 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "water.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
//.........这里部分代码省略.........