Auto-gradient entities
authorTerri00 <thrustmediaproductions@gmail.com>
Fri, 21 Jun 2019 15:16:54 +0000 (16:16 +0100)
committerTerri00 <thrustmediaproductions@gmail.com>
Fri, 21 Jun 2019 15:16:54 +0000 (16:16 +0100)
MCDV/GradientMap.hpp
MCDV/layer0.png
MCDV/main2.cpp
MCDV/sample_stuff/de_tavr_test.vmx
MCDV/tar_config.hpp

index 1ca3c8ad6e99bfc67944942e5dc44c05c5a42ca4..2a36639199bda735bbffb9153ada5bd543a8ee1e 100644 (file)
@@ -60,8 +60,8 @@ public:
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
                free(data);
        }
@@ -70,4 +70,67 @@ public:
                glActiveTexture(GL_TEXTURE0 + slot);
                glBindTexture(GL_TEXTURE_2D, this->texture_id);
        }*/
+};
+
+class WGradientTexture : public Texture{
+public:
+       WGradientTexture(std::vector<entity*>& tarcol) {
+               std::map<float, Color255> colorMap;
+
+               for (auto && i : tarcol) {
+                       colorMap.insert({ i->m_origin.y, kv::tryGetStringValue(i->m_keyvalues, "_light", "128 128 128 255") });
+               }
+
+               // Fill with blank color
+               if (colorMap.size() < 1) {
+                       colorMap.insert({ 0.0f, Color255("128 128 128 255") });
+               }
+
+               // Copy first to last
+               if (colorMap.size() < 2) {
+                       colorMap.insert({ 949.4342231f , colorMap.begin()->second });
+               }
+
+               std::map<float, Color255>::iterator it_end = colorMap.end();
+               it_end--;
+
+               float dy = it_end->first - colorMap.begin()->first;
+
+               std::map<float, Color255>::iterator it = colorMap.begin();
+               std::map<float, Color255>::iterator it_next = colorMap.begin();
+               it_next++;
+               
+               glGenTextures(1, &this->texture_id);
+               unsigned char* data = (unsigned char*)malloc(2048 * 4);
+
+               for (int i = 0; i < 2048; i++) {
+                       float pc = (float)i / (float)2048;
+                       float absdist = colorMap.begin()->first + (pc * dy);
+
+                       if (absdist > it_next->first) {
+                               if (it_next != colorMap.end()) {
+                                       it++;
+                                       it_next++;
+                               }
+                       }
+
+                       float subpc = remap(absdist, it->first, it_next->first, 0, 1);
+
+                       data[i * 4 + 0] = lerpT<float>(it->second.r, it_next->second.r, subpc);
+                       data[i * 4 + 1] = lerpT<float>(it->second.g, it_next->second.g, subpc);
+                       data[i * 4 + 2] = lerpT<float>(it->second.b, it_next->second.b, subpc);
+                       data[i * 4 + 3] = lerpT<float>(it->second.a, it_next->second.a, subpc);
+               }
+
+               glBindTexture(GL_TEXTURE_2D, this->texture_id);
+               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2048, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+               free(data);
+       }
 };
\ No newline at end of file
index dcdcd65560d10e4b4ef29a498cc415e158a0f59b..0bb5b28c002624d4aef85711a4956b9f43c228e8 100644 (file)
Binary files a/MCDV/layer0.png and b/MCDV/layer0.png differ
index c54ace47d4edad67bfd9e8a96668d4eb36a36efd..231e4e5d7532493220bd667b070b6cfa6ff9e500 100644 (file)
@@ -78,7 +78,7 @@ uint32_t g_msaa_mul = 1;
 void render_to_png(int x, int y, const char* filepath);
 void save_to_dds(int x, int y, const char* filepath, IMG imgmode = IMG::MODE_DXT1);
 
-//#define _DEBUG
+#define _DEBUG
 
 int app(int argc, const char** argv) {
 #ifndef _DEBUG
index 8e357a0740a0328fa27675c3fcb6195c3e1ff4f3..787a3cdf9caf54fc5f8ab61454a393f58d46e583 100644 (file)
@@ -2,7 +2,7 @@ versioninfo
 {
        "editorversion" "400"
        "editorbuild" "8075"
-       "mapversion" "357"
+       "mapversion" "379"
        "formatversion" "100"
        "prefab" "0"
 }
@@ -44,7 +44,7 @@ viewsettings
 world
 {
        "id" "1"
-       "mapversion" "357"
+       "mapversion" "379"
        "classname" "worldspawn"
        "detailmaterial" "detail/detailsprites"
        "detailvbsp" "detail.vbsp"
@@ -2636,10 +2636,80 @@ world
        }
 }
 entity
