本文整理汇总了C++中GLSLProgram::use方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::use方法的具体用法?C++ GLSLProgram::use怎么用?C++ GLSLProgram::use使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::use方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UseShader
GLSLProgram* ShaderManager::UseShader(const char* vertName, const char* fragName, std::string vertString, std::string fragString)
{
GLSLProgram* prog = GetShader(vertName, fragName,vertString, fragString);
assert(prog != NULL);
prog->use();
return prog;
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: init
void Renderer::init(GLSLProgram & shader)
{
setProjectionMatrix(30,1, 1, -100, projection);
shader.use();
shader.setUniformMatrix4fv("projectionMatrix", projection);
shader.unuse();
}
示例7: buildShadowMaps
void CascadedShadowMap::buildShadowMaps(Camera *camera, View *view, DirectLight *light)
{
//Profiler::getInstance()->startProfile("Build Shadow Maps");
float nSlice[] = {0.0, m_nSlices[0], m_nSlices[1], m_nSlices[2], 1.0};
Frustum *frustum = new Frustum();
frustum->getFrustum(camera, view);
m_shadowMaps[3]->bind();
glClearDepth(1.0);
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_CULL_FACE);
for (int i=0; i<4; i++)
{
Camera *lightCamera = createLightCamera(nSlice[i],nSlice[i+1],camera,view,light);
View *lightView = createLightView(nSlice[i],nSlice[i+1],camera,lightCamera,view,frustum);
Frustum *lightFrustum = new Frustum();
lightFrustum->getOrthoFrustum(lightCamera,lightView);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
m_shadowMaps[i]->bind();
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glPushAttrib( GL_VIEWPORT_BIT );
glViewport( 0, 0, m_nSize, m_nSize);
lightView->use3D(false);
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("DirectShadow");
glslProgram->use();
glm::mat4 cameraMat = glm::mat4(1.0f);
cameraMat = lightCamera->transformToMatrix(cameraMat);
m_m4LightMatrix[i] = MatrixManager::getInstance()->getMatrix4(PROJECTION) * cameraMat;
MatrixManager::getInstance()->putMatrix4(MODELVIEW, cameraMat);
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
SceneManager::getInstance()->draw("DirectShadow");
glslProgram->disable();
glPopAttrib();
m_shadowMaps[i]->unbind();
delete lightCamera;
delete lightView;
delete lightFrustum;
}
glEnable(GL_CULL_FACE);
//Profiler::getInstance()->endProfile();
}
示例8: onRender
void HelloGLSL::onRender()
{
glslProgram.use();
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glslProgram.unUse();
glBindVertexArray(0);
}
示例9: voxelRender
void MainGraphicsWidget::voxelRender()
{
VoxelGrid::getInstance()->buildVoxels(m_lightBuffer->getLight());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix3(NORMAL, glm::mat3(1.0f));
view->viewport();
view->use3D(true);
camera->transform();
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("Voxel");
glslProgram->use();
glBindFragDataLocation(glslProgram->getHandle(), 0, "fragColor");
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glslProgram->sendUniform("modelviewMatrix", &MatrixManager::getInstance()->getMatrix4(MODELVIEW)[0][0]);
glm::mat4 cameraInverse = glm::mat4(1.0);
cameraInverse = camera->transformToMatrix(cameraInverse);
cameraInverse = glm::inverse(cameraInverse);
glslProgram->sendUniform("invCameraMatrix", &cameraInverse[0][0]);
glslProgram->sendUniform("worldSize", WORLD_SIZE);
//glslProgram->sendUniform("numVoxels", VOXEL_SIZE);
//glslProgram->sendUniform("mipLevel", VoxelGrid::getInstance()->getMipLevel());
int mipFactor = pow(2.0, VoxelGrid::getInstance()->getMipLevel());
glActiveTexture(GL_TEXTURE8);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(VoxelGrid::getInstance()->getMipLevel());
glslProgram->sendUniform("voxelmap", 8);
//glEnable(GL_POINT_SMOOTH);
glPointSize(10.0f*mipFactor);
float voxelWidth = (float)WORLD_SIZE / (float)VOXEL_SIZE * mipFactor;
glBegin(GL_POINTS);
for (float x=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); x<(WORLD_SIZE/2.0); x+=voxelWidth)
{
for (float y=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); y<(WORLD_SIZE/2.0); y+=voxelWidth)
{
for (float z=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); z<(WORLD_SIZE/2.0); z+=voxelWidth)
{
glVertex3f(x,y,z);
}
}
}
glEnd();
glslProgram->disable();
}
示例10: onRender
void OgroInvasion::onRender()
{
glslProgram.use();
glBindVertexArray(vaoID);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
glBindVertexArray(0);
glslProgram.unUse();
}
示例11: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Black background
glClearColor(0.0f , 0.0f , 0.0f , 1.0f );
prog.compileShaderFromString (szIdentityShaderVP, GLSLShader:: VERTEX);
prog.compileShaderFromString (szIdentityShaderFP, GLSLShader:: FRAGMENT);
prog.link ();
prog.use ();
/////////////////// Create the VBO ////////////////////
GLfloat positionData [] = {
-0.8f, -0.8f , 0.0f ,
0.8f, -0.8f, 0.0f,
0.0f, 0.8f, 0.0f };
GLfloat colorData[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f };
// Create and populate the buffer objects
GLuint vboHandles[2];
glGenBuffers(2, vboHandles);
GLuint positionBufferHandle = vboHandles[0];
GLuint colorBufferHandle = vboHandles[1];
glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), positionData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), colorData, GL_STATIC_DRAW);
// Create and set-up the vertex array object
glGenVertexArrays( 1, &vaoHandle );
glBindVertexArray(vaoHandle);
glEnableVertexAttribArray(0); // Vertex position
glEnableVertexAttribArray(1); // Vertex color
glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
}
示例12: forwardRender
void MainGraphicsWidget::forwardRender()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix3(NORMAL, glm::mat3(1.0f));
view->viewport();
view->use3D(true);
camera->transform();
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("Basic");
glslProgram->use();
glBindFragDataLocation(glslProgram->getHandle(), 0, "fragColor");
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
glBindAttribLocation(glslProgram->getHandle(), 1, "v_texture");
glBindAttribLocation(glslProgram->getHandle(), 2, "v_normal");
glBindAttribLocation(glslProgram->getHandle(), 3, "v_tangent");
glBindAttribLocation(glslProgram->getHandle(), 4, "v_bitangent");
glslProgram->sendUniform("light.direction", 1.0f,-5.0f,2.0f);
glslProgram->sendUniform("light.color", 1.0f,1.0f,1.0f);
glslProgram->sendUniform("light.ambient", 0.7f);
glslProgram->sendUniform("light.diffuse", 0.6f);
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glslProgram->sendUniform("modelviewMatrix", &MatrixManager::getInstance()->getMatrix4(MODELVIEW)[0][0]);
glslProgram->sendUniform("curveGeometry", false);
glm::mat4 cameraInverse = glm::mat4(1.0);
cameraInverse = camera->transformToMatrix(cameraInverse);
cameraInverse = glm::inverse(cameraInverse);
glslProgram->sendUniform("inverseCameraMatrix", &cameraInverse[0][0]);
glslProgram->sendUniform("cameraPos", camera->getEyeX(), camera->getEyeY(), camera->getEyeZ());
MaterialManager::getInstance()->getMaterial("Default")->sendToShader("Basic");
myGrid->draw();
SceneManager::getInstance()->draw("Basic");
glslProgram->disable();
SceneManager::getInstance()->drawTransformers();
}
示例13: draw
void draw() {
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGenBuffers(1, &_vboID);
float vertexData[12];
float height = 1.0f;
float width = 1.0f;
float x = -1.0f;
float y = -1.0f;
//First Triangle
vertexData[0] = x + width;
vertexData[1] = y + height;
vertexData[2] = x;
vertexData[3] = y + height;
vertexData[4] = x;
vertexData[5] = y;
//Second Triangle
vertexData[6] = x;
vertexData[7] = y;
vertexData[8] = x + width;
vertexData[9] = y;
vertexData[10] = x + width;
vertexData[11] = y + height;
_Program.use();
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
_Program.unuse();
SDL_GL_SwapWindow(_window);
}
示例14: compile_link_shaders
int compile_link_shaders(GLSLProgram& prog, int num_shaders, ...)
{
va_list shader_list;
va_start(shader_list, num_shaders);
int type;
char *file= NULL;
GLSLProgram tmp_prog;
// Iterate over this argument list
for (int i=0; i<num_shaders; ++i) {
type = va_arg(shader_list, int);// Number of attributes
file = va_arg(shader_list, char*);
if (!tmp_prog.compile_shader_file(file, GLSLShader::GLSLShaderType(type)))
{
printf("%s shader failed to compile!\n%s", file, tmp_prog.log().c_str());
return 0;
}
}
va_end(shader_list);
if (!tmp_prog.link()) {
printf("Shader program failed to link!\n%s", tmp_prog.log().c_str());
return 0;
}
if (prog.isLinked())
prog.delete_program();
prog = tmp_prog;
prog.use();
return 1;
}
示例15: getVAOForContext
GLuint Model::getVAOForContext(GLSLProgram &shader, QGLContext *context){
if (!vaoHashContainer_.contains(context)) {
glGenVertexArrays(1, &vaoID_);
glBindVertexArray(vaoID_);
shader.use();
glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID_);
glEnableVertexAttribArray(shader["vVertex"]);
glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),0);
if (shader.isActive(shader["vNormal"])) {
glEnableVertexAttribArray(shader["vNormal"]);
glVertexAttribPointer(shader["vNormal"], 3, GL_FLOAT,
GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, normal)) );
}
if (shader.isActive(shader["vUV"])) {
glEnableVertexAttribArray(shader["vUV"]);
glVertexAttribPointer(shader["vUV"], 2, GL_FLOAT,
GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, uv)) );
}
if (materials_.size()==1)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID_);
glBindVertexArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
vaoHashContainer_.insert(context, vaoID_);
shader.unUse();
}
return vaoHashContainer_[context];
}