diff --git a/KREngine/KREngine/Classes/KRNode.cpp b/KREngine/KREngine/Classes/KRNode.cpp index 38c9bb2..397b9e9 100644 --- a/KREngine/KREngine/Classes/KRNode.cpp +++ b/KREngine/KREngine/Classes/KRNode.cpp @@ -14,6 +14,7 @@ #import "KRSpotLight.h" #import "KRDirectionalLight.h" #import "KRInstance.h" +#import "KRSkyBox.h" KRNode::KRNode(KRContext &context, std::string name) : KRContextObject(context) @@ -142,7 +143,8 @@ KRNode *KRNode::LoadXML(KRContext &context, tinyxml2::XMLElement *e) { new_node = new KRSpotLight(context, szName); } else if(strcmp(szElementName, "mesh") == 0) { new_node = new KRInstance(context, szName, szName, KRMat4(), e->Attribute("light_map")); - + } else if(strcmp(szElementName, "sky_box") == 0) { + new_node = new KRSkyBox(context, szName); } if(new_node) { diff --git a/KREngine/KREngine/Classes/KRSkyBox.cpp b/KREngine/KREngine/Classes/KRSkyBox.cpp index b8a1a38..bbd5fb8 100644 --- a/KREngine/KREngine/Classes/KRSkyBox.cpp +++ b/KREngine/KREngine/Classes/KRSkyBox.cpp @@ -16,6 +16,19 @@ KRSkyBox::KRSkyBox(KRContext &context, std::string name) : KRNode(context, name) { + m_frontTexture = ""; + m_backTexture = ""; + m_topTexture = ""; + m_bottomTexture = ""; + m_leftTexture = ""; + m_rightTexture = ""; + + m_pFrontTexture = NULL; + m_pBackTexture = NULL; + m_pTopTexture = NULL; + m_pBottomTexture = NULL; + m_pLeftTexture = NULL; + m_pRightTexture = NULL; } @@ -28,6 +41,60 @@ std::string KRSkyBox::getElementName() { return "sky_box"; } +void KRSkyBox::loadXML(tinyxml2::XMLElement *e) { + KRNode::loadXML(e); + + const char *szFrontTexture = e->Attribute("front_texture"); + if(szFrontTexture) { + m_frontTexture = szFrontTexture; + } else { + m_frontTexture = ""; + } + m_pFrontTexture = NULL; + + const char *szBackTexture = e->Attribute("back_texture"); + if(szBackTexture) { + m_backTexture = szBackTexture; + } else { + m_backTexture = ""; + } + m_pBackTexture = NULL; + + const char *szTopTexture = e->Attribute("top_texture"); + if(szTopTexture) { + m_topTexture = szTopTexture; + } else { + m_topTexture = ""; + } + m_pTopTexture = NULL; + + const char *szBottomTexture = e->Attribute("bottom_texture"); + if(szBottomTexture) { + m_bottomTexture = szBottomTexture; + } else { + m_bottomTexture = ""; + } + m_pBottomTexture = NULL; + + const char *szLeftTexture = e->Attribute("left_texture"); + if(szLeftTexture) { + m_leftTexture = szLeftTexture; + } else { + m_leftTexture = ""; + } + m_pLeftTexture = NULL; + + const char *szRightTexture = e->Attribute("right_texture"); + if(szRightTexture) { + m_rightTexture = szRightTexture; + } else { + m_rightTexture = ""; + } + m_pRightTexture = NULL; + +} + + #if TARGET_OS_IPHONE void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRNode::RenderPass renderPass) { @@ -42,9 +109,9 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume & matModelToView.transpose(); matModelToView.invert(); - KRShader *pShader = pContext->getShaderManager()->getShader("sky_box", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, renderPass); +// KRShader *pShader = pContext->getShaderManager()->getShader("sky_box", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, renderPass); - pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, NULL, NULL, NULL, 0, renderPass); +// pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, NULL, NULL, NULL, 0, renderPass); // Disable z-buffer write glDepthMask(GL_FALSE); @@ -67,4 +134,5 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume & } } -#endif \ No newline at end of file +#endif + diff --git a/KREngine/KREngine/Classes/KRSkyBox.h b/KREngine/KREngine/Classes/KRSkyBox.h index ae042c9..508348c 100644 --- a/KREngine/KREngine/Classes/KRSkyBox.h +++ b/KREngine/KREngine/Classes/KRSkyBox.h @@ -12,6 +12,7 @@ #include #import "KRMat4.h" #import "KRNode.h" +#import "KRTexture.h" class KRSkyBox : public KRNode { @@ -21,6 +22,7 @@ public: virtual ~KRSkyBox(); virtual std::string getElementName(); + virtual void loadXML(tinyxml2::XMLElement *e); #if TARGET_OS_IPHONE @@ -29,6 +31,22 @@ public: private: KRMat4 m_modelMatrix; + +protected: + std::string m_frontTexture; + std::string m_backTexture; + std::string m_topTexture; + std::string m_bottomTexture; + std::string m_leftTexture; + std::string m_rightTexture; + + KRTexture *m_pFrontTexture; + KRTexture *m_pBackTexture; + KRTexture *m_pTopTexture; + KRTexture *m_pBottomTexture; + KRTexture *m_pLeftTexture; + KRTexture *m_pRightTexture; + };