Enable alpha blending. main reads from stdin

This commit is contained in:
2025-08-25 03:43:30 -05:00
parent 59162408f1
commit e5a8f88556
3 changed files with 32 additions and 40 deletions

View File

@@ -19,6 +19,7 @@
#include <pthread.h>
#include <string>
#include <winnt.h>
#include <algorithm>
#include "util.hpp"
#include "shaders.hpp"
@@ -143,6 +144,7 @@ DllExport void __cdecl update_point(pointid id, float x, float y, float z) {
Point* p = id_to_point[id];
p->targetloc = { x, y, z };
p->startloc = p->b.pose[3];
p->start_s = _time();
LeaveCriticalSection(&cs);
}
@@ -218,6 +220,8 @@ DWORD _win_thread(LPVOID args) {
glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer again (former front buf)
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
while (!(glfwWindowShouldClose(win) || stop_flag))
_refresh_win();
@@ -264,10 +268,12 @@ void _refresh_win() {
// Perform fade
double elapsed_time_s = _time() - p->start_s;
float t = elapsed_time_s / p->lifetime_s;
p->b.color[3] = lerp(1.0, 0.0, t);
t = std::clamp(t, 0.0f, 1.0f);
p->b.color.w = lerp(1.0, 0.0, t);
// Lerp position
t = elapsed_time_s / LERP_MOVE_PERIOD_S;
t = std::clamp(t, 0.0f, 1.0f);
p->b.pose[3] = glm::vec4(lerp(p->startloc, p->targetloc, t), 1);
draw_body(p->b);
}

View File

@@ -1,43 +1,11 @@
#include <iostream>
#include <string>
#include <map>
#include "camera_poses.hpp"
#include "live_plotter.hpp"
//void* process_cin(void* args) {
// std::string line;
// while (true) {
// std::getline(std::cin, line);
// Array<char*> words = split_str(line.c_str());
// if (!words.len == 4)
// return NULL;
// printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
// float x = atof(words[1]);
// float y = atof(words[2]);
// float z = atof(words[3]);
// glm::vec3 new_loc = glm::vec3(x, y, z);
// bool found_match = false;
// for (int i = 0; i < camera_bodies.size(); i++) {
// if (strcmp(words[0], camera_bodies[i].name) == 0 && camera_bodies[i].b) {
// Body& b = *camera_bodies[i].b;
// glm::vec4& transl = b.pose[3];
// transl = (0.8f * transl) + (0.2f * glm::vec4(new_loc, 1)); // lp filter
// int color_i = i + 1;
// b.color = glm::vec4(color_i & 0x4, color_i & 0x2, color_i & 0x1, 1); // reset alpha to 1
// camera_bodies[i].hp = max_hp;
// found_match = true;
// } else if (camera_bodies[i].b) {
// float& cur_hp = camera_bodies[i].hp;
// if (cur_hp > 0)
// cur_hp -= 1;
// camera_bodies[i].b->color = glm::vec4(i & 0x4, i & 0x2, i & 0x1, cur_hp / max_hp);
// }
// }
// if (!found_match) {
// auto read = BarcodeRead { words[0], (Body*)NULL, max_hp };
// camera_bodies.push_back(read);
// }
// }
//}
static std::map<std::string, pointid> name_to_id;
int main() {
Array<glm::mat2x3> camera_pose_axes = { NULL, 0 };
@@ -55,6 +23,24 @@ int main() {
set_scale(id, 10);
}
while (true)
;
while (true) {
std::string line;
std::getline(std::cin, line);
Array<char*> words = split_str(line.c_str());
if (!words.len == 4)
return NULL;
printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
std::string name = std::string(words[0]);
float x = atof(words[1]);
float y = atof(words[2]);
float z = atof(words[3]);
if (auto it = name_to_id.find(name); it != name_to_id.end()) {
update_point(it->second, x, y, z);
} else {
name_to_id[name] = create_point(x, y, z);
set_lifetime(name_to_id[name], 0.2);
set_scale(name_to_id[name], 15);
}
}
}

View File

@@ -10,7 +10,7 @@ void main() {
vec3 dx = dFdx(frag_pos) * 500;
vec3 dy = dFdy(frag_pos) * 500;
vec3 N = normalize(cross(dFdx(frag_pos), dFdy(frag_pos)));
frag_color = color + vec4(N/2, 1)/2;
frag_color = color;
//frag_color = vec4(length(dx), length(dy), length(dy), 1.0);
//frag_color += color;
}