From c15488a212d8fa05e878f36064d4e23d551ce8a9 Mon Sep 17 00:00:00 2001 From: mathusummut Date: Thu, 21 Jun 2018 19:57:44 +0200 Subject: [PATCH] Full transparency support is now added --- source/g3d_viewer/main.cpp | 37 +- source/g3d_viewer/main.h | 4 +- source/g3d_viewer/renderer.cpp | 52 +- source/g3d_viewer/renderer.h | 12 +- source/glest_game/facilities/components.cpp | 7 +- source/glest_game/facilities/components.h | 25 +- source/glest_game/game/chat_manager.cpp | 10 +- source/glest_game/game/console.cpp | 6 +- source/glest_game/game/console.h | 10 +- source/glest_game/game/game.cpp | 23 +- source/glest_game/game/stats.cpp | 8 +- source/glest_game/game/stats.h | 6 +- source/glest_game/graphics/renderer.cpp | 179 ++-- source/glest_game/graphics/renderer.h | 11 +- source/glest_game/main/battle_end.cpp | 10 +- source/glest_game/main/intro.cpp | 3 +- source/glest_game/menu/main_menu.cpp | 7 +- .../menu/menu_state_connected_game.cpp | 26 +- .../menu/menu_state_custom_game.cpp | 23 +- .../glest_game/menu/menu_state_load_game.cpp | 4 +- .../menu/menu_state_masterserver.cpp | 4 +- source/glest_game/menu/menu_state_mods.cpp | 6 +- source/glest_game/menu/menu_state_root.cpp | 9 +- .../glest_game/menu/menu_state_scenario.cpp | 3 +- source/glest_game/menu/server_line.cpp | 9 +- .../glest_game/network/network_interface.cpp | 2 +- source/glest_game/network/network_interface.h | 2 +- source/glest_game/type_instances/object.cpp | 2 +- source/glest_game/type_instances/unit.cpp | 16 +- source/glest_game/types/object_type.cpp | 4 +- source/glest_game/types/object_type.h | 6 +- source/glest_game/world/minimap.cpp | 9 +- source/glest_game/world/surface_atlas.cpp | 2 +- source/glest_game/world/tileset.cpp | 6 +- source/glest_game/world/unit_updater.cpp | 6 +- source/glest_game/world/world.cpp | 2 +- source/glest_map_editor/main.cpp | 11 +- .../include/graphics/gl/text_renderer_gl.h | 6 +- source/shared_lib/include/graphics/model.h | 1 - source/shared_lib/include/graphics/particle.h | 4 +- .../include/graphics/text_renderer.h | 2 +- source/shared_lib/include/graphics/vec.h | 4 +- .../sources/graphics/gl/text_renderer_gl.cpp | 10 +- .../shared_lib/sources/graphics/particle.cpp | 6 +- source/tools/glexemel/g3d_support_b269.py | 929 ------------------ 45 files changed, 299 insertions(+), 1225 deletions(-) delete mode 100644 source/tools/glexemel/g3d_support_b269.py diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index ebd52ce1b..122ef6d56 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -407,7 +407,8 @@ namespace Shared { menuCustomColor->AppendCheckItem(miColorWhite, wxT("&White\t4")); menuCustomColor->AppendCheckItem(miColorCyan, wxT("&Cyan\t5")); menuCustomColor->AppendCheckItem(miColorOrange, wxT("&Orange\t6")); - menuCustomColor->AppendCheckItem(miColorMagenta, wxT("&Pink\t7")); // it is called Pink everywhere else so... + menuCustomColor->AppendCheckItem(miColorMagenta, wxT("&Pink\t7")); + menuCustomColor->AppendCheckItem(miColorTransparent, wxT("&Transparent\t8")); menu->Append(menuCustomColor, wxT("&Custom Color")); menuMode->Check(miModeGrid, true); @@ -1388,8 +1389,7 @@ namespace Shared { Vec3f vec = Vec3f(0.f, height / 2.f, 0.f); ups->setPos(vec); } - //ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0)); - ups->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0, 0)); + ups->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel4f(0, 0)); unitParticleSystems.push_back(ups); renderer->manageParticleSystem(ups); @@ -1502,7 +1502,7 @@ namespace Shared { Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); ps->setPath(vec, vec2); } - ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0, 0)); + ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel4f(0, 0)); projectileParticleSystems.push_back(ps); @@ -1609,7 +1609,7 @@ namespace Shared { //Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); // <------- removed relative projectile //ps->setPath(vec, vec2); // <------- removed relative projectile } - ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0, 0)); + ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel4f(0, 0)); splashParticleSystems.push_back(ps); @@ -1706,6 +1706,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1723,6 +1724,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1740,6 +1742,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1757,6 +1760,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1774,6 +1778,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1791,6 +1796,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, true); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1808,6 +1814,7 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, true); menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, false); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1825,6 +1832,25 @@ namespace Shared { menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorMagenta, true); + menuCustomColor->Check(miColorTransparent, false); + } catch (std::runtime_error &e) { + std::cout << e.what() << std::endl; + wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); + } + } + + void MainWindow::onMenuColorTransparent(wxCommandEvent &event) { + try { + playerColor = Renderer::pcTransparent; + menuCustomColor->Check(miColorRed, false); + menuCustomColor->Check(miColorBlue, false); + menuCustomColor->Check(miColorGreen, false); + menuCustomColor->Check(miColorYellow, false); + menuCustomColor->Check(miColorWhite, false); + menuCustomColor->Check(miColorCyan, false); + menuCustomColor->Check(miColorOrange, false); + menuCustomColor->Check(miColorMagenta, false); + menuCustomColor->Check(miColorTransparent, true); } catch (std::runtime_error &e) { std::cout << e.what() << std::endl; wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal(); @@ -1982,6 +2008,7 @@ namespace Shared { EVT_MENU(miColorCyan, MainWindow::onMenuColorCyan) EVT_MENU(miColorOrange, MainWindow::onMenuColorOrange) EVT_MENU(miColorMagenta, MainWindow::onMenuColorMagenta) + EVT_MENU(miColorTransparent, MainWindow::onMenuColorTransparent) EVT_MENU(miChangeBackgroundColor, MainWindow::OnChangeColor) END_EVENT_TABLE() diff --git a/source/g3d_viewer/main.h b/source/g3d_viewer/main.h index 02ab8e126..8108aee5d 100644 --- a/source/g3d_viewer/main.h +++ b/source/g3d_viewer/main.h @@ -71,7 +71,8 @@ namespace Shared { miColorWhite, miColorCyan, miColorOrange, - miColorMagenta + miColorMagenta, + miColorTransparent }; private: @@ -172,6 +173,7 @@ namespace Shared { void onMenuColorCyan(wxCommandEvent &event); void onMenuColorOrange(wxCommandEvent &event); void onMenuColorMagenta(wxCommandEvent &event); + void onMenuColorTransparent(wxCommandEvent &event); void onMouseWheelDown(wxMouseEvent &event); void onMouseWheelUp(wxMouseEvent &event); void onMouseMove(wxMouseEvent &event); diff --git a/source/g3d_viewer/renderer.cpp b/source/g3d_viewer/renderer.cpp index df1771e0f..0263dfbc9 100644 --- a/source/g3d_viewer/renderer.cpp +++ b/source/g3d_viewer/renderer.cpp @@ -54,7 +54,7 @@ namespace Shared { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); //set alpha to 1 - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, hasAlpha ? GL_COMBINE : GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); @@ -75,7 +75,7 @@ namespace Shared { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); //set alpha to 1 - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, hasAlpha ? GL_COMBINE : GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); @@ -115,6 +115,7 @@ namespace Shared { customTextureCyan = NULL; customTextureOrange = NULL; customTextureMagenta = NULL; + customTextureTransparent = NULL; particleManager = NULL; } @@ -239,43 +240,48 @@ namespace Shared { //red tex customTextureRed = textureManager->newTexture2D(); - customTextureRed->getPixmap()->init(1, 1, 3); - customTextureRed->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.f, 0.f)); + customTextureRed->getPixmap()->init(1, 1, 4); + customTextureRed->getPixmap()->setPixel(0, 0, Vec4f(1.f, 0.f, 0.f, 1.0f)); //blue tex customTextureBlue = textureManager->newTexture2D(); - customTextureBlue->getPixmap()->init(1, 1, 3); - customTextureBlue->getPixmap()->setPixel(0, 0, Vec3f(0.f, 0.f, 1.f)); + customTextureBlue->getPixmap()->init(1, 1, 4); + customTextureBlue->getPixmap()->setPixel(0, 0, Vec4f(0.f, 0.f, 1.f, 1.0f)); //green tex customTextureGreen = textureManager->newTexture2D(); - customTextureGreen->getPixmap()->init(1, 1, 3); - customTextureGreen->getPixmap()->setPixel(0, 0, Vec3f(0.f, 0.5f, 0.f)); + customTextureGreen->getPixmap()->init(1, 1, 4); + customTextureGreen->getPixmap()->setPixel(0, 0, Vec4f(0.f, 0.5f, 0.f, 1.0f)); //yellow tex customTextureYellow = textureManager->newTexture2D(); - customTextureYellow->getPixmap()->init(1, 1, 3); - customTextureYellow->getPixmap()->setPixel(0, 0, Vec3f(1.f, 1.f, 0.f)); + customTextureYellow->getPixmap()->init(1, 1, 4); + customTextureYellow->getPixmap()->setPixel(0, 0, Vec4f(1.f, 1.f, 0.f, 1.0f)); //white tex customTextureWhite = textureManager->newTexture2D(); - customTextureWhite->getPixmap()->init(1, 1, 3); - customTextureWhite->getPixmap()->setPixel(0, 0, Vec3f(1.f, 1.f, 1.f)); + customTextureWhite->getPixmap()->init(1, 1, 4); + customTextureWhite->getPixmap()->setPixel(0, 0, Vec4f(1.f, 1.f, 1.f, 1.0f)); //cyan tex customTextureCyan = textureManager->newTexture2D(); - customTextureCyan->getPixmap()->init(1, 1, 3); - customTextureCyan->getPixmap()->setPixel(0, 0, Vec3f(0.f, 1.f, 0.8f)); + customTextureCyan->getPixmap()->init(1, 1, 4); + customTextureCyan->getPixmap()->setPixel(0, 0, Vec4f(0.f, 1.f, 0.8f, 1.0f)); //orange tex customTextureOrange = textureManager->newTexture2D(); - customTextureOrange->getPixmap()->init(1, 1, 3); - customTextureOrange->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 0.f)); + customTextureOrange->getPixmap()->init(1, 1, 4); + customTextureOrange->getPixmap()->setPixel(0, 0, Vec4f(1.f, 0.5f, 0.f, 1.0f)); //magenta tex customTextureMagenta = textureManager->newTexture2D(); - customTextureMagenta->getPixmap()->init(1, 1, 3); - customTextureMagenta->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 1.f)); + customTextureMagenta->getPixmap()->init(1, 1, 4); + customTextureMagenta->getPixmap()->setPixel(0, 0, Vec4f(1.f, 0.5f, 1.f, 1.0f)); + + //transparent tex + customTextureTransparent = textureManager->newTexture2D(); + customTextureTransparent->getPixmap()->init(1, 1, 4); + customTextureTransparent->getPixmap()->setPixel(0, 0, Vec4f(1.0f, 1.0f, 1.0f, 0.0f)); glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -332,6 +338,7 @@ namespace Shared { glTranslatef(0, -1.5, -5); Texture2D *customTexture = NULL; + bool hasAlpha = false; switch (playerColor) { case pcRed: customTexture = customTextureRed; @@ -357,11 +364,15 @@ namespace Shared { case pcMagenta: customTexture = customTextureMagenta; break; + case pcTransparent: + customTexture = customTextureTransparent; + hasAlpha = true; + break; default: assert(false); break; } - meshCallbackTeamColor.setTeamTexture(customTexture); + meshCallbackTeamColor.setTeamTexture(customTexture, hasAlpha); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -483,6 +494,9 @@ namespace Shared { case pcMagenta: customTexture = customTextureMagenta; break; + case pcTransparent: + customTexture = customTextureTransparent; + break; default: throw megaglest_runtime_error("Unknown playercolor: " + intToStr(playerColor)); break; diff --git a/source/g3d_viewer/renderer.h b/source/g3d_viewer/renderer.h index 93a60d419..9d7f2bc3b 100644 --- a/source/g3d_viewer/renderer.h +++ b/source/g3d_viewer/renderer.h @@ -55,13 +55,19 @@ namespace Shared { class MeshCallbackTeamColor : public MeshCallback { private: const Texture *teamTexture; + bool hasAlpha; public: MeshCallbackTeamColor() : MeshCallback() { teamTexture = NULL; + hasAlpha = false; } - void setTeamTexture(const Texture *teamTexture) { + void setTeamTexture(const Texture *teamTexture, bool hasAlpha) { this->teamTexture = teamTexture; + this->hasAlpha = hasAlpha; + } + bool getHasAlpha() { + return hasAlpha; } virtual void execute(const Mesh *mesh); }; @@ -86,7 +92,8 @@ namespace Shared { pcWhite, pcCyan, pcOrange, - pcMagenta + pcMagenta, + pcTransparent }; private: @@ -112,6 +119,7 @@ namespace Shared { Texture2D *customTextureCyan; Texture2D *customTextureOrange; Texture2D *customTextureMagenta; + Texture2D *customTextureTransparent; MeshCallbackTeamColor meshCallbackTeamColor; float red; diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index cbb998d12..8ca81a57d 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -37,9 +37,6 @@ namespace Glest { float GraphicComponent::fade = 0.f; const float GraphicComponent::animSpeed = 0.02f; const float GraphicComponent::fadeSpeed = 0.01f; - // WHITE - Vec3f GraphicComponent::customTextColor = Vec3f(1.0, 1.0, 1.0); - std::map > GraphicComponent::registeredGraphicComponentList; GraphicComponent::GraphicComponent(const std::string &containerName, const std::string &objName, bool registerControl) { @@ -378,7 +375,7 @@ namespace Glest { texture = NULL; } - void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) { + void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec4f textColor, bool wordWrap) { GraphicComponent::init(x, y, w, h); this->centered = centered; this->textColor = textColor; @@ -469,7 +466,7 @@ namespace Glest { leftControlled = false; } - void GraphicListBox::init(int x, int y, int w, int h, Vec3f textColor) { + void GraphicListBox::init(int x, int y, int w, int h, Vec4f textColor) { GraphicComponent::init(x, y, w, h); this->textColor = textColor; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index ddb4ea649..a734b1d7f 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -24,6 +24,7 @@ #include "font.h" #include "texture.h" #include "leak_dumper.h" +#include "game_constants.h" #include "vec.h" using std::string; @@ -66,7 +67,6 @@ namespace Glest { static float anim; static float fade; - static Vec3f customTextColor; string containerName; string instanceName; @@ -79,13 +79,6 @@ namespace Glest { GraphicComponent(const std::string &containerName = "", const std::string &objName = "", bool registerControl = true); virtual ~GraphicComponent(); - static void setCustomTextColor(Vec3f value) { - customTextColor = value; - } - static Vec3f getCustomTextColor() { - return customTextColor; - } - static void clearRegisteredComponents(std::string containerName = ""); static void clearRegisterGraphicComponent(std::string containerName, std::string objName); static void clearRegisterGraphicComponent(std::string containerName, std::vector objNameList); @@ -205,7 +198,7 @@ namespace Glest { private: bool centered; - Vec3f textColor; + Vec4f textColor; bool wordWrap; int centeredW; @@ -223,7 +216,7 @@ namespace Glest { public: GraphicLabel(const std::string &containerName = "", const std::string &objName = "", bool registerControl = true); - void init(int x, int y, int w = defW, int h = defH, bool centered = false, Vec3f textColor = GraphicComponent::customTextColor, bool wordWrap = false); + void init(int x, int y, int w = defW, int h = defH, bool centered = false, Vec4f textColor = WHITE, bool wordWrap = false); virtual bool mouseMove(int x, int y); @@ -263,10 +256,10 @@ namespace Glest { bool getCenteredH() const; //void setCenteredH(bool centered); - Vec3f getTextColor() const { + Vec4f getTextColor() const { return textColor; } - void setTextColor(Vec3f color) { + void setTextColor(Vec4f color) { this->textColor = color; } @@ -383,12 +376,12 @@ namespace Glest { vector translated_items; int selectedItemIndex; bool lighted; - Vec3f textColor; + Vec4f textColor; bool leftControlled; public: GraphicListBox(const std::string &containerName = "", const std::string &objName = ""); - void init(int x, int y, int w = defW, int h = defH, Vec3f textColor = GraphicComponent::customTextColor); + void init(int x, int y, int w = defW, int h = defH, Vec4f textColor = WHITE); int getItemCount() const { return (int) items.size(); @@ -418,10 +411,10 @@ namespace Glest { return leftControlled; } void setLeftControlled(bool leftControlled); - Vec3f getTextColor() const { + Vec4f getTextColor() const { return textColor; } - void setTextColor(Vec3f color) { + void setTextColor(Vec4f color) { this->textColor = color; } diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index ceff370e3..320bb980d 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -267,11 +267,11 @@ namespace console->addLine(text, false, this-> manualPlayerNameOverride, - Vec3f(1.f, 1.f, 1.f), + Vec4f(1.f, 1.f, 1.f, 1.f), teamMode); } else { console->addLine(text, false, playerIndex, - Vec3f(1.f, 1.f, 1.f), + Vec4f(1.f, 1.f, 1.f, 1.f), teamMode); } @@ -679,13 +679,11 @@ namespace substr(1, msg.chatText.size()), true, msg.chatPlayerIndex, - Vec3f(1.f, 1.f, 1.f), + Vec4f(1.f, 1.f, 1.f, 1.f), teamMode); } else { console->addLine(msg.chatText, true, - msg.chatPlayerIndex, Vec3f(1.f, - 1.f, - 1.f), + msg.chatPlayerIndex, Vec4f(1.f, 1.f, 1.f, 1.f), teamMode); } diff --git a/source/glest_game/game/console.cpp b/source/glest_game/game/console.cpp index c77db77a0..fa896eb56 100644 --- a/source/glest_game/game/console.cpp +++ b/source/glest_game/game/console.cpp @@ -139,11 +139,11 @@ namespace Glest { } void Console::addLineOnly(const string & line) { - addLine(line, false, -1, Vec3f(1.f, 1.f, 1.f), false, true); + addLine(line, false, -1, Vec4f(1.f, 1.f, 1.f, 1.f), false, true); } void Console::addLine(const string & line, bool playSound, - int playerIndex, Vec3f textColor, bool teamMode, + int playerIndex, Vec4f textColor, bool teamMode, bool clearOtherLines) { try { if (playSound == true) { @@ -195,7 +195,7 @@ namespace Glest { } void Console::addLine(const string & line, bool playSound, - const string & playerName, Vec3f textColor, + const string & playerName, Vec4f textColor, bool teamMode) { try { if (playSound == true) { diff --git a/source/glest_game/game/console.h b/source/glest_game/game/console.h index 959d8fcb2..5a55619b3 100644 --- a/source/glest_game/game/console.h +++ b/source/glest_game/game/console.h @@ -48,7 +48,7 @@ namespace using Shared::Graphics::FontChangedCallbackInterface; using - Shared::Graphics::Vec3f; + Shared::Graphics::Vec4f; // ===================================================== // class Console // @@ -66,7 +66,7 @@ namespace PlayerIndex; string originalPlayerName; - Vec3f + Vec4f color; bool teamMode; @@ -254,14 +254,14 @@ namespace addLineOnly(const string & line); void addLine(const string & line, bool playSound = false, int playerIndex = - -1, Vec3f textColor = Vec3f(1.f, 1.f, 1.f), bool teamMode = + -1, Vec4f textColor = Vec4f(1.f, 1.f, 1.f, 1.f), bool teamMode = false, bool clearOtherLines = false); void addLine(const string & line, bool playSound, const string & playerName, - Vec3f textColor = Vec3f(1.f, 1.f, 1.f), bool teamMode = + Vec4f textColor = Vec4f(1.f, 1.f, 1.f, 1.f), bool teamMode = false); void - addLine(const string & line, bool playSound, Vec3f textColor) { + addLine(const string & line, bool playSound, Vec4f textColor) { addLine(line, playSound, "", textColor, false); } void diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 8b8569f0f..b48be8df6 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -7715,14 +7715,10 @@ namespace Glest { if (Renderer::renderText3DEnabled == true) { renderer.renderText3D(scriptManager.getDisplayText(), - coreData.getMenuFontNormal3D(), - Vec3f(fontColor.x, fontColor.y, - fontColor.z), 200, 660, false); + coreData.getMenuFontNormal3D(), fontColor, 200, 660, false); } else { renderer.renderText(scriptManager.getDisplayText(), - coreData.getMenuFontNormal(), - Vec3f(fontColor.x, fontColor.y, - fontColor.z), 200, 660, false); + coreData.getMenuFontNormal(), fontColor, 200, 660, false); } } @@ -7808,16 +7804,12 @@ namespace Glest { for (int i = 0; i < world.getFactionCount(); ++i) { string factionInfo = factionDebugInfo[i]; - Vec3f - playerColor = - world.getFaction(i)->getTexture()-> - getPixmapConst()->getPixel3f(0, 0); + Vec4f playerColor = world.getFaction(i)->getTexture()->getPixmapConst()->getPixel4f(0, 0); if (Renderer::renderText3DEnabled == true) { renderer.renderText3D(factionInfo, coreData.getMenuFontBig3D(), - Vec4f(playerColor.x, playerColor.y, - playerColor.z, 1.0), 10, + playerColor, 10, //metrics.getVirtualH() - mh - 90 - 280 - (i * 16), metrics.getVirtualH() - mh - 60 - playerPosY - fontHeightBig - @@ -7825,8 +7817,7 @@ namespace Glest { } else { renderer.renderText(factionInfo, coreData.getMenuFontBig(), - Vec4f(playerColor.x, playerColor.y, - playerColor.z, 1.0), 10, + playerColor, 10, //metrics.getVirtualH() - mh - 90 - 280 - (i * 16), metrics.getVirtualH() - mh - 60 - playerPosY - fontHeightBig - @@ -7842,10 +7833,10 @@ namespace Glest { if (Renderer::renderText3DEnabled == true) { renderer.renderUnitTitles3D(coreData.getMenuFontNormal3D(), - Vec3f(1.0f)); + Vec4f(1.0f)); } else { renderer.renderUnitTitles(coreData.getMenuFontNormal(), - Vec3f(1.0f)); + Vec4f(1.0f)); } } } diff --git a/source/glest_game/game/stats.cpp b/source/glest_game/game/stats.cpp index 8094f5043..f5e8c3584 100644 --- a/source/glest_game/game/stats.cpp +++ b/source/glest_game/game/stats.cpp @@ -31,7 +31,7 @@ namespace Glest { //playerName = ""; playerLeftBeforeEnd = false; timePlayerLeft = -1; - playerColor = Vec3f(0, 0, 0); + playerColor = Vec4f(0, 0, 0, 1); } string PlayerStats::getStats() const { @@ -222,7 +222,7 @@ namespace Glest { // string playerName; statsNodePlayer->addAttribute("playerName", stat.playerName, mapTagReplacements); - // Vec3f playerColor; + // Vec4f playerColor; statsNodePlayer->addAttribute("playerColor", stat.playerColor.getString(), mapTagReplacements); @@ -312,9 +312,9 @@ namespace Glest { // string playerName; stat.playerName = statsNodePlayer->getAttribute("playerName")->getValue(); - // Vec3f playerColor; + // Vec4f playerColor; stat.playerColor = - Vec3f::strToVec3(statsNodePlayer->getAttribute("playerColor")-> + Vec4f::strToVec4(statsNodePlayer->getAttribute("playerColor")-> getValue()); } // string description; diff --git a/source/glest_game/game/stats.h b/source/glest_game/game/stats.h index 0f2b81153..5f17a4330 100644 --- a/source/glest_game/game/stats.h +++ b/source/glest_game/game/stats.h @@ -67,7 +67,7 @@ namespace playerLeftBeforeEnd; int timePlayerLeft; - Vec3f + Vec4f playerColor; string @@ -253,7 +253,7 @@ namespace setPlayerLeftBeforeEnd(int factionIndex, bool value) { playerStats[factionIndex].playerLeftBeforeEnd = value; } - Vec3f + Vec4f getPlayerColor(int factionIndex) const { return playerStats[factionIndex]. @@ -339,7 +339,7 @@ namespace playerStats[playerIndex].playerName = value; } void - setPlayerColor(int playerIndex, Vec3f value) { + setPlayerColor(int playerIndex, Vec4f value) { playerStats[playerIndex].playerColor = value; } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 49c377193..3b8be8570 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -65,16 +65,12 @@ namespace Glest { //set color to interpolation glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE1); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); - //set alpha to 1 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); @@ -96,10 +92,14 @@ namespace Glest { glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); - //set alpha to 1 - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PRIMARY_COLOR); + //Interpolate alpha with alpha of previous texture + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); + glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); + glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); glActiveTexture(GL_TEXTURE0); } else { @@ -1615,7 +1615,8 @@ namespace Glest { if (downPos != Display::invalidPos) { // in state of doing something const Texture2D *texture = display->getDownImage(downPos); - renderTextureQuad(x + 18, y - 50, 32, 32, texture, 0.8f); + Vec4f color = Vec4f(1.f, 1.f, 1.f, 0.8f); + renderTextureQuad(x + 18, y - 50, 32, 32, texture, &color); } // else { // // Display current commandtype @@ -1632,14 +1633,14 @@ namespace Glest { // } // } // } - + Vec4f color = Vec4f(1.f, 1.f, 1.f, 0.8f); if (game->isMarkCellMode() == true) { const Texture2D *texture = game->getMarkCellTexture(); - renderTextureQuad(x, y, texture->getTextureWidth(), texture->getTextureHeight(), texture, 0.8f); + renderTextureQuad(x, y, texture->getTextureWidth(), texture->getTextureHeight(), texture, &color); } if (game->isUnMarkCellMode() == true) { const Texture2D *texture = game->getUnMarkCellTexture(); - renderTextureQuad(x, y, texture->getTextureWidth(), texture->getTextureHeight(), texture, 0.8f); + renderTextureQuad(x, y, texture->getTextureWidth(), texture->getTextureHeight(), texture, &color); } } @@ -1837,7 +1838,7 @@ namespace Glest { assertGl(); } - void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha, const Vec3f *color) { + void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, const Vec4f *color) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -1851,11 +1852,9 @@ namespace Glest { glEnable(GL_BLEND); if (color != NULL) { - Vec4f newColor(*color); - newColor.w = alpha; - glColor4fv(newColor.ptr()); + glColor4fv(color->ptr()); } else { - glColor4f(1.f, 1.f, 1.f, alpha); + glColor4f(1.f, 1.f, 1.f, 1.f); } renderQuad(x, y, w, h, texture); @@ -1887,10 +1886,8 @@ namespace Glest { if (lineInfo->PlayerIndex >= 0) { std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); - Vec3f playerColor = crcPlayerTextureCache[lineInfo->PlayerIndex]->getPixmap()->getPixel3f(0, 0); - fontColor.x = playerColor.x; - fontColor.y = playerColor.y; - fontColor.z = playerColor.z; + Vec4f playerColor = crcPlayerTextureCache[lineInfo->PlayerIndex]->getPixmap()->getPixel4f(0, 0); + fontColor = playerColor; GameNetworkInterface *gameNetInterface = NetworkManager::getInstance().getGameNetworkInterface(); if (gameNetInterface != NULL && gameNetInterface->getGameSettings() != NULL) { @@ -1991,10 +1988,8 @@ namespace Glest { if (lineInfo->PlayerIndex >= 0) { std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); - Vec3f playerColor = crcPlayerTextureCache[lineInfo->PlayerIndex]->getPixmap()->getPixel3f(0, 0); - fontColor.x = playerColor.x; - fontColor.y = playerColor.y; - fontColor.z = playerColor.z; + Vec4f playerColor = crcPlayerTextureCache[lineInfo->PlayerIndex]->getPixmap()->getPixel4f(0, 0); + fontColor = playerColor; GameNetworkInterface *gameNetInterface = NetworkManager::getInstance().getGameNetworkInterface(); if (gameNetInterface != NULL && gameNetInterface->getGameSettings() != NULL) { @@ -2541,7 +2536,7 @@ namespace Glest { //draw resource status if (localFactionResourcesOnly == true) { - Vec4f resourceFontColor = Vec4f(factionForResourceView->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + Vec4f resourceFontColor = factionForResourceView->getTexture()->getPixmapConst()->getPixel4f(0, 0); int resourceCol = 0; int resourceRow = startRow; @@ -2549,7 +2544,7 @@ namespace Glest { int y = resourceYStart - (resourceRowHeigth * resourceRow); int h = 16; int w = 8; - glColor3f(resourceFontColor.x, resourceFontColor.y, resourceFontColor.z); + glColor4f(resourceFontColor.x, resourceFontColor.y, resourceFontColor.z, resourceFontColor.w); glBegin(GL_TRIANGLE_STRIP); glVertex2i(x, y + h); glVertex2i(x, y); @@ -3177,34 +3172,24 @@ namespace Glest { glPopAttrib(); } } - Vec3f labelColor = label->getTextColor(); - Vec4f colorWithAlpha = Vec4f(labelColor.x, labelColor.y, labelColor.z, GraphicComponent::getFade()); - renderLabel(label, &colorWithAlpha); + Vec4f labelColor = label->getTextColor(); + renderLabel(label, &labelColor); } - void Renderer::renderLabel(GraphicLabel *label, const Vec3f *color) { + void Renderer::renderLabel(GraphicLabel *label, const Vec4f *colorWithAlpha) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } - - if (color != NULL) { - Vec4f colorWithAlpha = Vec4f(*color); - colorWithAlpha.w = GraphicComponent::getFade(); - renderLabel(label, &colorWithAlpha); - } else { - Vec4f *colorWithAlpha = NULL; - renderLabel(label, colorWithAlpha); - } - } - - void Renderer::renderLabel(GraphicLabel *label, const Vec4f *color) { - if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { - return; - } - if (label->getVisible() == false) { return; } + Vec4f clr; + const Vec4f *color = NULL; + if (colorWithAlpha != NULL) { + clr = *colorWithAlpha; + clr.w *= GraphicComponent::getFade(); + color = &clr; + } try { glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); @@ -3324,13 +3309,13 @@ namespace Glest { } //button - Vec4f fontColor(GraphicComponent::getCustomTextColor()); + Vec4f fontColor = WHITE; if (fontColorOverride != NULL) { fontColor = *fontColorOverride; } else { // white shadowed is default ( in the menu for example ) - fontColor.w = GraphicComponent::getFade(); + fontColor.w *= GraphicComponent::getFade(); } //Vec4f color= Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade()); @@ -3766,15 +3751,15 @@ namespace Glest { float anim = GraphicComponent::getAnim(); if (anim > 0.5f) anim = 1.f - anim; - Vec3f color = listBox->getTextColor(); + Vec4f color = listBox->getTextColor(); int x = listBox->getX() + listBox->getButton1()->getW(); int y = listBox->getY(); int h = listBox->getH(); int w = listBox->getW() - listBox->getButton1()->getW() - listBox->getButton2()->getW(); const int lightSize = 0; - const Vec4f color1 = Vec4f(color.x, color.y, color.z, 0.1f + anim * 0.5f); - const Vec4f color2 = Vec4f(color.x, color.y, color.z, 0.3f + anim); + const Vec4f color1 = Vec4f(color.x, color.y, color.z, color.w * (0.1f + anim * 0.5f)); + const Vec4f color2 = Vec4f(color.x, color.y, color.z, color.w * (0.3f + anim)); glBegin(GL_TRIANGLE_FAN); @@ -5094,8 +5079,8 @@ namespace Glest { visibleUnitIndex < (int) qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; Vec3f currVec = unit->getCurrVectorFlat(); - Vec3f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); - glColor4f(color.x, color.y, color.z, 0.7f); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + glColor4f(color.x, color.y, color.z, color.w * 0.7f); renderSelectionCircle(currVec, unit->getType()->getSize(), 0.8f, 0.05f); } glPopAttrib(); @@ -5125,20 +5110,14 @@ namespace Glest { std::map::iterator iterFindSpecialUnit = unitHighlightList.find(unit->getId()); if (iterFindSpecialUnit != unitHighlightList.end()) { - Vec3f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); float radius = 1.0f; float thickness = 0.1f; - float alpha = 0.65f; + color.w *= 0.65f; HighlightSpecialUnitInfo &specialInfo = iterFindSpecialUnit->second; - if (specialInfo.color.x >= 0) { - color.x = specialInfo.color.x; - color.y = specialInfo.color.y; - color.z = specialInfo.color.z; - } - if (specialInfo.color.w >= 0) { - alpha = specialInfo.color.w; - } + if (specialInfo.color.x >= 0) + color = specialInfo.color; if (specialInfo.radius > 0) { radius = specialInfo.radius; } @@ -5146,7 +5125,7 @@ namespace Glest { thickness = specialInfo.thickness; } - glColor4f(color.x, color.y, color.z, alpha); + glColor4f(color.x, color.y, color.z, color.w); Vec3f currVec = unit->getCurrVectorFlat(); renderSelectionCircle(currVec, unit->getType()->getSize(), radius, thickness); @@ -5175,7 +5154,7 @@ namespace Glest { if (unit->isAlive()) { Vec3f currVec = unit->getCurrVectorFlat(); renderTeamColorEffect(currVec, visibleUnitIndex, unit->getType()->getSize(), - unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0), texture); + unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0), texture); } } glDisable(GL_COLOR_MATERIAL); @@ -5383,8 +5362,8 @@ namespace Glest { visibleUnitIndex < (int) qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) { const UnitBuildInfo &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex]; //Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f); - const Vec3f teamColor = buildUnit.unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); - Vec4f modelColor = Vec4f(teamColor.x, teamColor.y, teamColor.z, 0.4f); + const Vec4f teamColor = buildUnit.unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + Vec4f modelColor = Vec4f(teamColor.x, teamColor.y, teamColor.z, teamColor.w * 0.4f); renderGhostModel(buildUnit.buildUnit, buildUnit.pos, buildUnit.facing, &modelColor); //printf("Rendering to build unit index = %d\n",visibleUnitIndex); @@ -5401,7 +5380,7 @@ namespace Glest { } - void Renderer::renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture) { + void Renderer::renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec4f color, const Texture2D *texture) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -5412,7 +5391,7 @@ namespace Glest { float heigthoffset = 0.5 + heigth % 25 * 0.004; glPushMatrix(); glBindTexture(GL_TEXTURE_2D, static_cast(texture)->getHandle()); - glColor4f(color.x, color.y, color.z, 1.0f); + glColor4f(color.x, color.y, color.z, color.w); glBegin(GL_TRIANGLE_STRIP); glTexCoord2i(0, 1); glVertex3f(v.x - halfSize, v.y + heigthoffset, v.z + halfSize); @@ -5609,7 +5588,7 @@ namespace Glest { map->clampPos(pos); Vec3f arrowTarget = Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y); - renderArrow(unit->getCurrVectorFlat(), arrowTarget, Vec3f(0.f, 0.f, 1.f), 0.3f); + renderArrow(unit->getCurrVectorFlat(), arrowTarget, Vec4f(0.f, 0.f, 1.f, 0.8f), 0.3f); } } } @@ -5631,17 +5610,17 @@ namespace Glest { if (ct->getClicks() != cOne) { //arrow color - Vec3f arrowColor; + Vec4f arrowColor; switch (ct->getClass()) { case ccMove: - arrowColor = Vec3f(0.f, 1.f, 0.f); + arrowColor = Vec4f(0.f, 1.f, 0.f, 0.8f); break; case ccAttack: case ccAttackStopped: - arrowColor = Vec3f(1.f, 0.f, 0.f); + arrowColor = Vec4f(1.f, 0.f, 0.f, 0.8f); break; default: - arrowColor = Vec3f(1.f, 1.f, 0.f); + arrowColor = Vec4f(1.f, 1.f, 0.f, 0.8f); break; } @@ -5932,7 +5911,7 @@ namespace Glest { Texture2D *hudTexture = game->getGui()->getHudTexture(); if (hudTexture != NULL) { const Metrics &metrics = Metrics::getInstance(); - renderTextureQuad(0, 0, metrics.getVirtualW(), metrics.getVirtualH(), hudTexture, 1.0f); + renderTextureQuad(0, 0, metrics.getVirtualW(), metrics.getVirtualH(), hudTexture, NULL); } } @@ -6185,7 +6164,7 @@ namespace Glest { uint32 unitIdx = 0; vector unit_vertices; unit_vertices.resize(visibleUnitList.size() * 4); - vector unit_colors; + vector unit_colors; unit_colors.resize(visibleUnitList.size() * 4); for (int visibleIndex = 0; @@ -6197,7 +6176,7 @@ namespace Glest { Vec2i pos = unit->getPos() / Map::cellScale; int size = unit->getType()->getSize(); - Vec3f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + pos.x*zoom.x, my + mh - (pos.y*zoom.y)); @@ -6217,9 +6196,10 @@ namespace Glest { } if (unitIdx > 0) { + glEnable(GL_BLEND); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); - glColorPointer(3, GL_FLOAT, 0, &unit_colors[0]); + glColorPointer(4, GL_FLOAT, 0, &unit_colors[0]); glVertexPointer(2, GL_FLOAT, 0, &unit_vertices[0]); glDrawArrays(GL_QUADS, 0, unitIdx); glDisableClientState(GL_COLOR_ARRAY); @@ -6300,18 +6280,17 @@ namespace Glest { const MarkedCell *mc = &highlightedCells->at(i); if (mc->getFaction() == NULL || (mc->getFaction()->getTeam() == game->getWorld()->getThisFaction()->getTeam())) { const Texture2D *texture = game->getHighlightCellTexture(); - Vec3f color(MarkedCell::static_system_marker_color); + Vec4f color = MarkedCell::static_system_marker_color; if (mc->getFaction() != NULL) { - color = mc->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); + color = mc->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); } int lighting = (mc->getAliveCount() % 15); - Vec3f myColor = Vec3f(color.x / 2 + .5f / lighting, color.y / 2 + .5f / lighting, color.z / 2 + .5f / lighting); + color = Vec4f(color.x / 2 + .5f / lighting, color.y / 2 + .5f / lighting, color.z / 2 + .5f / lighting, color.w); Vec2i pos = mc->getTargetPos(); if (texture != NULL) { //float alpha = 0.49f+0.5f/(mc->getAliveCount()%15); - float alpha = 1.0f; - renderTextureQuad((int) (pos.x*zoom.x) + pointersize, my + mh - (int) (pos.y*zoom.y), pointersize, pointersize, texture, alpha, &myColor); + renderTextureQuad((int) (pos.x*zoom.x) + pointersize, my + mh - (int) (pos.y*zoom.y), pointersize, pointersize, texture, &color); } } } @@ -6359,25 +6338,25 @@ namespace Glest { Vec2i pos = bm.getTargetPos() / Map::cellScale; float size = 0.5f; - Vec3f color(MarkedCell::static_system_marker_color); + Vec4f color = MarkedCell::static_system_marker_color; if (bm.getFaction() != NULL) { - color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); + color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); } - float alpha = 0.65f; + color.w *= 0.65f; - unit_colors[unitIdx] = Vec4f(color.x, color.y, color.z, alpha); + unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + pos.x*zoom.x, my + mh - (pos.y*zoom.y)); unitIdx++; - unit_colors[unitIdx] = Vec4f(color.x, color.y, color.z, alpha); + unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + (pos.x + 1)*zoom.x + size, my + mh - (pos.y*zoom.y)); unitIdx++; - unit_colors[unitIdx] = Vec4f(color.x, color.y, color.z, alpha); + unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + (pos.x + 1)*zoom.x + size, my + mh - ((pos.y + size)*zoom.y)); unitIdx++; - unit_colors[unitIdx] = Vec4f(color.x, color.y, color.z, alpha); + unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + pos.x*zoom.x, my + mh - ((pos.y + size)*zoom.y)); unitIdx++; } @@ -6494,14 +6473,14 @@ namespace Glest { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Vec3f color(MarkedCell::static_system_marker_color); + Vec4f color = MarkedCell::static_system_marker_color; if (bm.getFaction() != NULL) { - color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0); + color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); } - + color.w *= 0.8f; renderTextureQuad( bmVisible.second.x, bmVisible.second.y + yOffset, - texture->getTextureWidth(), texture->getTextureHeight(), texture, 0.8f, &color); + texture->getTextureWidth(), texture->getTextureHeight(), texture, &color); /* glActiveTexture(GL_TEXTURE1); @@ -8613,8 +8592,7 @@ namespace Glest { // glEnd(); } - void Renderer::renderArrow(const Vec3f &pos1, const Vec3f &pos2, - const Vec3f &color, float width) { + void Renderer::renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec4f &color, float width) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -8651,7 +8629,8 @@ namespace Glest { float t = static_cast(i) / tesselation; Vec3f a = pos1Left.lerp(t, pos2Left); Vec3f b = pos1Right.lerp(t, pos2Right); - Vec4f c = Vec4f(color, t*0.25f*alphaFactor); + Vec4f c = color; + c.w *= t * 0.25f * alphaFactor; glColor4fv(c.ptr()); @@ -8904,7 +8883,7 @@ namespace Glest { } // This method renders titles for units - void Renderer::renderUnitTitles3D(Font3D *font, Vec3f color) { + void Renderer::renderUnitTitles3D(Font3D *font, Vec4f color) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -8957,7 +8936,7 @@ namespace Glest { } // This method renders titles for units - void Renderer::renderUnitTitles(Font2D *font, Vec3f color) { + void Renderer::renderUnitTitles(Font2D *font, Vec4f color) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -9644,7 +9623,7 @@ namespace Glest { Vec2f *vertices = new Vec2f[map->getMaxFactions() * 4]; Vec3f *colors = new Vec3f[map->getMaxFactions() * 4]; - + for (int i = 0; i < map->getMaxFactions(); i++) { Vec3f color; switch (i) { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 6a02cbccb..00ee3e5ce 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -523,7 +523,7 @@ namespace Glest { void renderGhostModel(const UnitType *building, const Vec2i pos, CardinalDir facing, Vec4f *forceColor = NULL); void renderBackground(const Texture2D *texture); - void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha = 1.f, const Vec3f *color = NULL); + void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, const Vec4f *color = NULL); void renderConsole(const Console *console, ConsoleMode mode = consoleNormal, int overrideMaxConsoleLines = -1); void renderConsoleLine3D(int lineIndex, int xPosition, int yPosition, int lineHeight, Font3D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo); void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo); @@ -558,7 +558,6 @@ namespace Glest { //components void renderLabel(GraphicLabel *label); - void renderLabel(GraphicLabel *label, const Vec3f *color); void renderLabel(GraphicLabel *label, const Vec4f *color); void renderButton(GraphicButton *button, const Vec4f *fontColorOverride = NULL, bool *lightedOverride = NULL); void renderCheckBox(const GraphicCheckBox *box); @@ -632,8 +631,8 @@ namespace Glest { inline bool getAllowRenderUnitTitles() { return allowRenderUnitTitles; } - void renderUnitTitles(Font2D *font, Vec3f color); - void renderUnitTitles3D(Font3D *font, Vec3f color); + void renderUnitTitles(Font2D *font, Vec4f color); + void renderUnitTitles3D(Font3D *font, Vec4f color); Vec3f computeScreenPosition(const Vec3f &worldPos); void setPhotoMode(bool value) { @@ -744,8 +743,8 @@ namespace Glest { bool isHealthBarVisible(const Unit *unit, int healthbarMode); void renderHealthBar(Vec3f v, Unit *unit, float height, bool lineBorder, const Texture2D *texture = NULL, const Texture2D *backgroundTexture = NULL); void internalRenderHp(int numberOfBars, int barNumber, float hp, Vec3f posVector, float width, float singleHPheight, Vec3f rightVector, Vec3f upVector); - void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture); - void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width); + void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec4f color, const Texture2D *texture); + void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec4f &color, float width); //void renderTile(const Vec2i &pos); void renderQuad(int x, int y, int w, int h, const Texture2D *texture); diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index 315edaf1d..5faa15e09 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -714,14 +714,12 @@ namespace Glest { if (score == bestScore && stats.getVictory(i)) { if (CoreData::getInstance().getGameWinnerTexture() != NULL) { - renderer.renderTextureQuad(textX, bm + 420, -1, -1, - CoreData:: - getInstance().getGameWinnerTexture - (), 0.7f); + Vec4f color = Vec4f(1.f, 1.f, 1.f, 0.7f); + renderer.renderTextureQuad(textX, bm + 420, -1, -1, CoreData::getInstance().getGameWinnerTexture(), &color); } } - Vec3f color = stats.getPlayerColor(i); + Vec4f color = stats.getPlayerColor(i); if (stats.getPlayerName(i) != "") { string textToRender = stats.getPlayerName(i).substr(0, 11); if (stats.getPlayerLeftBeforeEnd(i) == true) { @@ -738,7 +736,7 @@ namespace Glest { bm + 400, false, &color); } - Vec3f highliteColor = Vec3f(WHITE.x, WHITE.y, WHITE.z); + Vec4f highliteColor = Vec4f(WHITE.x, WHITE.y, WHITE.z, WHITE.w); if (disableStatsColorCoding == false) { highliteColor.x = 0.85f; highliteColor.y = 0.8f; diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index fb0dfdd5c..c7b966c52 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -902,10 +902,11 @@ namespace Glest { } if (text->getTexture() != NULL) { + Vec4f color = Vec4f(1.f, 1.f, 1.f, alpha); renderer.renderTextureQuad(text->getPos().x, text->getPos().y, text->getSize().x, text->getSize().y, - text->getTexture(), alpha); + text->getTexture(), &color); } } } diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 955dfe46f..75e970883 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -79,15 +79,15 @@ namespace "In [%s::%s %d]\n", __FILE__, __FUNCTION__, __LINE__); - Config & + /*Config & config = Config::getInstance(); if (config.getString("CustomMenuTextColor", "") != "") { string customMenuTextColor = config.getString("CustomMenuTextColor"); Vec3f customTextColor = Vec3f::strToVec3(customMenuTextColor); - GraphicComponent::setCustomTextColor(customTextColor); - } + GraphicComponent::setCustomTextColor(Vec4f(customTextColor)); + }*/ setState(new MenuStateRoot(program, this)); @@ -143,7 +143,6 @@ namespace //SoundRenderer &soundRenderer= SoundRenderer::getInstance(); //soundRenderer.stopAllSounds(); - GraphicComponent::setCustomTextColor(Vec3f(1.0f, 1.0f, 1.0f)); if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem). enabled) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 42069e363..2ebfa6d38 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -233,7 +233,7 @@ namespace Glest { getMenuFontBig()); labelWaitingForPlayers.setFont3D(CoreData::getInstance(). getMenuFontBig3D()); - labelWaitingForPlayers.setTextColor(Vec3f(1.0f, 1.0f, 0.f)); + labelWaitingForPlayers.setTextColor(Vec4f(1.0f, 1.0f, 0.f, 1.0f)); timerLabelFlash = time(NULL); labelDataSynchInfo.registerGraphicComponent(containerName, @@ -625,7 +625,7 @@ namespace Glest { listBoxPlayerStatus.registerGraphicComponent(containerName, "listBoxPlayerStatus"); listBoxPlayerStatus.init(buttonx, buttony, 165); - listBoxPlayerStatus.setTextColor(Vec3f(1.0f, 0.f, 0.f)); + listBoxPlayerStatus.setTextColor(Vec4f(1.0f, 0.f, 0.f, 1.0f)); listBoxPlayerStatus.setLighted(true); playerStatuses.push_back(lang.getString("PlayerStatusSetup")); playerStatuses.push_back(lang.getString("PlayerStatusBeRightBack")); @@ -2259,13 +2259,13 @@ namespace Glest { __LINE__); if (getNetworkPlayerStatus() == npst_PickSettings) { - listBoxPlayerStatus.setTextColor(Vec3f(1.0f, 0.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(true); } else if (getNetworkPlayerStatus() == npst_BeRightBack) { - listBoxPlayerStatus.setTextColor(Vec3f(1.0f, 1.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(true); } else if (getNetworkPlayerStatus() == npst_Ready) { - listBoxPlayerStatus.setTextColor(Vec3f(0.0f, 1.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(false); } @@ -3583,8 +3583,7 @@ namespace Glest { if (factionTexture != NULL) { if (factionVideo == NULL || factionVideo->isPlaying() == false) { - renderer.renderTextureQuad(800, 600, 200, 150, factionTexture, - 1); + renderer.renderTextureQuad(800, 600, 200, 150, factionTexture, NULL); } } if (factionVideo != NULL) { @@ -3613,7 +3612,7 @@ namespace Glest { this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_W, this->render_mapPreviewTexture_H, - mapPreviewTexture, 1.0f); + mapPreviewTexture, NULL); if (this->zoomedMap == true) { return; } @@ -3621,8 +3620,7 @@ namespace Glest { } if (scenarioLogoTexture != NULL) { - renderer.renderTextureQuad(300, 350, 400, 300, scenarioLogoTexture, - 1.0f); + renderer.renderTextureQuad(300, 350, 400, 300, scenarioLogoTexture, NULL); //renderer.renderBackground(scenarioLogoTexture); } @@ -3701,9 +3699,9 @@ namespace Glest { if (crcPlayerTextureCache[i] != NULL) { // Render the player # label the player's color - Vec3f + Vec4f playerColor = - crcPlayerTextureCache[i]->getPixmap()->getPixel3f(0, 0); + crcPlayerTextureCache[i]->getPixmap()->getPixel4f(0, 0); if (clientInterface != NULL && clientInterface->getGameSettings() != NULL && clientInterface-> @@ -3745,11 +3743,11 @@ namespace Glest { renderer.renderListBox(&listBoxFactions[i]); int teamnumber = listBoxTeams[i].getSelectedItemIndex(); - Vec3f teamcolor = Vec3f(1.0f, 1.0f, 1.0f); + Vec4f teamcolor = Vec4f(1.0f, 1.0f, 1.0f, 1.0f); if (teamnumber >= 0 && teamnumber < 8) { teamcolor = crcPlayerTextureCache[teamnumber]-> - getPixmap()->getPixel3f(0, 0); + getPixmap()->getPixel4f(0, 0); } listBoxTeams[i].setTextColor(teamcolor); renderer.renderListBox(&listBoxTeams[i]); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 9076ac433..f52c7fa1c 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -257,7 +257,7 @@ namespace Glest { playerStatuses.push_back(lang.getString("PlayerStatusReady")); listBoxPlayerStatus.setItems(playerStatuses); listBoxPlayerStatus.setSelectedItemIndex(2, true); - listBoxPlayerStatus.setTextColor(Vec3f(0.0f, 1.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(false); listBoxPlayerStatus.setVisible(true); buttonx += 180; @@ -2232,13 +2232,13 @@ namespace Glest { soundRenderer.playFx(coreData.getClickSoundC()); if (getNetworkPlayerStatus() == npst_PickSettings) { - listBoxPlayerStatus.setTextColor(Vec3f(1.0f, 0.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(true); } else if (getNetworkPlayerStatus() == npst_BeRightBack) { - listBoxPlayerStatus.setTextColor(Vec3f(1.0f, 1.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(true); } else if (getNetworkPlayerStatus() == npst_Ready) { - listBoxPlayerStatus.setTextColor(Vec3f(0.0f, 1.0f, 0.0f)); + listBoxPlayerStatus.setTextColor(Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); listBoxPlayerStatus.setLighted(false); } @@ -2835,8 +2835,7 @@ namespace Glest { if (mainMessageBox.getEnabled() == false) { if (factionTexture != NULL) { if (factionVideo == NULL || factionVideo->isPlaying() == false) { - renderer.renderTextureQuad(800, 600, 200, 150, - factionTexture, 1.0f); + renderer.renderTextureQuad(800, 600, 200, 150, factionTexture, NULL); } } } @@ -2874,7 +2873,7 @@ namespace Glest { this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_W, this->render_mapPreviewTexture_H, - mapPreviewTexture, 1.0f); + mapPreviewTexture, NULL); if (this->zoomedMap == true) { return; } @@ -2882,7 +2881,7 @@ namespace Glest { } if (scenarioLogoTexture != NULL) { renderer.renderTextureQuad(300, 350, 400, 300, - scenarioLogoTexture, 1.0f); + scenarioLogoTexture, NULL); //renderer.renderBackground(scenarioLogoTexture); } @@ -2951,8 +2950,8 @@ namespace Glest { if (crcPlayerTextureCache[i] != NULL) { // Render the player # label the player's color - Vec3f playerColor = - crcPlayerTextureCache[i]->getPixmap()->getPixel3f(0, + Vec4f playerColor = + crcPlayerTextureCache[i]->getPixmap()->getPixel4f(0, 0); renderer.renderLabel(&labelPlayers[i], &playerColor); } else { @@ -2990,11 +2989,11 @@ namespace Glest { renderer.renderListBox(&listBoxFactions[i]); int teamnumber = listBoxTeams[i].getSelectedItemIndex(); - Vec3f teamcolor = Vec3f(1.0f, 1.0f, 1.0f); + Vec4f teamcolor = Vec4f(1.0f, 1.0f, 1.0f, 1.0f); if (teamnumber >= 0 && teamnumber < 8) { teamcolor = crcPlayerTextureCache[teamnumber]-> - getPixmap()->getPixel3f(0, 0); + getPixmap()->getPixel4f(0, 0); } listBoxTeams[i].setTextColor(teamcolor); diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp index 66be69b07..5f694137a 100644 --- a/source/glest_game/menu/menu_state_load_game.cpp +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -103,7 +103,7 @@ namespace Glest { "versionWarningLabel"); versionWarningLabel.init(550, 350); versionWarningLabel.setText(""); - versionWarningLabel.setTextColor(Vec3f(1.0f, 0.5f, 0.5f)); + versionWarningLabel.setTextColor(Vec4f(1.0f, 0.5f, 0.5f, 1.0f)); infoTextLabel.registerGraphicComponent(containerName, "infoTextLabel"); @@ -497,7 +497,7 @@ namespace Glest { if (previewTexture != NULL) { renderer.renderTextureQuad(550, slotLinesYBase - 300 + slotsLineHeight, - 400, 300, previewTexture, 1.0f); + 400, 300, previewTexture, NULL); } if (mainMessageBox.getEnabled()) { diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index bd07f3e20..9598b36e3 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -1274,7 +1274,7 @@ namespace Glest { //announcementLabel.setText(announcementTxt); consoleIRC.addLine(announcementTxt, true, - Vec3f(1.0f, 1.0f, 0.0f)); + Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); while (true) { lastIndex = announcementTxt.find("\n", lastIndex + 1); @@ -1314,7 +1314,7 @@ namespace Glest { //versionInfoLabel.setText(versionTxt); consoleIRC.addLine(versionTxt, true, - Vec3f(1.0f, 0.0f, 0.0f)); + Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); while (true) { lastIndex = versionTxt.find("\n", lastIndex + 1); diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index 70b873a03..93992cebc 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -2824,8 +2824,7 @@ namespace Glest { } } if (modPreviewImage != NULL) { - renderer.renderTextureQuad(508, 90, 485, 325, modPreviewImage, - 1.0f); + renderer.renderTextureQuad(508, 90, 485, 325, modPreviewImage, NULL); } } } @@ -3126,8 +3125,7 @@ namespace Glest { } if (validMapPreview) { if (mapPreviewTexture != NULL) { - renderer.renderTextureQuad(5, 185, 150, 150, mapPreviewTexture, - 1.0f); + renderer.renderTextureQuad(5, 185, 150, 150, mapPreviewTexture, NULL); } if (enableMapPreview && (mapPreview.hasFileLoaded() == true)) { diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index 9b7b48fca..344d2651c 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -668,10 +668,9 @@ namespace Glest { logoMainH = Config::getInstance().getInt(string(containerName) + "_MainLogo_h", intToStr(logoMainH).c_str()); - + Vec4f color = Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade()); renderer.renderTextureQuad(logoMainX, logoMainY, logoMainW, logoMainH, - coreData.getLogoTexture(), - GraphicComponent::getFade()); + coreData.getLogoTexture(), &color); int maxLogoWidth = 0; for (int idx = 0; idx < (int) coreData.getLogoTextureExtraCount(); @@ -705,10 +704,10 @@ namespace Glest { logoMainH = Config::getInstance().getInt(logoTagName + "h", intToStr(logoMainH).c_str()); - + Vec4f color = Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade()); renderer.renderTextureQuad(logoMainX, logoMainY, logoMainW, logoMainH, - extraLogo, GraphicComponent::getFade()); + extraLogo, &color); currentX += extraLogo->getPixmap()->getW(); } diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 9e7aa3c77..1398feaf4 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -339,8 +339,7 @@ namespace Glest { Renderer & renderer = Renderer::getInstance(); if (scenarioLogoTexture != NULL) { - renderer.renderTextureQuad(450, 200, 533, 400, scenarioLogoTexture, - 1.0f); + renderer.renderTextureQuad(450, 200, 533, 400, scenarioLogoTexture, NULL); //renderer.renderBackground(scenarioLogoTexture); } diff --git a/source/glest_game/menu/server_line.cpp b/source/glest_game/menu/server_line.cpp index 9650b1c98..137b8d3a1 100644 --- a/source/glest_game/menu/server_line.cpp +++ b/source/glest_game/menu/server_line.cpp @@ -40,10 +40,10 @@ namespace Glest { masterServerInfo = *mServerInfo; int i = 5; this->baseY = baseY; - Vec3f color = Vec3f(1.0f, 1.0f, 1.0f); + Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f); if (masterServerInfo.getConnectedClients() == 0) { - color = Vec3f(0.6f, 0.7f, 1.0f); + color = Vec4f(0.6f, 0.7f, 1.0f, 1.0f); } @@ -139,7 +139,7 @@ namespace Glest { // i+=100; wrongVersionLabel.init(i, baseY - lineOffset); - wrongVersionLabel.setTextColor(Vec3f(1.0f, 0.0f, 0.0f)); + wrongVersionLabel.setTextColor(Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); wrongVersionLabel.setText(lang.getString("IncompatibleVersion")); //game setup info: @@ -270,10 +270,11 @@ namespace Glest { //game info: renderer.renderLabel(&serverTitleLabel); if (countryTexture != NULL) { + Vec4f color = Vec4f(1.f, 1.f, 1.f, 0.7f); renderer.renderTextureQuad(country.getX() + 1, country.getY() + 4, countryTexture->getTextureWidth(), countryTexture->getTextureHeight(), - countryTexture, 0.7f); + countryTexture, &color); } else { renderer.renderLabel(&country); } diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index be8a9aa35..59bfcd5d1 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -39,7 +39,7 @@ namespace Glest { bool NetworkInterface::allowDownloadDataSynch = false; DisplayMessageFunction NetworkInterface::pCB_DisplayMessage = NULL; - Vec3f MarkedCell::static_system_marker_color(MAGENTA.x, MAGENTA.y, MAGENTA.z); + Vec4f MarkedCell::static_system_marker_color = MAGENTA; NetworkInterface::NetworkInterface() { networkAccessMutex = new Mutex(CODE_AT_LINE); diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index 8b878e063..aed57f8f6 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -103,7 +103,7 @@ namespace Glest { int aliveCount; public: - static Vec3f static_system_marker_color; + static Vec4f static_system_marker_color; MarkedCell() { faction = NULL; diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 592d5d6e4..a9f380e4f 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -133,7 +133,7 @@ namespace Glest { (*it)->setValues(ups); ups->setPos(this->pos); ups->setRotation(this->rotation); - ups->setFactionColor(Vec3f(0, 0, 0)); + ups->setFactionColor(Vec4f(0, 0, 0, 1)); ups->setVisible(false); this->unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index ec84e760a..9e1e7d82f 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -399,7 +399,7 @@ namespace Glest { if (unit->getFaction()->getTexture()) { ups->setFactionColor(unit->getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } //printf("Adding attack boost particle to deferred buffer: %p\n",ups); Renderer:: @@ -3052,7 +3052,7 @@ namespace Glest { currentAttackBoostOriginatorEffect. currentAppliedEffect->ups-> setFactionColor(getFaction()->getTexture()-> - getPixmapConst()->getPixel3f(0, 0)); + getPixmapConst()->getPixel4f(0, 0)); } Renderer:: getInstance().manageParticleSystem @@ -3215,7 +3215,7 @@ namespace Glest { currentAppliedEffect->ups-> setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } Renderer:: getInstance().manageParticleSystem @@ -3557,7 +3557,7 @@ namespace Glest { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); @@ -3721,7 +3721,7 @@ namespace Glest { if (getFaction()->getTexture()) { effect->ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } Renderer::getInstance().manageParticleSystem(effect->ups, rsGame); @@ -5155,7 +5155,7 @@ namespace Glest { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); @@ -5344,7 +5344,7 @@ namespace Glest { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } damageParticleSystems.push_back(ups); damageParticleSystemsInUse[i] = ups; @@ -5381,7 +5381,7 @@ namespace Glest { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel3f(0, 0)); + getPixel4f(0, 0)); } damageParticleSystems.push_back(ups); damageParticleSystemsInUse[i] = ups; diff --git a/source/glest_game/types/object_type.cpp b/source/glest_game/types/object_type.cpp index c0d195841..4a4222c59 100644 --- a/source/glest_game/types/object_type.cpp +++ b/source/glest_game/types/object_type.cpp @@ -45,12 +45,12 @@ namespace Glest { Model *model = Renderer::getInstance().newModel(rsGame, path, false, loadedFileList, &parentLoader); - color = Vec3f(0.f); + color = Vec4f(0.f); if (model && model->getMeshCount() > 0 && model->getMesh(0)->getTexture(0) != NULL) { const Pixmap2D *p = model->getMesh(0)->getTexture(0)->getPixmapConst(); - color = p->getPixel3f(p->getW() / 2, p->getH() / 2); + color = p->getPixel4f(p->getW() / 2, p->getH() / 2); } TilesetModelType *modelType = new TilesetModelType(); modelType->setModel(model); diff --git a/source/glest_game/types/object_type.h b/source/glest_game/types/object_type.h index 825694475..6edfebd69 100644 --- a/source/glest_game/types/object_type.h +++ b/source/glest_game/types/object_type.h @@ -29,7 +29,7 @@ namespace Glest { namespace Game { using Shared::Graphics::Model; - using Shared::Graphics::Vec3f; + using Shared::Graphics::Vec4f; // ===================================================== // class ObjectType @@ -50,7 +50,7 @@ namespace Glest { private: ModelTypes modeltypes; - Vec3f color; + Vec4f color; int objectClass; bool walkable; int height; @@ -75,7 +75,7 @@ namespace Glest { inline int getModelCount() const { return (int) modeltypes.size(); } - inline const Vec3f & getColor() const { + inline const Vec4f & getColor() const { return color; } inline int getClass() const { diff --git a/source/glest_game/world/minimap.cpp b/source/glest_game/world/minimap.cpp index f95d17141..db2d471b0 100644 --- a/source/glest_game/world/minimap.cpp +++ b/source/glest_game/world/minimap.cpp @@ -107,7 +107,7 @@ namespace Glest { //tex tex = renderer.newTexture2D(rsGame); if (tex) { - tex->getPixmap()->init(scaledW, scaledH, 3); + tex->getPixmap()->init(scaledW, scaledH, 4); tex->setMipmap(false); } @@ -261,7 +261,7 @@ namespace Glest { void Minimap::computeTexture(const World *world) { - Vec3f color; + Vec4f color; const Map *map = world->getMap(); if (tex) { @@ -273,16 +273,17 @@ namespace Glest { if (sc->getObject() == NULL || sc->getObject()->getType() == NULL) { const Pixmap2D *p = world->getTileset()->getSurfPixmap(sc->getSurfaceType(), 0); - color = p->getPixel3f(p->getW() / 2, p->getH() / 2); + color = p->getPixel4f(p->getW() / 2, p->getH() / 2); color = color * static_cast(sc->getVertex().y / 6.f); if (sc->getVertex().y <= world->getMap()->getWaterLevel()) { - color += Vec3f(0.5f, 0.5f, 1.0f); + color += Vec4f(0.5f, 0.5f, 1.0f, 1.0f); } if (color.x > 1.f) color.x = 1.f; if (color.y > 1.f) color.y = 1.f; if (color.z > 1.f) color.z = 1.f; + if (color.w > 1.f) color.w = 1.f; } else { color = sc->getObject()->getType()->getColor(); } diff --git a/source/glest_game/world/surface_atlas.cpp b/source/glest_game/world/surface_atlas.cpp index af737fe88..4a62a0a52 100644 --- a/source/glest_game/world/surface_atlas.cpp +++ b/source/glest_game/world/surface_atlas.cpp @@ -92,7 +92,7 @@ namespace Glest { // throw megaglest_runtime_error("Could not create new texture (NULL)"); //} t->setWrapMode(Texture::wmClampToEdge); - t->getPixmap()->init(surfaceSize, surfaceSize, 3); + t->getPixmap()->init(surfaceSize, surfaceSize, 4); } si->setCoord(Vec2f(0.f, 0.f)); diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index be9a628ec..d87f13390 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -216,7 +216,7 @@ namespace Glest { const XmlNode *textureNode = surfaceNode->getChild("texture", j); if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { surfPixmaps[i][j] = new Pixmap2D(); - surfPixmaps[i][j]->init(3); + surfPixmaps[i][j]->init(4); surfPixmaps[i][j]->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); } loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile, textureNode->getAttribute("path")->getRestrictedValue())); @@ -242,7 +242,7 @@ namespace Glest { try { pixmap = new Pixmap2D(); - pixmap->init(3); + pixmap->init(4); pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile, textureNode->getAttribute("path")->getRestrictedValue())); @@ -288,7 +288,7 @@ namespace Glest { for (int y = 0; y < parts; ++y) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { surfPixmaps[i][j] = new Pixmap2D(); - surfPixmaps[i][j]->init(partsize, partsize, 3); + surfPixmaps[i][j]->init(partsize, partsize, 4); surfPixmaps[i][j]->copyImagePart(x*partsize, y*partsize, pixmap); } surfProbs[i][j] = -1; diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index cc8026172..896e658ca 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2700,7 +2700,7 @@ namespace Glest { psProj->setObserver(new ParticleDamager(unit, (*pt), this, gameCamera)); psProj->setVisible(visible); if (unit->getFaction()->getTexture()) { - psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); } renderer.manageParticleSystem(psProj, rsGame); unit->addAttackParticleSystem(psProj); @@ -2710,7 +2710,7 @@ namespace Glest { psSplash->setPos(endPos); psSplash->setVisible(visible); if (unit->getFaction()->getTexture()) { - psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); } renderer.manageParticleSystem(psSplash, rsGame); unit->addAttackParticleSystem(psSplash); @@ -2731,7 +2731,7 @@ namespace Glest { psSplash->setPos(endPos); psSplash->setVisible(visible); if (unit->getFaction()->getTexture()) { - psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); } renderer.manageParticleSystem(psSplash, rsGame); unit->addAttackParticleSystem(psSplash); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 73217124c..b0810a7d9 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -2082,7 +2082,7 @@ namespace Glest { stats.setResourceMultiplier(i, (gs->getResourceMultiplierIndex(i) + 5)*0.1f); stats.setPlayerName(i, gs->getNetworkPlayerName(i)); if (getFaction(i)->getTexture()) { - stats.setPlayerColor(i, getFaction(i)->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + stats.setPlayerColor(i, getFaction(i)->getTexture()->getPixmapConst()->getPixel4f(0, 0)); } } diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index eb9b7ca3a..54d61e560 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -457,8 +457,9 @@ namespace MapEditor { currentFile = fname; fileName = cutLastExt(extractFileFromDirectoryPath(fname.c_str())); fileDialog->SetPath(ToUnicode(fname)); - } - SetTitle(ToUnicode(currentFile + " - " + winHeader)); + SetTitle(ToUnicode(winHeader + "; " + fname)); + } else + SetTitle(ToUnicode(winHeader)); //setDirty(false); //setExtension(); @@ -533,8 +534,10 @@ namespace MapEditor { //currentFile = fname; fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); fileDialog->SetPath(ToUnicode(currentFile)); - } - SetTitle(ToUnicode(currentFile + " - " + winHeader)); + SetTitle(ToUnicode(winHeader + "; " + currentFile)); + } else + SetTitle(ToUnicode(winHeader)); + setDirty(false); setExtension(); } diff --git a/source/shared_lib/include/graphics/gl/text_renderer_gl.h b/source/shared_lib/include/graphics/gl/text_renderer_gl.h index e8351bda5..4478570ac 100644 --- a/source/shared_lib/include/graphics/gl/text_renderer_gl.h +++ b/source/shared_lib/include/graphics/gl/text_renderer_gl.h @@ -41,7 +41,7 @@ namespace Shared { virtual ~TextRenderer2DGl(); virtual void begin(Font2D *font); - virtual void render(const string &text, float x, float y, bool centered = false, Vec3f *color = NULL); + virtual void render(const string &text, float x, float y, bool centered = false, Vec4f *color = NULL); virtual void end(); }; @@ -55,7 +55,7 @@ namespace Shared { bool rendering; int currentFTGLErrorCount; - void internalRender(const string &text, float x, float y, bool centered, Vec3f *color); + void internalRender(const string &text, float x, float y, bool centered, Vec4f *color); void specialFTGLErrorCheckWorkaround(string text); public: @@ -63,7 +63,7 @@ namespace Shared { virtual ~TextRenderer3DGl(); virtual void begin(Font3D *font); - virtual void render(const string &text, float x, float y, bool centered = false, Vec3f *color = NULL); + virtual void render(const string &text, float x, float y, bool centered = false, Vec4f *color = NULL); virtual void end(); }; diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 7093ebaa8..05f657bd5 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -339,7 +339,6 @@ namespace Shared { recycleUniqueColor(); } - //static const int COLOR_COMPONENTS = 3; static const int COLOR_COMPONENTS = 4; static void init(int bufferSize); static void beginPicking(); diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index c530ac0eb..9816fefd0 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -185,7 +185,7 @@ namespace Shared { float speed; float speedUpRelative; float speedUpConstant; - Vec3f factionColor; + Vec4f factionColor; bool teamcolorNoEnergy; bool teamcolorEnergy; int alternations; @@ -268,7 +268,7 @@ namespace Shared { void setParticleSystemStartDelay(int delay) { this->particleSystemStartDelay = delay; } - virtual void setFactionColor(Vec3f factionColor); + virtual void setFactionColor(Vec4f factionColor); static BlendMode strToBlendMode(const string &str); //misc diff --git a/source/shared_lib/include/graphics/text_renderer.h b/source/shared_lib/include/graphics/text_renderer.h index 2ccf17a06..145c7c64c 100644 --- a/source/shared_lib/include/graphics/text_renderer.h +++ b/source/shared_lib/include/graphics/text_renderer.h @@ -28,7 +28,7 @@ namespace Shared { class TextRenderer { public: - virtual void render(const string &text, float x, float y, bool centered = false, Vec3f *color = NULL) = 0; + virtual void render(const string &text, float x, float y, bool centered = false, Vec4f *color = NULL) = 0; virtual void end() = 0; virtual ~TextRenderer() { diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 478816e05..f18df0a57 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -745,7 +745,7 @@ namespace Shared { x += v.x; y += v.y; z += v.z; - w += w.z; + w += v.w; return *this; } @@ -753,7 +753,7 @@ namespace Shared { x -= v.x; y -= v.y; z -= v.z; - w -= w.z; + w -= v.w; return *this; } inline bool operator <(const Vec4 &v) const { diff --git a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp index 68297b580..fd17ac1a5 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -48,7 +48,7 @@ namespace Shared { rendering = true; } - void TextRenderer2DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) { + void TextRenderer2DGl::render(const string &text, float x, float y, bool centered, Vec4f *color) { if (SystemFlags::VERBOSE_MODE_ENABLED) printf("**** RENDERING 2D text [%s]\n", text.c_str()); assert(rendering); @@ -57,7 +57,7 @@ namespace Shared { if (color != NULL) { glPushAttrib(GL_CURRENT_BIT); - glColor3fv(color->ptr()); + glColor4fv(color->ptr()); } string renderText = text; @@ -377,7 +377,7 @@ namespace Shared { //assertGl(); } - void TextRenderer3DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) { + void TextRenderer3DGl::render(const string &text, float x, float y, bool centered, Vec4f *color) { assert(rendering); if (text.empty() == false) { @@ -433,7 +433,7 @@ namespace Shared { //} } - void TextRenderer3DGl::internalRender(const string &text, float x, float y, bool centered, Vec3f *color) { + void TextRenderer3DGl::internalRender(const string &text, float x, float y, bool centered, Vec4f *color) { //assert(rendering); if (color != NULL) { @@ -442,7 +442,7 @@ namespace Shared { //assertGl(); - glColor3fv(color->ptr()); + glColor4fv(color->ptr()); //assertGl(); } diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 54110a5e8..1153b373b 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -526,8 +526,8 @@ namespace Shared { particleSize = particleSystemNode->getAttribute("particleSize")->getFloatValue(); // float speed; speed = particleSystemNode->getAttribute("speed")->getFloatValue(); - // Vec3f factionColor; - factionColor = Vec3f::strToVec3(particleSystemNode->getAttribute("factionColor")->getValue()); + // Vec4f factionColor; + factionColor = Vec4f::strToVec4(particleSystemNode->getAttribute("factionColor")->getValue()); // bool teamcolorNoEnergy; teamcolorNoEnergy = particleSystemNode->getAttribute("teamcolorNoEnergy")->getIntValue() != 0; // bool teamcolorEnergy; @@ -627,7 +627,7 @@ namespace Shared { aliveParticleCount--; } - void ParticleSystem::setFactionColor(Vec3f factionColor) { + void ParticleSystem::setFactionColor(Vec4f factionColor) { this->factionColor = factionColor; Vec3f tmpCol; diff --git a/source/tools/glexemel/g3d_support_b269.py b/source/tools/glexemel/g3d_support_b269.py deleted file mode 100644 index db15670c4..000000000 --- a/source/tools/glexemel/g3d_support_b269.py +++ /dev/null @@ -1,929 +0,0 @@ -# -*- coding: utf-8 -*- - -########################################################################### -# Glest Model / Texture / UV / Animation Importer and Exporter -# for the Game Glest that u can find http://www.glest.org -# copyright 2005 By Andreas Becker (seltsamuel@yahoo.de) -# -# 2011/05/25: v0.1 alpha1 -# modified by William Zheng for Blender 2.57(loveheaven_zhengwei@hotmail.com) -# -# corrected by MrPostiga for Blender 2.58 -# -# extended by Yggdrasil -# -# Started Date: 07 June 2005 Put Public 20 June 2005 -# Distributed under the GNU PUBLIC LICENSE -#""" -#Here an explanation of the V4 Format found at www.glest.org -#================================ -#1. DATA TYPES -#================================ -#G3D files use the following data types: -#uint8: 8 bit unsigned integer -#uint16: 16 bit unsigned integer -#uint32: 32 bit unsigned integer -#float32: 32 bit floating point -#================================ -#2. OVERALL STRUCTURE -#================================ -#- File header -#- Model header -#- Mesh header -#- Texture names -#- Mesh data -#================================ -#2. FILE HEADER -#================================ -#Code: -#struct FileHeader{ -# uint8 id[3]; -# uint8 version; -#}; -#This header is shared among all the versions of G3D, it identifies this file as a G3D model and provides information of the version. -#id: must be "G3D" -#version: must be 4, in binary (not '4') -#================================ -#3. MODEL HEADER -#================================ -#Code: -#struct ModelHeader{ -# uint16 meshCount; -# uint8 type; -#}; -#meshCount: number of meshes in this model -#type: must be 0 -#================================ -#4. MESH HEADER -#================================ -#There is a mesh header for each mesh, there must be "meshCount" headers in a file but they are not consecutive, texture names and mesh data are stored in between. -#Code: -#struct MeshHeader{ -# uint8 name[64]; -# uint32 frameCount; -# uint32 vertexCount; -# uint32 indexCount; -# float32 diffuseColor[3]; -# float32 specularColor[3]; -# float32 specularPower; -# float32 opacity; -# uint32 properties; -# uint32 textures; -#}; -#name: name of the mesh -#frameCount: number of keyframes in this mesh -#vertexCount: number of vertices in each frame -#indexCount: number of indices in this mesh (the number of triangles is indexCount/3) -#diffuseColor: RGB diffuse color -#specularColor: RGB specular color (currently unused) -#specularPower: specular power (currently unused) -##properties: property flags -#Code: -#enum MeshPropertyFlag{ -# mpfCustomColor= 1, -# mpfTwoSided= 2, -# mpfNoSelect= 4 -#}; -#mpfTwoSided: meshes in this mesh are rendered by both sides, if this flag is not present only "counter clockwise" faces are rendered -#mpfCustomColor: alpha in this model is replaced by a custom color, usually the player color -#textures: texture flags -#Code: -#enum MeshTexture{ -# diffuse = 1, -# specular = 2, -# normal = 4 -#}; -#================================ -#4. TEXTURE NAMES -#================================ -#A list of uint8[64] texture name values. One for each texture in the mesh. If there are no textures in the mesh no texture names are present. -#================================ -#5. MESH DATA -#================================ -#After each mesh header and texture names the mesh data is placed. -#vertices: frameCount * vertexCount * 3, float32 values representing the x, y, z vertex coords for all frames -#normals: frameCount * vertexCount * 3, float32 values representing the x, y, z normal coords for all frames -#texture coords: vertexCount * 2, float32 values representing the s, t tex coords for all frames (only present if the mesh has 1 texture at least) -#indices: indexCount, uint32 values representing the indices -########################################################################### - -bl_info = { - "name": "G3D Mesh Import/Export", - "description": "Import/Export .g3d file (Glest 3D)", - "author": "various, see head of script", - "version": (0, 11, 1), - "blender": (2, 65, 0), - "location": "File > Import-Export", - "warning": "always keep .blend files", - "wiki_url": "http://glest.wikia.com/wiki/G3D_support", - "tracker_url": "https://forum.megaglest.org/index.php?topic=6596", - "category": "Import-Export"} -########################################################################### -# Importing Structures needed (must later verify if i need them really all) -########################################################################### -import bpy -from bpy.props import StringProperty -from bpy_extras.image_utils import load_image -from bpy_extras.io_utils import ImportHelper, ExportHelper -import bmesh - -import sys, struct, string, types -from types import * -import os -from os import path -from os.path import dirname, abspath - -import subprocess -from mathutils import Matrix -from math import radians -########################################################################### -# Variables that are better Global to handle -########################################################################### -imported = [] #List of all imported Objects -toexport = [] #List of Objects to export (actually only meshes) -sceneID = None #Points to the active Blender Scene -def unpack_list(list_of_tuples): - l = [] - for t in list_of_tuples: - l.extend(t) - return l -########################################################################### -# Declaring Structures of G3D Format -########################################################################### -class G3DHeader: #Read first 4 Bytes of file should be G3D + Versionnumber - binary_format = "<3cB" - def __init__(self, fileID): - temp = fileID.read(struct.calcsize(self.binary_format)) - data = struct.unpack(self.binary_format,temp) - self.id = str(data[0]+data[1]+data[2], "utf-8") - self.version = data[3] - -class G3DModelHeaderv3: #Read Modelheader in V3 there is only the number of Meshes in file - binary_format = "> 3 - while tex: - tex &= tex - 1 # set rightmost 1-bit to 0 - # discard texture name, as we don't know what to do with it - fileID.seek(struct.calcsize(self.texname_format)) - print("warning: ignored texture in undefined texture slot") - -class G3DMeshdataV3: #Calculate and read the Mesh Datapack - def __init__(self,fileID,header): - #Calculation of the Meshdatasize to load because its variable - #Animationframes * Vertices per Animation * 3 (Each Point are 3 Float X Y Z Coordinates) - vertex_format = "<%if" % int(header.framecount * header.vertexcount * 3) - #The same for Normals - normals_format = "<%if" % int(header.normalframecount * header.vertexcount * 3) - #Same here but Textures are 2D so only 2 Floats needed for Position inside Texture Bitmap - texturecoords_format = "<%if" % int(header.texturecoordframecount * header.vertexcount * 2) - #Colors in format RGBA - colors_format = "<%if" % int(header.colorframecount * 4) - #Indices - indices_format = "<%iI" % int(header.indexcount) - #Load the Meshdata as calculated above - self.vertices = struct.unpack(vertex_format,fileID.read(struct.calcsize(vertex_format))) - self.normals = struct.unpack(normals_format,fileID.read(struct.calcsize(normals_format))) - self.texturecoords = struct.unpack(texturecoords_format,fileID.read(struct.calcsize(texturecoords_format))) - self.colors = struct.unpack(colors_format,fileID.read(struct.calcsize(colors_format))) - self.indices = struct.unpack(indices_format ,fileID.read(struct.calcsize(indices_format))) - -class G3DMeshdataV4: #Calculate and read the Mesh Datapack - def __init__(self,fileID,header): - #Calculation of the Meshdatasize to load because its variable - #Animationframes * Points (Vertex) per Animation * 3 (Each Point are 3 Float X Y Z Coordinates) - vertex_format = "<%if" % int(header.framecount * header.vertexcount * 3) - #The same for Normals - normals_format = "<%if" % int(header.framecount * header.vertexcount * 3) - #Same here but Textures are 2D so only 2 Floats needed for Position inside Texture Bitmap - texturecoords_format = "<%if" % int(header.vertexcount * 2) - #Indices - indices_format = "<%iI" % int(header.indexcount) - #Load the Meshdata as calculated above - self.vertices = struct.unpack(vertex_format,fileID.read(struct.calcsize(vertex_format))) - self.normals = struct.unpack(normals_format,fileID.read(struct.calcsize(normals_format))) - if header.hastexture: - self.texturecoords = struct.unpack(texturecoords_format,fileID.read(struct.calcsize(texturecoords_format))) - self.indices = struct.unpack(indices_format ,fileID.read(struct.calcsize(indices_format))) - -#Create a Mesh inside Blender -def createMesh(filename, header, data, toblender, operator): - mesh = bpy.data.meshes.new(header.meshname) #New Mesh - meshobj = bpy.data.objects.new(header.meshname+'Object', mesh) #New Object for the new Mesh - scene = bpy.context.scene - scene.objects.link(meshobj) - scene.update() - uvcoords = [] - img_diffuse = None - img_specular = None - img_normal = None - if header.hastexture: #Load Texture when assigned - try: - texturefile = dirname(abspath(filename)) + os.sep + header.diffusetexture - img_diffuse = bpy.data.images.load(texturefile) - for x in range(0,len(data.texturecoords),2): #Prepare the UV - uvcoords.append([data.texturecoords[x],data.texturecoords[x+1]]) - - if header.isv4: - if header.speculartexture: - texturefile = dirname(abspath(filename)) + os.sep + header.speculartexture - img_specular = bpy.data.images.load(texturefile) - if header.normaltexture: - texturefile = dirname(abspath(filename)) + os.sep + header.normaltexture - img_normal = bpy.data.images.load(texturefile) - except: - import traceback - traceback.print_exc() - - header.hastexture = False - operator.report({'WARNING'}, "Couldn't load texture. See console for details.") - - vertsCO = [] - vertsNormal = [] - for x in range(0,header.vertexcount*3,3): #Get the Vertices and Normals into empty Mesh - vertsCO.extend([(data.vertices[x],data.vertices[x+1],data.vertices[x+2])]) - vertsNormal.extend([(data.normals[x],data.normals[x+1],data.normals[x+2])]) - #vertsCO.extend([(data.vertices[x+(header.framecount-1)*header.vertexcount*3],data.vertices[x+(header.framecount-1)*header.vertexcount*3+1],data.vertices[x+(header.framecount-1)*header.vertexcount*3+2])]) - #vertsNormal.extend([(data.normals[x+(header.framecount-1)*header.vertexcount*3],data.normals[x+(header.framecount-1)*header.vertexcount*3+1],data.normals[x+(header.framecount-1)*header.vertexcount*3+2])]) - mesh.vertices.add(len(vertsCO)) - mesh.vertices.foreach_set("co", unpack_list(vertsCO)) - mesh.vertices.foreach_set("normal", unpack_list(vertsNormal)) - - faces = [] - faceuv = [] - for i in range(0,len(data.indices),3): #Build Faces into Mesh - faces.extend([data.indices[i], data.indices[i+1], data.indices[i+2], 0]) - if header.hastexture: - uv = [] - u0 = uvcoords[data.indices[i]][0] - v0 = uvcoords[data.indices[i]][1] - uv.append([u0,v0]) - u1 = uvcoords[data.indices[i+1]][0] - v1 = uvcoords[data.indices[i+1]][1] - uv.append([u1,v1]) - u2 = uvcoords[data.indices[i+2]][0] - v2 = uvcoords[data.indices[i+2]][1] - uv.append([u2,v2]) - faceuv.append([uv,0,0,0]) - else: - uv = [] - uv.append([0,0]) - uv.append([0,0]) - uv.append([0,0]) - faceuv.append([uv,0,0,0]) - mesh.tessfaces.add(len(faces)//4) - mesh.tessfaces.foreach_set("vertices_raw", faces) - mesh.tessfaces.foreach_set("use_smooth", [True] * len(mesh.tessfaces)) - mesh.g3d_customColor = header.customalpha - mesh.show_double_sided = header.istwosided - if header.isv4: - mesh.g3d_noSelect = header.noselect - mesh.g3d_glow = header.glow - else: - mesh.g3d_noSelect = False - mesh.glow = False - mesh.g3d_fullyOpaque = False - #=================================================================================================== - #Material Setup - #=================================================================================================== - def addtexslot(matdata,index,name,img): - texture = bpy.data.textures.new(name=name,type='IMAGE') - texture.image = img - slot = matdata.texture_slots.create(index) - slot.texture = texture - slot.texture_coords = 'UV' - - if header.hastexture: - materialname = "pskmat" - materials = [] - matdata = bpy.data.materials.new(materialname + '1') - - addtexslot(matdata, 0, 'diffusetexture', img_diffuse) - if img_specular: - addtexslot(matdata, 1, 'speculartexture', img_specular) - if img_normal: - addtexslot(matdata, 2, 'normaltexture', img_normal) - - if header.isv4: - matdata.diffuse_color = (header.diffusecolor[0], header.diffusecolor[1],header.diffusecolor[2]) - matdata.alpha = header.opacity - matdata.specular_color = (header.specularcolor[0], header.specularcolor[1],header.specularcolor[2]) - materials.append(matdata) - - for material in materials: - #add material to the mesh list of materials - mesh.materials.append(material) - - countm = 0 - psktexname="psk" + str(countm) - mesh.tessface_uv_textures.new(name=psktexname) - if (len(faceuv) > 0): - for countm in range(len(mesh.tessface_uv_textures)): - uvtex = mesh.tessface_uv_textures[countm] #add one uv texture - for i, face in enumerate(mesh.tessfaces): - blender_tface = uvtex.data[i] #face - mfaceuv = faceuv[i] - if countm == faceuv[i][1]: - face.material_index = faceuv[i][1] - blender_tface.uv1 = mfaceuv[0][0] #uv = (0,0) - blender_tface.uv2 = mfaceuv[0][1] #uv = (0,0) - blender_tface.uv3 = mfaceuv[0][2] #uv = (0,0) - blender_tface.image = img_diffuse - else: - blender_tface.uv1 = [0,0] - blender_tface.uv2 = [0,0] - blender_tface.uv3 = [0,0] - imported.append(meshobj) #Add to Imported Objects - sk = meshobj.shape_key_add() - for x in range(1,header.framecount): #Put in Vertex Positions for Keyanimation - sk = meshobj.shape_key_add() - for i in range(0,header.vertexcount*3,3): - sk.data[i//3].co[0]= data.vertices[x*header.vertexcount*3 + i] - sk.data[i//3].co[1]= data.vertices[x*header.vertexcount*3 + i +1] - sk.data[i//3].co[2]= data.vertices[x*header.vertexcount*3 + i +2] - - # activate one shapekey per frame - for i in range(1,header.framecount): - shape = mesh.shape_keys.key_blocks[i] - shape.value = 0.0 - shape.keyframe_insert("value", frame=i) - shape.value = 1.0 - shape.keyframe_insert("value", frame=(i+1)) - shape.value = 0.0 - shape.keyframe_insert("value", frame=(i+2)) - - meshobj.active_shape_key_index = 0 - - if toblender: - # rotate from glest to blender orientation - #mesh.transform( Matrix( ((1,0,0,0),(0,0,-1,0),(0,1,0,0),(0,0,0,1)) ) ) - # doesn't work, maybe because of shape keys - # use object transformation instead - meshobj.rotation_euler = (radians(90), 0, 0) - - # update polygon structures from tessfaces - mesh.update() - mesh.update_tag() - - # remove duplicates - bm = bmesh.new() - bm.from_mesh(mesh) - bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001) - bm.to_mesh(mesh) - bm.free() - - return -########################################################################### -# Import -########################################################################### -def G3DLoader(filepath, toblender, operator): #Main Import Routine - global imported, sceneID - print ("\nNow Importing File: " + filepath) - fileID = open(filepath,"rb") - header = G3DHeader(fileID) - print ("\nHeader ID : " + header.id) - print ("Version : " + str(header.version)) - if header.id != "G3D": - print ("ERROR: This is Not a G3D Model File") - operator.report({'ERROR'}, "This is Not a G3D Model File") - fileID.close - return - if header.version not in (3, 4): - print ("ERROR: The Version of this G3D File is not Supported") - operator.report({'ERROR'}, "The Version of this G3D File is not Supported") - fileID.close - return - #in_editmode = Blender.Window.EditMode() #Must leave Editmode when active - #if in_editmode: Blender.Window.EditMode(0) - sceneID = bpy.context.scene #Get active Scene - #scenecontext=sceneID.getRenderingContext() #To Access the Start/Endframe its so hidden i searched till i got angry :-) - basename=os.path.basename(filepath).split('.')[0] #Generate the Base Filename without Path + extension - imported = [] - maxframe=0 - if header.version == 3: - modelheader = G3DModelHeaderv3(fileID) - print ("Number of Meshes : " + str(modelheader.meshcount)) - for x in range(modelheader.meshcount): - meshheader = G3DMeshHeaderv3(fileID) - meshheader.isv4 = False - print ("\nMesh Number : " + str(x+1)) - print ("framecount : " + str(meshheader.framecount)) - print ("normalframecount : " + str(meshheader.normalframecount)) - print ("texturecoordframecount: " + str(meshheader.texturecoordframecount)) - print ("colorframecount : " + str(meshheader.colorframecount)) - print ("pointcount : " + str(meshheader.vertexcount)) - print ("indexcount : " + str(meshheader.indexcount)) - print ("texturename : " + str(meshheader.diffusetexture)) - print ("hastexture : " + str(meshheader.hastexture)) - print ("istwosided : " + str(meshheader.istwosided)) - print ("customalpha : " + str(meshheader.customalpha)) - meshheader.meshname = basename+str(x+1) #Generate Meshname because V3 has none - if meshheader.framecount > maxframe: maxframe = meshheader.framecount #Evaluate the maximal animationsteps - meshdata = G3DMeshdataV3(fileID,meshheader) - createMesh(filepath, meshheader, meshdata, toblender, operator) - fileID.close - bpy.context.scene.frame_start=1 - bpy.context.scene.frame_end=maxframe - bpy.context.scene.frame_current=1 - anchor = bpy.data.objects.new('Empty', None) - anchor.select = True - bpy.context.scene.objects.link(anchor) - for ob in imported: - ob.parent = anchor - bpy.context.scene.update() - return - if header.version == 4: - modelheader = G3DModelHeaderv4(fileID) - print ("Number of Meshes : " + str(modelheader.meshcount)) - for x in range(modelheader.meshcount): - meshheader = G3DMeshHeaderv4(fileID) - meshheader.isv4 = True - print ("\nMesh Number : " + str(x+1)) - print ("meshname : " + str(meshheader.meshname)) - print ("framecount : " + str(meshheader.framecount)) - print ("vertexcount : " + str(meshheader.vertexcount)) - print ("indexcount : " + str(meshheader.indexcount)) - print ("diffusecolor : %1.6f %1.6f %1.6f" %meshheader.diffusecolor) - print ("specularcolor : %1.6f %1.6f %1.6f" %meshheader.specularcolor) - print ("specularpower : %1.6f" %meshheader.specularpower) - print ("opacity : %1.6f" %meshheader.opacity) - print ("properties : " + str(meshheader.properties)) - print ("textures : " + str(meshheader.textures)) - print ("texturename : " + str(meshheader.diffusetexture)) - if len(meshheader.meshname) ==0: #When no Meshname in File Generate one - meshheader.meshname = basename+str(x+1) - if meshheader.framecount > maxframe: maxframe = meshheader.framecount #Evaluate the maximal animationsteps - meshdata = G3DMeshdataV4(fileID,meshheader) - createMesh(filepath, meshheader, meshdata, toblender, operator) - fileID.close - - bpy.context.scene.frame_start=1 - bpy.context.scene.frame_end=maxframe - bpy.context.scene.frame_current=1 - anchor = bpy.data.objects.new('Empty', None) - anchor.select = True - bpy.context.scene.objects.link(anchor) - for ob in imported: - ob.parent = anchor - bpy.context.scene.update() - print ("Created a empty Object as 'Grip' where all imported Objects are parented to") - print ("To move the complete Meshes only select this empty Object and move it") - print ("All Done, have a good Day :-)\n\n") - return - -def G3DSaver(filepath, context, toglest, operator): - print ("\nNow Exporting File: " + filepath) - - objs = context.selected_objects - if len(objs) == 0: - objs = bpy.data.objects - - #get real meshcount as len(bpy.data.meshes) holds also old meshes - meshCount = 0 - for obj in objs: - if obj.type == 'MESH': - meshCount += 1 - if obj.mode != 'OBJECT': # we want to be in object mode - print("ERROR: mesh not in object mode") - operator.report({'ERROR'}, "mesh not in object mode") - return -1 - - if meshCount == 0: - print("ERROR: no meshes found") - operator.report({'ERROR'}, "no meshes found") - return -1 - - fileID = open(filepath,"wb") - # G3DHeader v4 - fileID.write(struct.pack("<3cB", b'G', b'3', b'D', 4)) - # G3DModelHeaderv4 - fileID.write(struct.pack(" 0: - # we have a texture, hopefully - material = mesh.materials[0] - slot = material.texture_slots[0] - # only look for other textures when we have diffuse - if slot and slot.texture.type=='IMAGE' and len(mesh.uv_textures)>0: - diffuseColor = material.diffuse_color - specularColor = material.specular_color - opacity = material.alpha - textures = 1 - texnames = [] - texnames.append(bpy.path.basename(slot.texture.image.filepath)) - # specular and normal - for i in range(1, 3): - slot = material.texture_slots[i] - if slot and slot.texture.type=='IMAGE': - texnames.append(bpy.path.basename(slot.texture.image.filepath)) - textures |= 1 << i - - else: - print("WARNING: first texture slot in first material isn't of type IMAGE or it's not unwrapped, texture ignored") - operator.report({'WARNING'}, "first texture slot in first material isn't of type IMAGE or it's not unwrapped, texture ignored") - #continue without texture - - meshname = mesh.name - frameCount = context.scene.frame_end - context.scene.frame_start +1 - realFaceCount = 0 # real face count (triangles) - indices=[] # list of indices - newverts=[] # list of vertex indices which need to be duplicated - uvlist = [] # list of texcoords - mesh.update(calc_tessface=True) # tesselate n-polygons to triangles & quads - if textures: - uvtex = mesh.tessface_uv_textures[0] - uvlist[:] = [[0]*2 for i in range(len(mesh.vertices))] - # blender allows to have multiple texcoords per vertex, - # in g3d format every vertex can only have one texcoord - # -> duplicate vertex - # the dictionary/map vdict collects all the stuff - # index to "unique" vertices from blender - # -> tuple( list of texcoords, list of indices to the duplicated vertex ) - vdict = dict() - nextIndex = len(mesh.vertices) - for face in mesh.tessfaces: - # when a vertex is duplicated it gets a new index, so the - # triple of indices describing the face is different too - faceindices = [] - realFaceCount += 1 - uvdata = uvtex.data[face.index] - for i in range(3): - #closure, got rid of copy&paste, still looking weird - def getTexCoords(): - nonlocal nextIndex, vdict, uvlist, newverts - vindex = face.vertices[i] - if vindex not in vdict: # new vertex -> add it - vdict[vindex] = [uvdata.uv[i]], [vindex] - uvlist[vindex] = uvdata.uv[i] # that's a (s,t)-pair - else: - found = False - idx = 0 - for ele in vdict[vindex][0]: - if uvdata.uv[i][0] == ele[0] and uvdata.uv[i][1] == ele[1]: - found = True - break - idx += 1 - if found: # same vertex and texcoord before - # it could be a different index now, the index of a new - # duplicated vertex - #vindex = vdict[vindex][1][ vdict[vindex][0].index(uvdata.uv[i]) ] - vindex = vdict[vindex][1][idx] - else: # same vertex as before but with different texcoord -> duplicate - vdict[vindex][0].append(uvdata.uv[i]) - vdict[vindex][1].append(nextIndex) - - # duplicate vertex because it takes part in different faces - # with different texcoords - newverts.append(vindex) - uvlist.append(uvdata.uv[i]) - # new index for the duplicated vertex - vindex = nextIndex - nextIndex += 1 - - faceindices.append(vindex) - getTexCoords() - indices.extend(faceindices) - - if len(face.vertices) == 4: - faceindices = [] - realFaceCount += 1 - for i in [0,2,3]: - getTexCoords() - indices.extend(faceindices) - else: - for face in mesh.tessfaces: - realFaceCount += 1 - indices.extend(face.vertices[0:3]) - if len(face.vertices) == 4: - realFaceCount += 1 - # new face because quad got split - indices.append(face.vertices[0]) - indices.append(face.vertices[2]) - indices.append(face.vertices[3]) - - - # abort when no triangles as it crashs g3dviewer - if realFaceCount == 0: - print("ERROR: no triangles found") - operator.report({'ERROR'}, "no triangles found") - fileID.close() - return -1 - indexCount = realFaceCount * 3 - vertexCount = len(mesh.vertices) + len(newverts) - specularPower = 9.999999 # unused, same as old exporter - properties = 0 - if mesh.g3d_customColor: - properties |= 1 - if mesh.show_double_sided: - properties |= 2 - if mesh.g3d_noSelect: - properties |= 4 - if mesh.g3d_glow: - properties |= 8 - - #MeshData - vertices = [] - normals = [] - fcurrent = context.scene.frame_current - for i in range(context.scene.frame_start, context.scene.frame_end+1): - context.scene.frame_set(i) - #FIXME: not sure what's better: PREVIEW or RENDER settings - m = obj.to_mesh(context.scene, True, 'RENDER') - m.transform(obj.matrix_world) # apply object-mode transformations - - if toglest: - # rotate from blender to glest orientation - m.transform( Matrix( ((1,0,0,0),(0,0,1,0),(0,-1,0,0),(0,0,0,1)) ) ) - # transform normals too - m.calc_normals() - - for vertex in m.vertices: - vertices.extend(vertex.co) - normals.extend(vertex.normal) - - # duplicate vertices and corresponding normals, for every frame - for nv in newverts: - vertices.extend(m.vertices[nv].co) - normals.extend(m.vertices[nv].normal) - - context.scene.frame_set(fcurrent) - - if mesh.g3d_fullyOpaque: - opacity = 1.0 - - # MeshHeader - fileID.write(struct.pack("<64s3I8f2I", - bytes(meshname, "ascii"), - frameCount, vertexCount, indexCount, - diffuseColor[0], diffuseColor[1], diffuseColor[2], - specularColor[0], specularColor[1], specularColor[2], - specularPower, opacity, - properties, textures - )) - #Texture names - if textures: # only when we have textures - for i in range(len(texnames)): - fileID.write(struct.pack("<64s", bytes(texnames[i], "ascii"))) - - # see G3DMeshdataV4 - vertex_format = "<%if" % int(frameCount * vertexCount * 3) - normals_format = "<%if" % int(frameCount * vertexCount * 3) - texturecoords_format = "<%if" % int(vertexCount * 2) - indices_format = "<%iI" % int(indexCount) - - fileID.write(struct.pack(vertex_format, *vertices)) - fileID.write(struct.pack(normals_format, *normals)) - - # texcoords - if textures: # only when we have textures - texcoords = [] - for uv in uvlist: - texcoords.extend(uv) - fileID.write(struct.pack(texturecoords_format, *texcoords)) - - fileID.write(struct.pack(indices_format, *indices)) - - fileID.close() - return 0 - - -#---=== Register === -class G3DPanel(bpy.types.Panel): - #bl_idname = "OBJECT_PT_G3DPanel" - bl_label = "G3D properties" - bl_space_type = 'PROPERTIES' - bl_region_type = 'WINDOW' - bl_context = "data" - - @classmethod - def poll(cls, context): - return (context.object is not None and context.object.type == 'MESH') - - def draw(self, context): - self.layout.prop(context.object.data, "g3d_customColor") - self.layout.prop(context.object.data, "show_double_sided", text="double sided") - self.layout.prop(context.object.data, "g3d_noSelect") - self.layout.prop(context.object.data, "g3d_fullyOpaque") - self.layout.prop(context.object.data, "g3d_glow") - -class ImportG3D(bpy.types.Operator, ImportHelper): - '''Load a G3D file''' - bl_idname = "importg3d.g3d" - bl_label = "Import G3D" - - filename_ext = ".g3d" - filter_glob = StringProperty(default="*.g3d", options={'HIDDEN'}) - - toblender = bpy.props.BoolProperty( - name="rotate to Blender orientation", - description="Rotate meshes from Glest to Blender orientation", - default=True) - - def execute(self, context): - try: - G3DLoader(self.filepath, self.toblender, self) - except: - import traceback - traceback.print_exc() - - return {'CANCELLED'} - - return {'FINISHED'} - -class ExportG3D(bpy.types.Operator, ExportHelper): - '''Save a G3D file''' - bl_idname = "exportg3d.g3d" - bl_label = "Export G3D" - - filename_ext = ".g3d" - filter_glob = StringProperty(default="*.g3d", options={'HIDDEN'}) - - #export options - showg3d = bpy.props.BoolProperty( - name="show G3D afterwards", - description=("Run g3dviewer to show G3D after export. " - "g3dviewer needs to be in the scripts directory, " - "otherwise the associated program of .g3d is run."), - default=False) - toglest = bpy.props.BoolProperty( - name="rotate to glest orientation", - description="Rotate meshes from Blender to Glest orientation", - default=True) - - def execute(self, context): - try: - res = G3DSaver(self.filepath, context, self.toglest, self) - if res==0 and self.showg3d: - print("opening g3dviewer with " + self.filepath) - scriptsdir = bpy.utils.script_path_user() - dname = os.path.dirname(self.filepath) - found = False - for f in os.listdir(scriptsdir): - if "g3dviewer" in f: - f = os.path.join(scriptsdir, f) - if os.path.isfile(f) and os.access(f, os.X_OK): - cmd = [f, self.filepath] - print(cmd) - subprocess.Popen(cmd, cwd=dname) - found = True - - # try default associated program - if not found: - if os.name == 'posix': - # xdg-open is only a shell script which delegates the job to a - # desktop specific program, e.g. if DE=kde than kde-open - # needs DE environment variable set, otherwise it just throws it - # at the browser, which is not very helpful - print("running xdg-open "+self.filepath) - subprocess.Popen(['xdg-open', self.filepath], cwd=dname) - elif os.name == 'mac': - subprocess.Popen(['open', self.filepath], cwd=dname) - elif os.name == 'nt': - #os.startfile(self.filepath) # no way to change dir - subprocess.Popen(['cmd', '/C', 'start', self.filepath], cwd=dname) - - except: - import traceback - traceback.print_exc() - - return {'CANCELLED'} - - return {'FINISHED'} - -def menu_func_import(self, context): - self.layout.operator(ImportG3D.bl_idname, text="Glest 3D File (.g3d)") - -def menu_func_export(self, context): - self.layout.operator(ExportG3D.bl_idname, text="Glest 3D File (.g3d)") - -def register(): - # custom mesh properties - bpy.types.Mesh.g3d_customColor = bpy.props.BoolProperty( - name="team color", - description="replace alpha channel of texture with team color") - bpy.types.Mesh.g3d_noSelect = bpy.props.BoolProperty( - name="non-selectable", - description="click on mesh doesn't select unit") - bpy.types.Mesh.g3d_fullyOpaque = bpy.props.BoolProperty( - name="fully opaque", - description="sets opacity to 1.0, ignoring what's set in materials") - bpy.types.Mesh.g3d_glow = bpy.props.BoolProperty( - name="glow", - description="let objects glow like particles") - - bpy.utils.register_module(__name__) - - bpy.types.INFO_MT_file_import.append(menu_func_import) - bpy.types.INFO_MT_file_export.append(menu_func_export) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - bpy.types.INFO_MT_file_import.remove(menu_func_import) - bpy.types.INFO_MT_file_export.remove(menu_func_export) - -if __name__ == '__main__': - register() -# main() - - #for obj in bpy.data.objects: - # if obj.type == 'MESH': - # obj.select = True - # bpy.ops.object.delete() - #G3DLoader("import.g3d", True, None) - - #for obj in bpy.context.selected_objects: - # obj.select = False # deselect everything, so we get it all - #G3DSaver("test.g3d", bpy.context) -