本文整理汇总了C++中TriangleMesh::TriangleCount方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleMesh::TriangleCount方法的具体用法?C++ TriangleMesh::TriangleCount怎么用?C++ TriangleMesh::TriangleCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriangleMesh
的用法示例。
在下文中一共展示了TriangleMesh::TriangleCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DemoDisplay
//The main display function.
void DemoDisplay()
{
glDisable(GL_STENCIL_TEST);
//setup for rendering
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); //render to texture
glUseProgram(objectShaderProgram);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//set the vertex attributes to vertex position and normal vector
glBindVertexArray(objectVertexArray);
GLuint pos = glGetAttribLocation(objectShaderProgram, "position");
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, objectVertexBuffer);
glVertexAttribPointer(pos, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(1);
GLuint norm = glGetAttribLocation(objectShaderProgram, "normal");
glBindBuffer(GL_ARRAY_BUFFER, objectNormBuffer);
glVertexAttribPointer(norm, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
//element buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, objectElementBuffer);
glActiveTexture(GL_TEXTURE0);
//texture...
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(glGetUniformLocation(objectShaderProgram, "tex"), 0);
//camera
glm::vec3 eye(0, 0, -5);
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 1.0f, 20.0f);
// Camera matrix
glm::mat4 View = glm::lookAt(eye, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
// Transformations to perform on model
glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(20.0f, 20.0f, 20.0f));
glm::mat4 translate_z = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 2.0f));
glm::mat4 rotate_x = glm::rotate(glm::mat4(1.0f), x_angle, glm::vec3(1, 0, 0));
glm::mat4 rotate_y = glm::rotate(glm::mat4(1.0f), y_angle, glm::vec3(0, 1, 0));
glm::mat4 Model = rotate_x * rotate_y * translate_z * scale;
//construct data to send to vertex shader
glm::mat4 MN = glm::transpose(glm::inverse(Model));
glm::vec4 lightPos(5, 5, -5, 1);
glm::vec4 eyePos(eye, 1);
//find locations of shader program variables
GLuint SM = glGetUniformLocation(objectShaderProgram, "model");
GLuint SMN = glGetUniformLocation(objectShaderProgram, "normTrans");
GLuint SMV = glGetUniformLocation(objectShaderProgram, "view");
GLuint SMVP = glGetUniformLocation(objectShaderProgram, "proj");
GLuint SEyePos = glGetUniformLocation(objectShaderProgram, "eyePos");
GLuint SLightPos = glGetUniformLocation(objectShaderProgram, "lightPos");
//transfer data to shader program
glUniformMatrix4fv(SM, 1, GL_FALSE, &Model[0][0]);
glUniformMatrix4fv(SMN, 1, GL_FALSE, &MN[0][0]);
glUniformMatrix4fv(SMV, 1, GL_FALSE, &View[0][0]);
glUniformMatrix4fv(SMVP, 1, GL_FALSE, &Projection[0][0]);
glUniform4fv(SLightPos, 1, &lightPos[0]);
glUniform4fv(SEyePos, 1, &eyePos[0]);
//draw the elements (triangles)
glDrawElements(GL_TRIANGLES, 3 * geom.TriangleCount(), GL_UNSIGNED_INT, (void*)0);
//render postprocesseing
glBindFramebuffer(GL_FRAMEBUFFER, 0); //render to screen
glUseProgram(screenShaderProgram);
//no depth testing necessary
glDisable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//gives us access to two textures, the colour and the depth (z-buffer) information
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, renderTarget);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, depthStencil);
//bind the colour and depth textures to locations in the shader program
glUniform1i(glGetUniformLocation(screenShaderProgram, "tex"), 0);
glUniform1i(glGetUniformLocation(screenShaderProgram, "depth"), 1);
//set the vertex attributes to vertex position and normal vector
glBindVertexArray(screenVertexArray);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, screenVertexBuffer);
GLuint posS = glGetAttribLocation(screenShaderProgram, "position");
glVertexAttribPointer(posS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, screenElementBuffer);
glDrawElements(GL_TRIANGLES, 3 * 2, GL_UNSIGNED_INT, (void*)0);
//rotate object
x_angle = x_angle + 0.01;
y_angle = y_angle + 0.0052;
}