diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 5670615bf..1d126e33c 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -2116,7 +2116,13 @@ void Game::render2d(){ if(renderer.getAllowRenderUnitTitles() == false) { renderer.setAllowRenderUnitTitles(true); } - renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f)); + + if(Renderer::renderText3DEnabled == true) { + renderer.renderUnitTitles3D(coreData.getMenuFontNormal3D(),Vec3f(1.0f)); + } + else { + renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f)); + } } } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 1aad079cb..731346bee 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1445,6 +1445,7 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i pos.x += ((w / 2.f) - (lineWidth / 2.f)); } const Metrics &metrics= Metrics::getInstance(); + //float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); //lineHeight=metrics.toVirtualY(lineHeight); //lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR); @@ -2696,6 +2697,9 @@ void Renderer::renderSurface(const int renderFps) { //Restore static_cast(modelRenderer)->setDuplicateTexCoords(false); + + glDisable(GL_TEXTURE_2D); + glPopAttrib(); //assert @@ -5355,11 +5359,70 @@ void Renderer::setAllowRenderUnitTitles(bool value) { //} } +// This method renders titles for units +void Renderer::renderUnitTitles3D(Font3D *font, Vec3f color) { + std::map unitRenderedList; + + if(visibleFrameUnitList.size() > 0) { + //printf("Render Unit titles ON\n"); + + for(int idx = 0; idx < visibleFrameUnitList.size(); idx++) { + const Unit *unit = visibleFrameUnitList[idx]; + if(unit != NULL && unit->getVisible() == true) { + if(unit != NULL && unit->getCurrentUnitTitle() != "") { + //get the screen coordinates + Vec3f screenPos = unit->getScreenPos(); + #ifdef USE_STREFLOP + renderText3D(unit->getCurrentUnitTitle(), font, color, streflop::fabs(screenPos.x) + 5, streflop::fabs(screenPos.y) + 5, false); + #else + renderText3D(unit->getCurrentUnitTitle(), font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false); + #endif + + unitRenderedList[unit->getId()] = true; + } + else { + string str = unit->getFullName() + " - " + intToStr(unit->getId()) + " [" + unit->getPos().getString() + "]"; + Vec3f screenPos = unit->getScreenPos(); + #ifdef USE_STREFLOP + renderText3D(str, font, color, streflop::fabs(screenPos.x) + 5, streflop::fabs(screenPos.y) + 5, false); + #else + renderText3D(str, font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false); + #endif + } + } + } + visibleFrameUnitList.clear(); + } + + /* + if(renderUnitTitleList.size() > 0) { + for(int idx = 0; idx < renderUnitTitleList.size(); idx++) { + std::pair &unitInfo = renderUnitTitleList[idx]; + Unit *unit = unitInfo.first; + + const World *world= game->getWorld(); + Unit *validUnit = world->findUnitById(unit->getId()); + + if(validUnit != NULL && unitRenderedList.find(validUnit->getId()) == unitRenderedList.end()) { + string str = validUnit->getFullName() + " - " + intToStr(validUnit->getId()); + //get the screen coordinates + Vec3f &screenPos = unitInfo.second; + renderText(str, font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",__FILE__,__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z); + } + } + renderUnitTitleList.clear(); + } + */ +} + // This method renders titles for units void Renderer::renderUnitTitles(Font2D *font, Vec3f color) { std::map unitRenderedList; if(visibleFrameUnitList.size() > 0) { + //printf("Render Unit titles ON\n"); + for(int idx = 0; idx < visibleFrameUnitList.size(); idx++) { const Unit *unit = visibleFrameUnitList[idx]; if(unit != NULL && unit->getCurrentUnitTitle() != "") { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 9c94aa00d..85eeb733d 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -434,6 +434,7 @@ public: void setAllowRenderUnitTitles(bool value); bool getAllowRenderUnitTitles() { return allowRenderUnitTitles; } void renderUnitTitles(Font2D *font, Vec3f color); + void renderUnitTitles3D(Font3D *font, Vec3f color); Vec3f computeScreenPosition(const Vec3f &worldPos); void setPhotoMode(bool value) { photoMode = value; } diff --git a/source/shared_lib/include/graphics/pixmap.h b/source/shared_lib/include/graphics/pixmap.h index 49af89313..55c16b0dc 100644 --- a/source/shared_lib/include/graphics/pixmap.h +++ b/source/shared_lib/include/graphics/pixmap.h @@ -320,6 +320,7 @@ public: void loadSlice(const string &path, int slice); void loadSliceBmp(const string &path, int slice); void loadSliceTga(const string &path, int slice); + void loadSlicePng(const string &path, int slice); //get int getW() const {return w;} diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 033ec5db6..b2598ccd5 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -1209,18 +1209,21 @@ bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){ // class Pixmap3D // ===================================================== -Pixmap3D::Pixmap3D(){ +Pixmap3D::Pixmap3D() { w= -1; h= -1; d= -1; components= -1; + pixels = NULL; } Pixmap3D::Pixmap3D(int w, int h, int d, int components){ + pixels = NULL; init(w, h, d, components); } Pixmap3D::Pixmap3D(int d, int components){ + pixels = NULL; init(d, components); } @@ -1263,7 +1266,10 @@ Pixmap3D::~Pixmap3D() { void Pixmap3D::loadSlice(const string &path, int slice) { string extension= path.substr(path.find_last_of('.') + 1); - if(extension == "bmp") { + if(extension == "png") { + loadSlicePng(path, slice); + } + else if(extension == "bmp") { loadSliceBmp(path, slice); } else if(extension == "tga") { @@ -1275,6 +1281,48 @@ void Pixmap3D::loadSlice(const string &path, int slice) { this->path = path; } +void Pixmap3D::loadSlicePng(const string &path, int slice) { + this->path = path; + + Pixmap3D *pixmap = FileReader::readPath(path); + if(pixmap != NULL) { + this->path = path; + + w= pixmap->getW(); + h= pixmap->getH(); + if(components==-1){ + components= pixmap->getComponents(); + } + + if(pixels==NULL) { + pixels= new uint8[(std::size_t)pixmap->getPixelByteCount()]; + } + + for(unsigned int i = 0; i < pixmap->getPixelByteCount(); ++i) { + pixels[i] = pixmap->getPixels()[i]; + } + } + +// PixmapIoP plt; +// plt.openRead(path); +// +// //header +// int fileComponents= plt.getComponents(); +// +// //init +// w= plt.getW(); +// h= plt.getH(); +// if(components==-1){ +// components= fileComponents; +// } +// if(pixels==NULL){ +// pixels= new uint8[(std::size_t)getPixelByteCount()]; +// } +// +// //read data +// plt.read(&pixels[slice*w*h*components], components); +} + void Pixmap3D::loadSliceBmp(const string &path, int slice){ this->path = path;