void Renderer::Render(const Camera& cam, IContext& c){ #if ZEUS_SAFE if (c.GetType() != IContext::OpenGL21) throw Exception("Context not supported by renderer: " + Utils::ToString<IContext::Type>(c.GetType())); #endif Context& glContext = (Context&)c; // Draw scene ApplyCamera(cam, c); glEnable(GL_CULL_FACE); // @TODO Setup light. Lightmaps 'n shit glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); Vector3 dir = Vector3(1,3,2); Normalize(dir); float hat[4]; dir.GetData(hat); hat[3] = 1.0f; glLightfv(GL_LIGHT0, GL_POSITION, hat); SceneObjectList::iterator itr = SceneObjectList::Begin(); while (itr != SceneObjectList::End()){ //Debug::Log("Rendering " + (*itr)->GetName()); const ModelComponent* m = (*itr)->GetComponent<ModelComponent>(); if (m){ //Debug::Log((*itr)->GetName() + " has mesh"); const ModelPropertiesPtr props = m->GetModelProperties(); if (props) { ModelProperties::Texture2DIterator itr = props->Texture2DBegin(); while (itr != props->Texture2DEnd()) { const GLTexture2D* tex = glContext.AddTexture(itr->second); glBindTexture(GL_TEXTURE_2D, tex->GetID()); glEnable(GL_TEXTURE_2D); ++itr; } } else { glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } const MeshPtr mesh = m->GetMesh(); if (mesh) { const Transformation* t = (*itr)->GetComponent<Transformation>(); glPushMatrix(); Matrix4x4 m = t->GetAccumulatedMatrix(); glMultMatrixf(m.GetData()); // @TODO Apply material const GLMesh* mInfo = glContext.AddMesh(mesh); RenderModel(*mInfo, glContext); glPopMatrix(); } } ++itr; } glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_CULL_FACE); }