- bugfix for unit titles in special debug mode

- added support for png format for pixmap3d (Water) textures
This commit is contained in:
Mark Vejvoda 2011-07-01 07:46:18 +00:00
parent ec15c81d12
commit d2c8cc0187
5 changed files with 122 additions and 3 deletions

View File

@ -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));
}
}
}

View File

@ -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<ModelRendererGl*>(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<int,bool> 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<Unit *,Vec3f> &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<int,bool> 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() != "") {

View File

@ -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; }

View File

@ -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;}

View File

@ -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<Pixmap3D>::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;