void renderEnvironmentMap(int face) { // Always clear the frame buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cur_scene = scene1; currentMesh_vec = &meshes_1; // use the shader associated with the Cathedral (shader 0) int shaderNum = 0; for (int i = 0; i < currentMesh_vec->size(); i++) { glUseProgram(shaders[shaderNum]->programID()); environmentMatrixTransform(scene1, face); setMaterial(scene1, i, shaderNum); setTextures(i, shaderNum, true); setMeshData(i, shaderNum); // Draw the mesh if ((*currentMesh_vec)[i].mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) { glDrawElements(GL_TRIANGLES, 3*(*currentMesh_vec)[i].mesh->mNumFaces, GL_UNSIGNED_INT, &(*currentMesh_vec)[i].indexBuffer[0]); } } }
MeshComponent::MeshComponent(const std::string &meshFilePath, ResourceLoadingMode lm) : MeshComponent() { m_rmgrListener->m_guid = resources::CreateGUIDFromPath(meshFilePath); setMeshData(svc().resourceMgr.getFactory().createMeshData(meshFilePath, lm)); }
void renderFrame() { // Always clear the frame buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int shaderNum; // Cathedral scene (scene1, meshes_1, shader 0) cur_scene = scene1; currentMesh_vec = &meshes_1; shaderNum = 0; for (int i = 0; i < currentMesh_vec->size(); i++) { glUseProgram(shaders[shaderNum]->programID()); setMatrices(cur_scene); setMaterial(cur_scene, i, shaderNum); setTextures(i, shaderNum, false); setMeshData(i, shaderNum); // Draw the mesh if ((*currentMesh_vec)[i].mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) { glDrawElements(GL_TRIANGLES, 3*(*currentMesh_vec)[i].mesh->mNumFaces, GL_UNSIGNED_INT, &(*currentMesh_vec)[i].indexBuffer[0]); } } // Statue scene (scene2, meshes_2, shader 1) cur_scene = scene2; currentMesh_vec = &meshes_2; shaderNum = 1; for (int i = 0; i < currentMesh_vec->size(); i++) { glUseProgram(shaders[shaderNum]->programID()); setMatrices(cur_scene); setMaterial(cur_scene, i, shaderNum); setTextures(i, shaderNum, false); setMeshData(i, shaderNum); // Draw the mesh if ((*currentMesh_vec)[i].mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) { glDrawElements(GL_TRIANGLES, 3*(*currentMesh_vec)[i].mesh->mNumFaces, GL_UNSIGNED_INT, &(*currentMesh_vec)[i].indexBuffer[0]); } } }
std::shared_ptr<MeshRenderer> Scene::createPlane(GameObject *gameObject){ if (!gameObject) { gameObject = createGameObject("Plane"); } auto meshRenderer = gameObject->addComponent<MeshRenderer>(); auto mesh = make_shared<Mesh>(); mesh->setMeshData(MeshFactory::createPlaneData()); meshRenderer->setMesh(mesh); Material* mat = Project::createMaterial("assets/shaders/diffuse.shader"); meshRenderer->setMaterial(mat); return meshRenderer; }
MeshComponent::MeshComponent(shared_ptr<render::MeshData> meshData) : MeshComponent() { setMeshData(meshData); }
void renderNode(Shader *shader, aiScene const * scene, aiNode *node, bool doShadows) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); aiMatrix4x4 m = node->mTransformation; m = m.Transpose(); glMultMatrixf((float *)&m); if (shader == phongShader) { // store active texture to restore afterwards GLint activeTxtUnit; glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTxtUnit); glMatrixMode(GL_TEXTURE); glActiveTexture(GL_TEXTURE6); glPushMatrix(); glMultMatrixf((float *)&m); glActiveTexture(activeTxtUnit); } for (int i = 0; i < node->mNumMeshes; i++) { int meshIndex = node->mMeshes[i]; aiMesh *mesh = scene->mMeshes[meshIndex]; if (mesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE) continue; if (shader == phongShader) { setMaterial(scene, mesh); } if (shader != simpleShader) { setTextures(shader, scene, mesh); } setMeshData(mesh, shader); // Draw the mesh std::map<aiMesh *, std::vector<unsigned>*>::iterator itr = indexBuffers.find(mesh); if (itr != indexBuffers.end()) { std::vector<unsigned> indexBuffer = *itr->second; // Found an index buffer! Draw it glDrawElements(GL_TRIANGLES, 3*mesh->mNumFaces, GL_UNSIGNED_INT, &indexBuffer[0]); } } for (int i = 0; i < node->mNumChildren; i++) { aiNode *childNode = node->mChildren[i]; renderNode(shader, scene, childNode, doShadows); } if (shader == phongShader) { // store active texture to restore afterwards GLint activeTxtUnit; glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTxtUnit); glMatrixMode(GL_TEXTURE); glActiveTexture(GL_TEXTURE6); glPopMatrix(); glActiveTexture(activeTxtUnit); } glMatrixMode(GL_MODELVIEW); glPopMatrix(); }