From 68e6ebe24cb476997b2ddfc21a5b13fb6f332fa7 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Fri, 16 Jul 2021 21:00:28 +0300 Subject: Render texture onto window on each iteration. Keep colormap in renderer so we don't pass the colormapped windows like animals. Pre-render empty window. Fixes #15. --- src/live.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/live.cpp') diff --git a/src/live.cpp b/src/live.cpp index f1ae3d6..641eb7d 100644 --- a/src/live.cpp +++ b/src/live.cpp @@ -23,11 +23,17 @@ LiveOutput::LiveOutput(const Configuration& conf, const ColorMap& cmap, const Va /* FFT area raw memory used to update the area texture */ this->fft_area_.resize(conf.GetWidth() * conf.GetCount() * 4); /* RGBA pixel array */ + + /* render the live FFT area with a DC signal of zero */ + Render(); /* I don't have a good idea why this is needed, but I guess it has something to do with double buffering */ + this->renderer_.RenderFFTArea(this->fft_area_); + this->renderer_.RenderLiveFFT(RealWindow(conf.GetWidth())); } -void -LiveOutput::AddWindow(const std::vector& window, const RealWindow& win_values) +std::vector +LiveOutput::AddWindow(const RealWindow& win_values) { + auto window = this->renderer_.RenderLiveFFT(win_values); std::size_t wlen_bytes = this->configuration_.GetWidth() * 4; if (window.size() != wlen_bytes) { throw std::runtime_error("input window size differs from live window size"); @@ -43,12 +49,9 @@ LiveOutput::AddWindow(const std::vector& window, const RealWindow& win_ reinterpret_cast(window.data()), wlen_bytes); - /* update renderer */ + /* update renderer texture */ this->renderer_.RenderFFTArea(this->fft_area_); - this->renderer_.RenderLiveFFT(win_values, window); - - /* draw window */ - this->Render(); + return window; } bool @@ -65,6 +68,7 @@ LiveOutput::HandleEvents() void LiveOutput::Render() { + /* draw renderer output to window */ sf::Texture canvas_texture = this->renderer_.GetCanvas(); sf::Sprite canvas_sprite(canvas_texture); if (this->configuration_.IsHorizontal()) { @@ -74,4 +78,4 @@ LiveOutput::Render() this->window_.draw(canvas_sprite); this->window_.display(); -} \ No newline at end of file +} -- cgit v1.2.3