From 584640f12c42e7fe5752bad94eec422301091ef4 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 22 Jun 2013 14:14:35 +0300 Subject: [PATCH] Added help for truecolor light testing thing. Also added colors. --- plugins/rendermax/renderer_opengl.hpp | 51 +++++++++++++++++++-------- plugins/rendermax/rendermax.cpp | 35 +++++++++++++----- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/plugins/rendermax/renderer_opengl.hpp b/plugins/rendermax/renderer_opengl.hpp index 09d96ae45..525460b71 100644 --- a/plugins/rendermax/renderer_opengl.hpp +++ b/plugins/rendermax/renderer_opengl.hpp @@ -166,6 +166,27 @@ public: colorizeTile(x,y); }; }; + +struct lightCell +{ + float r,g,b; + lightCell():r(0),g(0),b(0) + { + + } + lightCell(float r,float g,float b):r(r),g(g),b(b) + { + + } + lightCell operator*(float val) + { + return lightCell(r*val,g*val,b*val); + } + lightCell operator+(const lightCell& other) + { + return lightCell(r+other.r,g+other.g,b+other.b); + } +}; struct renderer_test : public renderer_wrap { private: void colorizeTile(int x,int y) @@ -175,34 +196,34 @@ private: float *fg = p->fg + tile * 4 * 6; float *bg = p->bg + tile * 4 * 6; float *tex = p->tex + tile * 2 * 6; - float v=opacity[tile]; + lightCell light=lightGrid[tile]; for (int i = 0; i < 6; i++) { - *(fg++) *= v; - *(fg++) *= v; - *(fg++) *= v; + *(fg++) *= light.r; + *(fg++) *= light.g; + *(fg++) *= light.b; *(fg++) = 1; - *(bg++) *= v; - *(bg++) *= v; - *(bg++) *= v; + *(bg++) *= light.r; + *(bg++) *= light.g; + *(bg++) *= light.b; *(bg++) = 1; } } - void reinitOpacity(int w,int h) + void reinitLightGrid(int w,int h) { tthread::lock_guard guard(dataMutex); - opacity.resize(w*h); + lightGrid.resize(w*h); } - void reinitOpacity() + void reinitLightGrid() { - reinitOpacity(df::global::gps->dimy,df::global::gps->dimx); + reinitLightGrid(df::global::gps->dimy,df::global::gps->dimx); } public: tthread::fast_mutex dataMutex; - std::vector opacity; + std::vector lightGrid; renderer_test(renderer* parent):renderer_wrap(parent) { - reinitOpacity(); + reinitLightGrid(); } virtual void update_tile(int32_t x, int32_t y) { renderer_wrap::update_tile(x,y); @@ -223,10 +244,10 @@ public: }; virtual void grid_resize(int32_t w, int32_t h) { renderer_wrap::grid_resize(w,h); - reinitOpacity(w,h); + reinitLightGrid(w,h); }; virtual void resize(int32_t w, int32_t h) { renderer_wrap::resize(w,h); - reinitOpacity(w,h); + reinitLightGrid(w,h); } }; \ No newline at end of file diff --git a/plugins/rendermax/rendermax.cpp b/plugins/rendermax/rendermax.cpp index 69709ac96..85232cde9 100644 --- a/plugins/rendermax/rendermax.cpp +++ b/plugins/rendermax/rendermax.cpp @@ -30,6 +30,7 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector & parameters installNew(new renderer_trippy(df::global::enabler->renderer),MODE_TRIPPY); return CR_OK; } - else if(cmd=="test") + else if(cmd=="truecolor") { + if(current_mode!=MODE_TRUECOLOR) + { + removeOld(); + installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR); + } if(current_mode==MODE_TRUECOLOR && parameters.size()==2) { + lightCell red(1,0,0),green(0,1,0),blue(0,0,1),white(1,1,1); + lightCell cur=white; + lightCell dim(0.2,0.2,0.2); + string col=parameters[1]; + if(col=="red") + cur=red; + else if(col=="green") + cur=green; + else if(col=="blue") + cur=blue; + renderer_test* r=reinterpret_cast(df::global::enabler->renderer); tthread::lock_guard guard(r->dataMutex); int h=df::global::gps->dimy; @@ -70,20 +87,22 @@ static command_result rendermax(color_ostream &out, vector & parameters if(rad>cy)rad=cy; rad/=2; int radsq=rad*rad; + for(size_t i=0;ilightGrid.size();i++) + { + r->lightGrid[i]=dim; + } for(int i=-rad;iopacity[(cx+i)*h+(cy+j)]=(radsq-i*i-j*j)/(float)radsq; + { + float val=(radsq-i*i-j*j)/(float)radsq; + r->lightGrid[(cx+i)*h+(cy+j)]=dim+cur*val; + } } return CR_OK; } - else - { - removeOld(); - installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR); - return CR_OK; - } + } else if(cmd=="disable")