+{
+       "id" "3061"
+       "classname" "tar_color"
+       "_light" "0 255 0 255"
+       "origin" "-393 -64 48"
+       editor
+       {
+               "color" "220 30 220"
+               "visgroupshown" "1"
+               "visgroupautoshown" "1"
+               "logicalpos" "[0 0]"
+       }
+}
+entity
+{
+       "id" "3159"
+       "classname" "tar_color"
+       "_light" "255 255 0 255"
+       "origin" "-393 -64 208"
+       editor
+       {
+               "color" "220 30 220"
+               "visgroupshown" "1"
+               "visgroupautoshown" "1"
+               "logicalpos" "[0 0]"
+       }
+}
+entity
+{
+       "id" "3165"
+       "classname" "tar_color"
+       "_light" "198 57 149 255"
+       "origin" "-393 -64 224"
+       editor
+       {
+               "color" "220 30 220"
+               "visgroupshown" "1"
+               "visgroupautoshown" "1"
+               "logicalpos" "[0 0]"
+       }
+}
+entity
+{
+       "id" "3004"
+       "classname" "tar_color"
+       "_light" "255 0 0 255"
+       "origin" "-393 -64 80"
+       editor
+       {
+               "color" "220 30 220"
+               "visgroupshown" "1"
+               "visgroupautoshown" "1"
+               "logicalpos" "[0 0]"
+       }
+}
+entity
+{
+       "id" "3026"
+       "classname" "tar_color"
+       "_light" "0 0 255 255"
+       "origin" "-393 -64 104.5"
+       editor
+       {
+               "color" "220 30 220"
+               "visgroupshown" "1"
+               "visgroupautoshown" "1"
+               "logicalpos" "[0 0]"
+       }
+}
+entity
 {
        "id" "2969"
        "classname" "tar_max"
-       "origin" "-368.448 -11.867 140.175"
+       "origin" "-368.448 16 128"
        editor
        {
                "color" "127 224 0"
@@ -2652,7 +2722,7 @@ entity
 {
        "id" "2971"
        "classname" "tar_min"
-       "origin" "-344.583 -139.156 33"
+       "origin" "-344.583 640 -192"
        editor
        {
                "color" "127 224 0"
@@ -2667,7 +2737,7 @@ entity
        "classname" "tar_config"
        "aoSize" "1000"
        "background" "grid.png"
-       "colorScheme" "7"
+       "colorScheme" "-2"
        "customCol0" "104 15 15"
        "customCol1" "64 166 38"
        "customCol2" "44 199 199"
@@ -2687,7 +2757,7 @@ entity
        "zColCover2" "85 85 85 170"
        "zColObjective" "0 128 255 255"
        "zColOutline" "204 204 204 255"
-       "origin" "-240 592 33"
+       "origin" "-352 -144 33"
        editor
        {
                "color" "127 224 0"
index 1adf93a97544b91f24fbbaf16689774338fa15bf..b7af3492bd70ce1911590cd19bd2f4b67d57e054 100644 (file)
@@ -84,13 +84,18 @@ public:
                // Load color scheme gradient
                // TODO: Entity based gradients
                std::string schemeNum = kv::tryGetStringValue(kvs, "colorScheme", "0");
-               if (schemeNum == "-1" || schemeNum == "-2") {
+               if (schemeNum == "-1") {
                        this->m_texture_gradient = new GradientTexture(
                                kv::tryGetStringValue(kvs, "customCol0", "39  56  79  255"),
                                kv::tryGetStringValue(kvs, "customCol1", "77  74  72  255"),
                                kv::tryGetStringValue(kvs, "customCol2", "178 113 65  255")
                        );
-               } else {
+               }
+               else if (schemeNum == "-2") {
+                       // Do thi thening
+                       this->m_texture_gradient = new WGradientTexture(v->get_entities_by_classname("tar_color"));
+               }
+               else {
                        this->m_texture_gradient = new Texture("textures/gradients/gradientmap_" + schemeNum + ".png", true);
                }