From 9920ba04b8d8d9714ff460860549e1e962df43de Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 17 Sep 2010 16:18:19 +0000 Subject: [PATCH] added enableBlending flag to WFObj rendering git-svn-id: svn://anubis/misc/wfobj@242 bd8a9e45-a331-0410-811e-c64571078777 --- WFObj.cc | 25 +++++++++++++++++-------- WFObj.h | 9 ++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 98de054..01d34af 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -195,7 +195,7 @@ void WFObj::processInputLine(const std::string & input) } -GLuint WFObj::render(bool doTextureInfo) +GLuint WFObj::render(bool doTextureInfo, bool enableBlending) { checkGLError(); GLuint list = glGenLists(1); @@ -331,13 +331,15 @@ GLuint WFObj::render(bool doTextureInfo) } if (inMaterial) { - material.renderEnd(currentMaterialName, doTextureInfo); + material.renderEnd(currentMaterialName, doTextureInfo, + enableBlending); inMaterial = false; } if (m_data[i].size() >= 2) { currentMaterialName = m_data[i][1]; - material.renderBegin(currentMaterialName, doTextureInfo); + material.renderBegin(currentMaterialName, doTextureInfo, + enableBlending); inMaterial = true; } } @@ -362,7 +364,7 @@ GLuint WFObj::render(bool doTextureInfo) } if (inMaterial) { - material.renderEnd(currentMaterialName, doTextureInfo); + material.renderEnd(currentMaterialName, doTextureInfo, enableBlending); inMaterial = false; } glEndList(); @@ -493,7 +495,8 @@ void WFObj::WFMtl::processInputLine(const std::string & input) } } -void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo) +void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo, + bool enableBlending) { map< string, vector< vector > >::iterator it = m_data.find(mtlname); if (it == m_data.end()) @@ -610,6 +613,11 @@ void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo) pushAttributes(); if (doTextureInfo) { + if (enableBlending) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } if (foundTexture) { #ifdef DEBUGGL @@ -635,15 +643,16 @@ void WFObj::WFMtl::pushAttributes() return; m_attributesPushed = true; #ifdef DEBUGGL - cout << " glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT)" + cout << " glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT)" << endl; #endif checkGLError(); - glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT); + glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); checkGLError(); } -void WFObj::WFMtl::renderEnd(const string & mtlname, bool doTextureInfo) +void WFObj::WFMtl::renderEnd(const string & mtlname, bool doTextureInfo, + bool enableBlending) { map< string, vector< vector > >::iterator it = m_data.find(mtlname); if (it == m_data.end()) diff --git a/WFObj.h b/WFObj.h index 52e03ac..d8815ca 100644 --- a/WFObj.h +++ b/WFObj.h @@ -24,9 +24,11 @@ public: WFMtl(WFObj * obj) { m_obj = obj; } bool load(const FileLoader::Path & path); void renderBegin(const std::string & mtlname, - bool doTextureInfo = true); + bool doTextureInfo = true, + bool enableBlending = false); void renderEnd(const std::string & mtlname, - bool doTextureInfo = true); + bool doTextureInfo = true, + bool enableBlending = false); protected: /* methods */ @@ -51,7 +53,8 @@ public: }; bool load(const FileLoader::Path & path); - GLuint render(bool doTextureInfo = true); + GLuint render(bool doTextureInfo = true, + bool enableBlending = false); const float * const getAABB() { return m_aabb; } protected: