diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index df1b4803..91ff1de7 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1837,7 +1837,7 @@ void Renderer::renderMouse3d() { if(gui->isPlacingBuilding()) { - modelRenderer->begin(true, true, false); + modelRenderer->begin(true, true, false, false); const UnitType *building= gui->getBuilding(); const Gui *gui= game->getGui(); @@ -2576,9 +2576,7 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, } glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr()); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); - //textRenderer3D->begin(font); textRenderer3D->render(text, pos.x, pos.y); - //textRenderer3D->end(); safeTextRender.end(); glDisable(GL_BLEND); @@ -2597,7 +2595,6 @@ void Renderer::renderText3D(const string &text, Font3D *font, float alpha, int x Vec2i pos= Vec2i(x, y); //Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); textRenderer3D->render(text, pos.x, pos.y, centered); //textRenderer3D->end(); @@ -2618,10 +2615,8 @@ void Renderer::renderText(const string &text, Font2D *font, float alpha, int x, Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer,font); textRenderer->render(text, pos.x, pos.y); - //textRenderer->end(); safeTextRender.end(); glPopAttrib(); @@ -2726,10 +2721,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth,maxEditRenderWidth); } glColor3fv(color.ptr()); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); textRenderer3D->render(text, pos.x, pos.y); - //textRenderer3D->end(); safeTextRender.end(); glPopAttrib(); @@ -2746,10 +2739,8 @@ void Renderer::renderText3D(const string &text, Font3D *font, const Vec3f &color Vec2i pos= Vec2i(x, y); //Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); textRenderer3D->render(text, pos.x, pos.y, centered); - //textRenderer3D->end(); safeTextRender.end(); glPopAttrib(); @@ -2765,10 +2756,8 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec3f &color, Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer,font); textRenderer->render(text, pos.x, pos.y); - //textRenderer->end(); safeTextRender.end(); glPopAttrib(); @@ -2808,10 +2797,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth,maxEditRenderWidth); } glColor4fv(color.ptr()); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); textRenderer3D->render(text, pos.x, pos.y); - //textRenderer3D->end(); safeTextRender.end(); glDisable(GL_BLEND); @@ -2830,10 +2817,8 @@ void Renderer::renderText3D(const string &text, Font3D *font, const Vec4f &color Vec2i pos= Vec2i(x, y); //Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); textRenderer3D->render(text, pos.x, pos.y, centered); - //textRenderer3D->end(); safeTextRender.end(); glDisable(GL_BLEND); @@ -2851,10 +2836,8 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec4f &color, Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer,font); textRenderer->render(text, pos.x, pos.y); - //textRenderer->end(); safeTextRender.end(); glPopAttrib(); @@ -2873,7 +2856,6 @@ void Renderer::renderTextShadow3D(const string &text, Font3D *font,const Vec4f & Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer3D->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer3D,font); if(color.w < 0.5) { glColor3f(0.0f, 0.0f, 0.0f); @@ -2902,7 +2884,6 @@ void Renderer::renderTextShadow(const string &text, Font2D *font,const Vec4f &co Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - //textRenderer->begin(font); TextRendererSafeWrapper safeTextRender(textRenderer,font); if(color.w < 0.5) { glColor3f(0.0f, 0.0f, 0.0f); @@ -4618,7 +4599,7 @@ void Renderer::renderObjects(const int renderFps) { glEnable(GL_COLOR_MATERIAL); glAlphaFunc(GL_GREATER, 0.5f); - modelRenderer->begin(true, true, false); + modelRenderer->begin(true, true, false, false); } //ambient and diffuse color is taken from cell color @@ -5015,7 +4996,7 @@ void Renderer::renderUnits(const int renderFps) { } glActiveTexture(baseTexUnit); - modelRenderer->begin(true, true, true, &meshCallbackTeamColor); + modelRenderer->begin(true, true, true, false, &meshCallbackTeamColor); } glMatrixMode(GL_MODELVIEW); @@ -5107,7 +5088,7 @@ void Renderer::renderUnitsToBuild(const int renderFps) { glEnable(GL_COLOR_MATERIAL); glDepthMask(GL_FALSE); - modelRenderer->begin(true, true, false); + modelRenderer->begin(true, true, false, false); for(int visibleUnitIndex = 0; visibleUnitIndex < qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) { @@ -6386,7 +6367,7 @@ void Renderer::renderMenuBackground(const MenuBackground *menuBackground) { //main model glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); - modelRenderer->begin(true, true, true); + modelRenderer->begin(true, true, true, false); menuBackground->getMainModelPtr()->updateInterpolationData(menuBackground->getAnim(), true); modelRenderer->render(menuBackground->getMainModelPtr()); modelRenderer->end(); @@ -6405,7 +6386,7 @@ void Renderer::renderMenuBackground(const MenuBackground *menuBackground) { CacheManager::getCachedItem< std::vector >(GameConstants::characterMenuScreenPositionListCacheLookupKey); characterMenuScreenPositionListCache.clear(); - modelRenderer->begin(true, true, false); + modelRenderer->begin(true, true, false, false); for(int i=0; i < MenuBackground::characterCount; ++i) { glMatrixMode(GL_MODELVIEW); @@ -6559,7 +6540,7 @@ void Renderer::renderMenuBackground(Camera *camera, float fade, Model *mainModel if(mainModel) { glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); - modelRenderer->begin(true, true, true); + modelRenderer->begin(true, true, true, false); mainModel->updateInterpolationData(anim, true); modelRenderer->render(mainModel); modelRenderer->end(); @@ -6574,7 +6555,7 @@ void Renderer::renderMenuBackground(Camera *camera, float fade, Model *mainModel glAlphaFunc(GL_GREATER, 0.0f); float alpha= clamp((minDist-dist) / minDist, 0.f, 1.f); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Vec4f(1.0f, 1.0f, 1.0f, alpha).ptr()); - modelRenderer->begin(true, true, false); + modelRenderer->begin(true, true, false, false); for(unsigned int i = 0; i < characterModels.size(); ++i) { if(characterModels[i]) { @@ -7459,20 +7440,11 @@ vector Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin } } - //assertGl(); + modelRenderer->begin(false, renderingShadows, false, colorPickingSelection); - modelRenderer->begin(false, renderingShadows, false); - - //assertGl(); - - if(colorPickingSelection == true) { - BaseColorPickEntity::beginPicking(); - } - else { + if(colorPickingSelection == false) { glInitNames(); } - - //assertGl(); } if(colorPickingSelection == false) { @@ -7504,12 +7476,8 @@ vector Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin if(colorPickingSelection == true) { unit->setUniquePickingColor(); unitsList.push_back(unit); - - //assertGl(); } - //assertGl(); - modelRenderer->render(model,rmSelection); glPopMatrix(); @@ -7517,35 +7485,22 @@ vector Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin if(colorPickingSelection == false) { glPopName(); } - - //assertGl(); } if(modelRenderStarted == true) { - //assertGl(); - modelRenderer->end(); - - //assertGl(); - - if(colorPickingSelection == true) { - BaseColorPickEntity::endPicking(); - } - else { + if(colorPickingSelection == false) { glPopAttrib(); } - -// assertGl(); } } -// assertGl(); - return unitsList; } //render objects for selection purposes -vector Renderer::renderObjectsFast(bool renderingShadows, bool resourceOnly, bool colorPickingSelection) { +vector Renderer::renderObjectsFast(bool renderingShadows, bool resourceOnly, + bool colorPickingSelection) { vector objectList; if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return objectList; @@ -7591,12 +7546,9 @@ vector Renderer::renderObjectsFast(bool renderingShadows, bool resour } } - modelRenderer->begin(false, renderingShadows, false); + modelRenderer->begin(false, renderingShadows, false, colorPickingSelection); - if(colorPickingSelection == true) { - BaseColorPickEntity::beginPicking(); - } - else { + if(colorPickingSelection == false) { glInitNames(); } } @@ -7640,10 +7592,7 @@ vector Renderer::renderObjectsFast(bool renderingShadows, bool resour if(modelRenderStarted == true) { modelRenderer->end(); - if(colorPickingSelection == true) { - BaseColorPickEntity::endPicking(); - } - else { + if(colorPickingSelection == false) { glPopAttrib(); } } diff --git a/source/shared_lib/include/graphics/gl/model_renderer_gl.h b/source/shared_lib/include/graphics/gl/model_renderer_gl.h index 62fc687b..80c85a4c 100644 --- a/source/shared_lib/include/graphics/gl/model_renderer_gl.h +++ b/source/shared_lib/include/graphics/gl/model_renderer_gl.h @@ -32,7 +32,7 @@ private: public: ModelRendererGl(); - virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback); + virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, bool colorPickingMode, MeshCallback *meshCallback); virtual void end(); virtual void render(Model *model,int renderMode=rmNormal); virtual void renderNormalsOnly(Model *model); diff --git a/source/shared_lib/include/graphics/model_renderer.h b/source/shared_lib/include/graphics/model_renderer.h index 68a72cfb..58e7aade 100644 --- a/source/shared_lib/include/graphics/model_renderer.h +++ b/source/shared_lib/include/graphics/model_renderer.h @@ -49,6 +49,7 @@ protected: bool renderNormals; bool renderTextures; bool renderColors; + bool colorPickingMode; MeshCallback *meshCallback; public: @@ -56,13 +57,14 @@ public: renderNormals = false; renderTextures = false; renderColors = false; + colorPickingMode = false; meshCallback= NULL; } virtual ~ModelRenderer(){}; - virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback= NULL)=0; + virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, bool colorPickingMode, MeshCallback *meshCallback= NULL)=0; virtual void end()=0; virtual void render(Model *model,int renderMode=rmNormal)=0; virtual void renderNormalsOnly(Model *model)=0; diff --git a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp index a0386e69..6ae03eab 100644 --- a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp @@ -34,7 +34,8 @@ ModelRendererGl::ModelRendererGl() { lastTexture=0; } -void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback) { +void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool renderColors, + bool colorPickingMode, MeshCallback *meshCallback) { //assertions assert(rendering == false); assertGl(); @@ -42,6 +43,7 @@ void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool render this->renderTextures= renderTextures; this->renderNormals= renderNormals; this->renderColors= renderColors; + this->colorPickingMode = colorPickingMode; this->meshCallback= meshCallback; rendering= true; @@ -53,14 +55,19 @@ void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool render glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); //init opengl - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if(this->colorPickingMode == false) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } glBindTexture(GL_TEXTURE_2D, 0); glFrontFace(GL_CCW); - glEnable(GL_NORMALIZE); - glEnable(GL_BLEND); - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(0.005f, 0.0f); + if(this->colorPickingMode == false) { + glEnable(GL_NORMALIZE); + glEnable(GL_BLEND); + + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(0.005f, 0.0f); + } glEnableClientState(GL_VERTEX_ARRAY); @@ -81,6 +88,11 @@ void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool render glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST ); glHint( GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST ); */ + + if(this->colorPickingMode == true) { + BaseColorPickEntity::beginPicking(); + } + //assertions assertGl(); } @@ -93,13 +105,19 @@ void ModelRendererGl::end() { //set render state rendering= false; - glPolygonOffset( 0.0f, 0.0f ); - glDisable(GL_POLYGON_OFFSET_FILL); + if(this->colorPickingMode == false) { + glPolygonOffset( 0.0f, 0.0f ); + glDisable(GL_POLYGON_OFFSET_FILL); + } //pop glPopAttrib(); glPopClientAttrib(); + if(colorPickingMode == true) { + BaseColorPickEntity::endPicking(); + } + //assertions assertGl(); } @@ -157,35 +175,37 @@ void ModelRendererGl::renderMesh(Mesh *mesh,int renderMode) { glEnable(GL_CULL_FACE); } - //set color - if(renderColors) { - Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity()); - glColor4fv(color.ptr()); - } + if(this->colorPickingMode == false) { + //set color + if(renderColors) { + Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity()); + glColor4fv(color.ptr()); + } - //texture state - const Texture2DGl *texture= static_cast(mesh->getTexture(mtDiffuse)); - if(texture != NULL && renderTextures) { - if(lastTexture != texture->getHandle()){ - //assert(glIsTexture(texture->getHandle())); - //throw megaglest_runtime_error("glIsTexture(texture->getHandle()) == false for texture: " + texture->getPath()); - if(glIsTexture(texture->getHandle()) == GL_TRUE) { - glBindTexture(GL_TEXTURE_2D, texture->getHandle()); - lastTexture= texture->getHandle(); - } - else { - glBindTexture(GL_TEXTURE_2D, 0); - lastTexture= 0; + //texture state + const Texture2DGl *texture= static_cast(mesh->getTexture(mtDiffuse)); + if(texture != NULL && renderTextures) { + if(lastTexture != texture->getHandle()){ + //assert(glIsTexture(texture->getHandle())); + //throw megaglest_runtime_error("glIsTexture(texture->getHandle()) == false for texture: " + texture->getPath()); + if(glIsTexture(texture->getHandle()) == GL_TRUE) { + glBindTexture(GL_TEXTURE_2D, texture->getHandle()); + lastTexture= texture->getHandle(); + } + else { + glBindTexture(GL_TEXTURE_2D, 0); + lastTexture= 0; + } } } - } - else{ - glBindTexture(GL_TEXTURE_2D, 0); - lastTexture= 0; - } + else{ + glBindTexture(GL_TEXTURE_2D, 0); + lastTexture= 0; + } - if(meshCallback != NULL) { - meshCallback->execute(mesh); + if(meshCallback != NULL) { + meshCallback->execute(mesh); + } } //misc vars diff --git a/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp index fdf390d9..26a56dd8 100644 --- a/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp @@ -261,7 +261,7 @@ void ParticleRendererGl::renderModel(GameParticleSystem *ps, ModelRenderer *mr){ glRotatef(angleH, 0.f, 1.f, 0.f); //render - mr->begin(true, true, false); + mr->begin(true, true, false, false); float t = ps->getTween(); if(t < 0.0f || t > 1.0f) { diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 311e532b..27bc0c1d 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -1528,15 +1528,18 @@ void BaseColorPickEntity::beginPicking() { //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT); - //glDisable(GL_TEXTURE_2D); - //glDisable(GL_FOG); - //glDisable(GL_LIGHTING); + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_TEXTURE_2D); + glDisable(GL_FOG); + glDisable(GL_LIGHTING); + glDisable(GL_BLEND); + glDisable(GL_MULTISAMPLE); + glDisable(GL_DITHER); + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_NORMALIZE); - //glDisable(GL_BLEND); - //glDisable(GL_MULTISAMPLE); - //glDisable(GL_DITHER); - - glPushAttrib(GL_TEXTURE_2D | GL_LIGHTING | GL_BLEND | GL_MULTISAMPLE | GL_DITHER); + //glPushAttrib(GL_TEXTURE_2D | GL_LIGHTING | GL_BLEND | GL_MULTISAMPLE | GL_DITHER); + //glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT | GL_NORMALIZE | GL_BLEND | GL_POLYGON_OFFSET_FILL); } void BaseColorPickEntity::endPicking() {