本文整理汇总了C++中GLSLShader类的典型用法代码示例。如果您正苦于以下问题:C++ GLSLShader类的具体用法?C++ GLSLShader怎么用?C++ GLSLShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GLSLShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawScene
//function to render scene given the combined modelview projection matrix
//and a shader
void DrawScene(const glm::mat4& MVP, GLSLShader& shader) {
//enable alpha blending with over compositing
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//bind the cube vertex array object
glBindVertexArray(cubeVAOID);
//bind the shader
shader.Use();
//for all cubes
for(int k=-1;k<=1;k++) {
for(int j=-1;j<=1;j++) {
int index =0;
for(int i=-1;i<=1;i++) {
GL_CHECK_ERRORS
//set the modelling transformation and shader uniforms
glm::mat4 T = glm::translate(glm::mat4(1), glm::vec3(i*2,j*2,k*2));
glUniform4fv(shader("vColor"),1, &(box_colors[index++].x));
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP*R*T));
//draw the cube
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
GL_CHECK_ERRORS
}
}
}
//unbind shader
shader.UnUse();
//unbind vertex array object
glBindVertexArray(0);
}
示例2: getGeometryShader
void GLSLProgram::setTransformFeedbackVaryings(const std::vector<String>& nameStrings)
{
// Get program object ID.
GLuint programId;
if (Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
{
//TODO include tessellation stages
GLSLShader* glslGpuProgram = getGeometryShader();
if (!glslGpuProgram)
glslGpuProgram = getVertexShader();
programId = glslGpuProgram->getGLProgramHandle();
// force re-link
GpuProgramManager::getSingleton().removeMicrocodeFromCache(glslGpuProgram->_getHash());
glslGpuProgram->setLinked(false);
}
else
{
programId = getGLProgramHandle();
// force re-link
GpuProgramManager::getSingleton().removeMicrocodeFromCache(getCombinedHash());
}
mLinked = false;
// Convert to const char * for GL
std::vector<const char*> names;
for (uint e = 0; e < nameStrings.size(); e++)
{
names.push_back(nameStrings[e].c_str());
}
// TODO replace glTransformFeedbackVaryings with in-shader specification (GL 4.4)
OGRE_CHECK_GL_ERROR(glTransformFeedbackVaryings(programId, nameStrings.size(), &names[0],
GL_INTERLEAVED_ATTRIBS));
#if OGRE_DEBUG_MODE
activate();
// Check if varyings were successfully set.
GLchar Name[64];
GLsizei Length(0);
GLsizei Size(0);
GLenum Type(0);
// bool Validated = false;
for (size_t i = 0; i < nameStrings.size(); i++)
{
OGRE_CHECK_GL_ERROR(
glGetTransformFeedbackVarying(programId, i, 64, &Length, &Size, &Type, Name));
LogManager::getSingleton().stream() << "Varying " << i << ": " << Name << " " << Length
<< " " << Size << " " << Type;
// Validated = (Size == 1) && (Type == GL_FLOAT_VEC3);
// std::cout << Validated << " " << GL_FLOAT_VEC3 << std::endl;
}
#endif
}
示例3: String
Shader *GLSLShaderModule::createShader(TiXmlNode *node) {
TiXmlNode* pChild, *pChild2, *pChild3;
GLSLProgram *vp = NULL;
GLSLProgram *fp = NULL;
GLSLShader *retShader = NULL;
for (pChild = node->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
if(strcmp(pChild->Value(), "vp") == 0) {
vp = (GLSLProgram*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_PROGRAM, String(pChild->ToElement()->Attribute("source")));
if(vp) {
for (pChild2 = pChild->FirstChild(); pChild2 != 0; pChild2 = pChild2->NextSibling()) {
if(strcmp(pChild2->Value(), "params") == 0) {
for (pChild3 = pChild2->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
if(strcmp(pChild3->Value(), "param") == 0) {
addParamToProgram(vp,pChild3);
}
}
}
}
}
}
if(strcmp(pChild->Value(), "fp") == 0) {
fp = (GLSLProgram*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_PROGRAM, String(pChild->ToElement()->Attribute("source")));
if(fp) {
for (pChild2 = pChild->FirstChild(); pChild2 != 0; pChild2 = pChild2->NextSibling()) {
if(strcmp(pChild2->Value(), "params") == 0) {
for (pChild3 = pChild2->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
if(strcmp(pChild3->Value(), "param") == 0) {
addParamToProgram(fp,pChild3);
}
}
}
}
}
}
}
if(vp != NULL && fp != NULL) {
GLSLShader *cgShader = new GLSLShader(vp,fp);
cgShader->setName(String(node->ToElement()->Attribute("name")));
retShader = cgShader;
shaders.push_back((Shader*)cgShader);
}
return retShader;
}
示例4: display
// display texture
// XXX: NEEDS TO BE IMPLEMENTED
void Texture::display(void){
// setup model matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(rayTraceMode){
normQuadShader.bind();
rayTexture.bind();
quad.draw();
normQuadShader.unbind();
rayTexture.unbind();
}else{
mesh1.draw();
mesh.draw();
mesh2.draw();
}
glutSwapBuffers();
// glPopAttrib();
}
示例5: OnShutdown
//release all allocated resources here
void OnShutdown() {
//delete all textures
size_t total_textures = materialMap.size();
for(size_t i=0;i<total_textures;i++) {
if(materialNames[i].length()>0)
glDeleteTextures(1, &materialMap[materialNames[i]]);
}
materialNames.clear();
materialMap.clear();
submeshes.clear();
vertices.clear();
indices.clear();
skeleton.clear();
animations.clear();
dualQuaternions.clear();
animatedXform.clear();
skeleton.clear();
bindPose.clear();
invBindPose.clear();
//Destroy shader
shader.DeleteShaderProgram();
flatShader.DeleteShaderProgram();
//Destroy vao and vbo
glDeleteBuffers(1, &vboVerticesID);
glDeleteBuffers(1, &vboIndicesID);
glDeleteVertexArrays(1, &vaoID);
glDeleteVertexArrays(1, &lightVAOID);
glDeleteVertexArrays(1, &lightVerticesVBO);
cout<<"Shutdown successfull"<<endl;
}
示例6: OnShutdown
void OnShutdown() {
X.clear();
X_last.clear();
F.clear();
indices.clear();
springs.clear();
glDeleteQueries(1, &query);
glDeleteQueries(1, &t_query);
glDeleteTextures( 2, texPosID);
glDeleteTextures( 2, texPrePosID);
glDeleteVertexArrays(2, vaoUpdateID);
glDeleteVertexArrays(2, vaoRenderID);
glDeleteVertexArrays(1, &clothVAOID);
glDeleteVertexArrays(1, &gridVAOID);
glDeleteBuffers( 1, &gridVBOVerticesID);
glDeleteBuffers( 1, &gridVBOIndicesID);
glDeleteBuffers( 1, &clothVBOVerticesID);
glDeleteBuffers( 1, &clothVBOIndicesID);
glDeleteBuffers( 2, vboID_Pos);
glDeleteBuffers( 2, vboID_PrePos);
glDeleteBuffers( 1, &vboIndices);
glDeleteTransformFeedbacks(1, &tfID);
renderShader.DeleteProgram();
massSpringShader.DeleteProgram();
particleShader.DeleteProgram();
}
示例7: OnRender
//display callback
void OnRender() {
//get the elapse time
time = glutGet(GLUT_ELAPSED_TIME)/1000.0f * SPEED;
//clear the colour and depth buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//set teh camera viewing transformation
glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
glm::mat4 Rx = glm::rotate(T, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 MV = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 MVP = P*MV;
//bind the shader
shader.Use();
//set the shader uniforms
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniform1f(shader("time"), time);
//draw the mesh triangles
glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_SHORT, 0);
//unbind the shader
shader.UnUse();
//swap front and back buffers to show the rendered result
glutSwapBuffers();
}
示例8: OnRender
//display function
void OnRender() {
//clear colour and depth buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//set the camera transform
glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
glm::mat4 Rx = glm::rotate(T, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 Ry = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 MV = Ry;
glm::mat4 MVP = P*MV;
//since we have kept the terrain vertex array object bound
//it is still bound to the context so we can directly call draw element
//which will draw vertices from the bound vertex array object
//bind the terrain shader
shader.Use();
//pass shader uniforms
glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
//draw terrain mesh
glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_INT, 0);
//unbind shader
shader.UnUse();
//swap front and back buffers to show the rendered result
glutSwapBuffers();
}
示例9: OnShutdown
//release all allocated resources
void OnShutdown() {
glDeleteTextures(1, &shadowMapTexID);
//Destroy shader
shader.DeleteShaderProgram();
flatshader.DeleteShaderProgram();
//Destroy vao and vbo
glDeleteBuffers(1, &sphereVerticesVBO);
glDeleteBuffers(1, &sphereIndicesVBO);
glDeleteVertexArrays(1, &sphereVAOID);
glDeleteBuffers(1, &cubeVerticesVBO);
glDeleteBuffers(1, &cubeIndicesVBO);
glDeleteVertexArrays(1, &cubeVAOID);
glDeleteBuffers(1, &planeVerticesVBO);
glDeleteBuffers(1, &planeIndicesVBO);
glDeleteVertexArrays(1, &planeVAOID);
glDeleteVertexArrays(1, &lightVAOID);
glDeleteBuffers(1, &lightVerticesVBO);
glDeleteFramebuffers(1,&fboID);
cout<<"Shutdown successfull"<<endl;
}
示例10: DrawSphere
//renders sphere using the render shader
void DrawSphere(const glm::mat4& mvp) {
renderShader.Use();
glBindVertexArray(sphereVAOID);
glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawElements(GL_TRIANGLES, total_sphere_indices,GL_UNSIGNED_SHORT,0);
renderShader.UnUse();
}
示例11: DrawGrid
void DrawGrid()
{
renderShader.Use();
glBindVertexArray(gridVAOID);
glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));
glDrawElements(GL_LINES, grid_indices.size(),GL_UNSIGNED_SHORT,0);
glBindVertexArray(0);
renderShader.UnUse();
}
示例12: DrawCloth
void DrawCloth()
{
renderShader.Use();
glBindVertexArray(clothVAOID);
glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));
glDrawElements(GL_TRIANGLES, indices.size(),GL_UNSIGNED_SHORT,0);
//glBindVertexArray(0);
renderShader.UnUse();
}
示例13: onInit
void onInit() {
//tex = loadImage("../textures/texture.png");
tex = loadImage("../textures/dots.png");
tex2 = loadImage("../textures/dots.png");
ctv = new CTextureViewer(0, "../shaders/textureViewer.vs", "../shaders/textureViewer.frag");
ctv->setTexture(tex);
ctv->setTexture2(tex2);
hist.LoadFromFile(GL_VERTEX_SHADER, "../shaders/histogram.vs");
hist.LoadFromFile(GL_FRAGMENT_SHADER, "../shaders/histogram.frag");
hist.CreateAndLinkProgram();
hist.Use();
//Create uniforms and attributes (filled later)
hist.AddAttribute("vPosition");
hist.AddUniform("tex");
hist.AddUniform("textureWidth");
hist.AddUniform("textureHeight");
hist.UnUse();
initTex();
initPointVBO();
initHistogramFBO();
}
示例14: computeHistogram
void computeHistogram() {
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 0.0);
glDisable(GL_DEPTH_TEST);
//Enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
//Additive
glBlendEquation(GL_FUNC_ADD);
hist.Use();
glBindBuffer(GL_ARRAY_BUFFER, HistogramVBO);
glVertexAttribPointer(hist["vPosition"], 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GL_FLOAT), (void*)0);
glEnableVertexAttribArray(hist["vPosition"]);
glUniform1i(hist("tex"), 0);
glUniform1f(hist("textureWidth"), (float)WIDTH);
glUniform1f(hist("textureHeight"), (float)HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
//glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Compute histogram
glDrawArrays(GL_POINTS, 0, WIDTH*HEIGHT);
glBindBuffer(GL_ARRAY_BUFFER, 0);
hist.UnUse();
//Disable blending
glDisable(GL_BLEND);
float hPixels[256];
glReadPixels(0, 0, 256, 1, GL_BLUE, GL_FLOAT, hPixels);
int sum = 0;
if (printed != 0)
{
cout << "\n\n-----------\n\n";
for(int j = 0; j < 256; j++)
{
//if((j % 3) == 0)
cout << j << ":" << hPixels[j] << endl;
sum += hPixels[j];
}
cout << endl << sum << endl;
printed--;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
示例15: OnRender
//display callback function
void OnRender() {
GL_CHECK_ERRORS
//clear colour and depth buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//set the camera transform
glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
glm::mat4 Rx = glm::rotate(T, rX, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 MV = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
//1) Render scene from the light's POV
//enable rendering to FBO
glBindFramebuffer(GL_FRAMEBUFFER,fboID);
//clear depth buffer
glClear(GL_DEPTH_BUFFER_BIT);
//reset viewport to the shadow map texture size
glViewport(0,0,SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
//enable front face culling
glCullFace(GL_FRONT);
//draw scene from the point of view of light
DrawScene(MV_L, P_L);
//enable back face culling
glCullFace(GL_BACK);
//restore normal rendering path
//unbind FBO, set the default back buffer and reset the viewport to screen size
glBindFramebuffer(GL_FRAMEBUFFER,0);
glDrawBuffer(GL_BACK_LEFT);
glViewport(0,0,WIDTH, HEIGHT);
//2) Render scene from point of view of eye
DrawScene(MV, P, 0 );
//bind light gizmo vertex array object
glBindVertexArray(lightVAOID); {
//set the flat shader
flatshader.Use();
//set the light's transform and render 3 lines
glm::mat4 T = glm::translate(glm::mat4(1), lightPosOS);
glUniformMatrix4fv(flatshader("MVP"), 1, GL_FALSE, glm::value_ptr(P*MV*T));
glDrawArrays(GL_LINES, 0, 6);
//unbind shader
flatshader.UnUse();
}
//unbind the vertex array object
glBindVertexArray(0);
//swap front and back buffers to show the rendered result
glutSwapBuffers();
}