void RenderWorld() { glEnable(GL_LIGHTING); txrGround.BindTexture(); mtrGround.Apply(); glBegin(GL_QUADS); glNormal3f(0.0,1.0,0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-700.0, -20, 700.0); glTexCoord2f(0.0, 1.0); glVertex3f(700.0, -20, 700.0); glTexCoord2f(1.0, 1.0); glVertex3f(700.0, -20, -700.0); glTexCoord2f(1.0, 0.0); glVertex3f(-700.0, -20, -700.0); glEnd(); txrGround.UnBindTexture(); /* glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); GLUquadricObj *obj; obj = gluNewQuadric(); gluQuadricDrawStyle( obj, GLU_FILL ); gluQuadricOrientation( obj, GLU_OUTSIDE ); gluQuadricTexture( obj, GL_TRUE ); gluQuadricNormals( obj, GLU_SMOOTH ); gluSphere(obj,800,360,180); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); */ glPushMatrix(); glRotatef(90,1,0,0); glScalef(800,800,800); txrSky.BindTexture(); mtrSpace.Apply(); glCallList(SphereList); txrSky.UnBindTexture(); glPopMatrix(); DrawEarth(); DrawMoon(); }
bool RenderManager::DrawMesh(int meshID) { Mesh* m = Mesh::GetMeshPointer(meshID); if (m != NULL) { Material mat = m->GetMaterial(); UniformLocations uniforms = mat.GetUniforms(); mat.Apply(); // Build the modelview matrix for the mesh GameObject* g = m->GetParentPointer(); BuildModelViewMatrix(*g); // Find the uniform locations for this program and put relevant data into said locations SetUniforms(uniforms); // Bind the VAO and draw the array glBindVertexArray(VAOMap[meshID]); glDrawElements(GL_TRIANGLES, m->GetNumberOfVerts(), GL_UNSIGNED_INT, (void*)0); // unbind our shaders and arrays glBindVertexArray(0); glUseProgram(0); return true; } else { // If the mesh pointer is NULL then retrun false so we know to remove it from the renderlist return false; } }
void Render::DrawAtoms(D3DMATRIX* view, D3DMATRIX* projection) { // Apply the technique contained in the effect BYTE previousRenderedMaterial = 255; for(int iAtom = 0; iAtom < atomCount; iAtom++) { Atom* currentAtom = &atoms[iAtom]; Material* material = elementMaterials + currentAtom->Material; // Scale & translate the sphere D3DXMATRIX world = D3DMATRIXCREATE( currentAtom->Radius,0,0,0, 0,currentAtom->Radius,0,0, 0,0,currentAtom->Radius,0, currentAtom->Position.x,currentAtom->Position.y,currentAtom->Position.z,1.0f); material->SetMatrices(&world, view, projection); // Setup material's parameters if (previousRenderedMaterial != currentAtom->Material) { // Skip if the params has been already presented previousRenderedMaterial = currentAtom->Material; material->Apply(); } // Render the mesh with the applied technique highPolySphere->Draw(); } }
void Render::DrawBonds(D3DMATRIX* view, D3DMATRIX* projection) { // Apply the technique contained in the effect BYTE previousRenderedMaterial = 255; if (bondRenderOptions.UseSingleMaterial) { bondRenderOptions.Material.Apply(); } for(int iBond = 0; iBond < bondCount; iBond++) { Bond* currentBond = &bonds[iBond]; Material* material = bondRenderOptions.UseSingleMaterial ? &bondRenderOptions.Material : elementMaterials + currentBond->Material; // Transform along to direction D3DVECTOR direction; direction.x = currentBond->End.x - currentBond->Begin.x; direction.y = currentBond->End.y - currentBond->Begin.y; direction.z = currentBond->End.z - currentBond->Begin.z; float height = GetLength(direction); //Normalize(direction); D3DMATRIX alongTo = TransformAlongTo(direction); // Scale D3DXMATRIX scale = D3DMATRIXCREATE( bondRenderOptions.BondSize,0,0,0, 0,1,0,0, 0,0,bondRenderOptions.BondSize,0, 0,0,0,1.0f); // Translate the cylinder D3DXMATRIX translate = D3DMATRIXCREATE( 1.0f,0,0,0, 0,1.0f,0,0, 0,0,1.0f,0, currentBond->Begin.x,currentBond->Begin.y,currentBond->Begin.z,1.0f); D3DXMATRIX world = Multiply(Multiply(scale, alongTo), translate); material->SetMatrices(&world, view, projection); // Setup material's parameters if (!bondRenderOptions.UseSingleMaterial && previousRenderedMaterial != currentBond->Material) { // Skip if the params has been already presented previousRenderedMaterial = currentBond->Material; material->Apply(); } // Render the mesh with the applied technique highPolyCylinder->Draw(); } }
void DrawMoon() { static float fAngle = 0.0; glPushMatrix(); glRotatef(fAngle,0,1,0); glTranslatef(0,200,300); glScalef(20,20,20); txrMoon.BindTexture(); mtrMoon.Apply(); glCallList(SphereList); txrMoon.UnBindTexture(); glPopMatrix(); fAngle += 0.8; }
void DrawEarth() { static float fAngle = 0; glPushMatrix(); glTranslatef(0,200,300); glRotatef(fAngle,0,-1,0); glScalef(70,70,70); txrEarth.BindTexture(); mtrEarth.Apply(); glCallList(SphereList); txrEarth.UnBindTexture(); glPopMatrix(); fAngle+=0.5; }
void RenderManager::DrawTerrain() { float xmul = 0; float ymul = 0; Vector2 b = terrainManager->GetBase(0, 0); Vector2 b2 = terrainManager->GetBase(1, 1); float dif = b.u - b2.u; for (int i = 0; i < terrainManager->GetSize(); i++) { for (int j = 0; j < terrainManager->GetSize(); j++) { Material mat = terrainManager->GetMaterial(i, j); UniformLocations uniforms = mat.GetUniforms(); mat.Apply(); xmul = terrainManager->GetBase(i, j).u; ymul = terrainManager->GetBase(i, j).v; GameObject base; base.SetLocation(xmul, 0.0f, ymul); // Build the modelview matrix for the mesh BuildModelViewMatrix(base); // Find the uniform locations for this program and put relevant data into said locations SetUniforms(uniforms); glUniform1f(uniforms.XMulFactor, xmul); glUniform1f(uniforms.YMulFactor, ymul); // Bind the VAO and draw the array glBindVertexArray(terrain); glPatchParameteri(GL_PATCH_VERTICES, 3); glDrawElements(GL_PATCHES, terrainManager->GetTerrainMesh().GetIndexLength(), GL_UNSIGNED_INT, (void*)0); // unbind our shaders and arrays glBindVertexArray(0); glUseProgram(0); } } }
void Render::DrawResidues(D3DMATRIX* view, D3DMATRIX* projection) { // Apply the technique contained in the effect BYTE previousRenderedMaterial = 255; if (residueMaterials == NULL || residues == NULL) return; if (residuesMeshes == NULL) { residuesMeshesCount = residuesCount; residuesMeshes = new Mesh*[residuesCount]; for (int i = 0; i < residuesMeshesCount; i++) { Mesh* mesh = new Mesh(); mesh->Set(residues[i].VerticesPointer, residues[i].VerticesCount, residues[i].IndicesPointer, residues[i].IndicesCount); residuesMeshes[i] = mesh; } } // Scale & translate the sphere D3DXMATRIX world = D3DMATRIXCREATE( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1.0f); residueMaterials[0].SetMatrices(&world, view, projection); for(int i = 0; i < residuesCount; i++) { Residue* currentResidue = &residues[i]; Material* material = residueMaterials + currentResidue->Material; // Setup material's parameters if (previousRenderedMaterial != currentResidue->Material) { // Skip if the params has been already presented previousRenderedMaterial = currentResidue->Material; material->Apply(); } // Render the mesh with the applied technique residuesMeshes[i]->Draw(); } }
void RenderManager::DrawSkyBox() { Mesh* m = Mesh::GetMeshPointer(sky); Material mat = m->GetMaterial(); UniformLocations uniforms = mat.GetUniforms(); mat.Apply(); // Build the modelview matrix for the mesh BuildSkyBoxViewMatrix(*activeCamera->GetParent()); // Find the uniform locations for this program and put relevant data into said locations SetUniforms(uniforms); // Bind the VAO and draw the array glBindVertexArray(skyBox); glDisable(GL_DEPTH_TEST); glDrawElements(GL_TRIANGLES, m->GetNumberOfVerts(), GL_UNSIGNED_INT, (void*)0); glEnable(GL_DEPTH_TEST); // unbind our shaders and arrays glBindVertexArray(0); glUseProgram(0); }
AEResult GameLightsUpdate::ShadowLightRenderGameObject(GameObject* gameObject, const glm::mat4& lightView, const glm::mat4& lightProj) { AEAssert(gameObject != nullptr); if (gameObject == nullptr) { return AEResult::NullParameter; } if (gameObject->HasMeshGOC() && gameObject->HasMaterialGOCs()) { Mesh* mesh = gameObject->GetMeshGOC()->GetMeshResource(); if (mesh != nullptr) { ConstantBuffer* cb = nullptr; Material* mat = nullptr; bool hasAnimation = gameObject->HasMeshAnimationGOC(); if (hasAnimation) { mat = m_VarianceSkinningShadowMaterial; ShaderProperties* vsProps = m_VarianceSkinningShadowMaterial->GetVSProps(); cb = vsProps->GetConstantBuffer(AE_CB_WORLD_VIEW_PROJ_NAME); ConstantBuffer* cbBones = vsProps->GetConstantBuffer(AE_CB_BONES_NAME); if (cbBones != nullptr) { AnimationPlayer* player = gameObject->GetMeshAnimationGOC()->GetAnimationPlayer(); cbBones->SetValue(AE_CB_BONE_TRANSFORMS_VAR_NAME, player->GetBoneTransforms(), sizeof(glm::mat4) * AE_MAX_BONES); } } else { mat = m_VarianceShadowMaterial; ShaderProperties* vsProps = m_VarianceShadowMaterial->GetVSProps(); cb = vsProps->GetConstantBuffer(AE_CB_WORLD_VIEW_PROJ_NAME); } cb->SetValueT<glm::mat4>(AE_CB_WORLD_VAR_NAME, gameObject->GetWorldTransform()); cb->SetValueT<glm::mat4>(AE_CB_VIEW_VAR_NAME, lightView); cb->SetValueT<glm::mat4>(AE_CB_PROJECTION_VAR_NAME, lightProj); AETODO("check return"); mat->Apply(); for (uint32_t i = 0; i < mesh->GetNumberMeshParts(); i++) { MeshPart* meshPart = mesh->GetMeshPart(i); m_GraphicDevice->SetVertexBuffer(meshPart->GetVertexBuffer()); m_GraphicDevice->SetIndexBuffer(meshPart->GetIndexBuffer()); m_GraphicDevice->SetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_GraphicDevice->DrawIndexed(0, 0, meshPart->GetIndexBuffer()->GetSize()); } AETODO("check return"); mat->UnApply(); } } for (auto goIt : *gameObject) { ShadowLightRenderGameObject(goIt.second, lightView, lightProj); } return AEResult::Ok; }