mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-04 06:07:49 -04:00
Unify demod drawing functions
This commit is contained in:
parent
7f9a871598
commit
33e2e18c57
@ -66,3 +66,94 @@ GLFont *PrimaryGLContext::getFont() {
|
|||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
|
||||||
|
if (!demod) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE;
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
||||||
|
glColor4f(r, g, b, 0.6);
|
||||||
|
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
||||||
|
|
||||||
|
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
|
||||||
|
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
||||||
|
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
||||||
|
glColor4f(r, g, b, 0.2);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
||||||
|
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
|
||||||
|
DemodulatorInstance *demod = wxGetApp().getDemodTest();
|
||||||
|
|
||||||
|
if (!demod) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
||||||
|
glColor4f(r, g, b, 0.6);
|
||||||
|
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
||||||
|
|
||||||
|
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
|
||||||
|
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
||||||
|
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
||||||
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimaryGLContext::BeginDraw() {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrimaryGLContext::EndDraw() {
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
CheckGLError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "CubicSDRDefs.h"
|
#include "CubicSDRDefs.h"
|
||||||
#include "GLFont.h"
|
#include "GLFont.h"
|
||||||
|
#include "DemodulatorMgr.h"
|
||||||
|
|
||||||
class PrimaryGLContext: public wxGLContext {
|
class PrimaryGLContext: public wxGLContext {
|
||||||
public:
|
public:
|
||||||
@ -16,6 +17,12 @@ public:
|
|||||||
static wxString glGetwxString(GLenum name);
|
static wxString glGetwxString(GLenum name);
|
||||||
static void CheckGLError();
|
static void CheckGLError();
|
||||||
|
|
||||||
|
void BeginDraw();
|
||||||
|
void EndDraw();
|
||||||
|
|
||||||
|
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1);
|
||||||
|
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
||||||
|
|
||||||
static GLFont *getFont();
|
static GLFont *getFont();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -61,8 +61,17 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
|||||||
glContext->SetCurrent(*this);
|
glContext->SetCurrent(*this);
|
||||||
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
||||||
|
|
||||||
|
glContext->BeginDraw();
|
||||||
glContext->Draw(spectrum_points);
|
glContext->Draw(spectrum_points);
|
||||||
|
|
||||||
|
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
|
||||||
|
|
||||||
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
|
glContext->DrawDemod(demods[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
glContext->EndDraw();
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +82,13 @@ void SpectrumCanvas::OnKeyDown(wxKeyEvent& event) {
|
|||||||
switch (event.GetKeyCode()) {
|
switch (event.GetKeyCode()) {
|
||||||
case WXK_RIGHT:
|
case WXK_RIGHT:
|
||||||
freq = wxGetApp().getFrequency();
|
freq = wxGetApp().getFrequency();
|
||||||
freq += SRATE/2;
|
freq += SRATE / 2;
|
||||||
wxGetApp().setFrequency(freq);
|
wxGetApp().setFrequency(freq);
|
||||||
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
||||||
break;
|
break;
|
||||||
case WXK_LEFT:
|
case WXK_LEFT:
|
||||||
freq = wxGetApp().getFrequency();
|
freq = wxGetApp().getFrequency();
|
||||||
freq -= SRATE/2;
|
freq -= SRATE / 2;
|
||||||
wxGetApp().setFrequency(freq);
|
wxGetApp().setFrequency(freq);
|
||||||
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
||||||
break;
|
break;
|
||||||
@ -119,12 +128,12 @@ void SpectrumCanvas::setData(std::vector<signed char> *data) {
|
|||||||
|
|
||||||
int n;
|
int n;
|
||||||
for (int i = 0, iMax = FFT_SIZE / 2; i < iMax; i++) {
|
for (int i = 0, iMax = FFT_SIZE / 2; i < iMax; i++) {
|
||||||
n = (i == 0)?1:i;
|
n = (i == 0) ? 1 : i;
|
||||||
double a = out[n][0];
|
double a = out[n][0];
|
||||||
double b = out[n][1];
|
double b = out[n][1];
|
||||||
double c = sqrt(a * a + b * b);
|
double c = sqrt(a * a + b * b);
|
||||||
|
|
||||||
n = (i == FFT_SIZE/2)?(FFT_SIZE/2+1):i;
|
n = (i == FFT_SIZE / 2) ? (FFT_SIZE / 2 + 1) : i;
|
||||||
double x = out[FFT_SIZE / 2 + n][0];
|
double x = out[FFT_SIZE / 2 + n][0];
|
||||||
double y = out[FFT_SIZE / 2 + n][1];
|
double y = out[FFT_SIZE / 2 + n][1];
|
||||||
double z = sqrt(x * x + y * y);
|
double z = sqrt(x * x + y * y);
|
||||||
|
@ -13,13 +13,8 @@ SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumContext::Draw(std::vector<float> &points) {
|
void SpectrumContext::Draw(std::vector<float> &points) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
if (points.size()) {
|
if (points.size()) {
|
||||||
|
@ -37,12 +37,6 @@ WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedC
|
|||||||
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]);
|
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterfallContext::BeginDraw() {
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaterfallContext::Draw(std::vector<float> &points) {
|
void WaterfallContext::Draw(std::vector<float> &points) {
|
||||||
|
|
||||||
@ -82,83 +76,3 @@ void WaterfallContext::Draw(std::vector<float> &points) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterfallContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
|
|
||||||
if (!demod) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE;
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
|
||||||
glColor4f(r, g, b, 0.6);
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
|
||||||
|
|
||||||
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
|
|
||||||
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
|
||||||
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
|
||||||
glColor4f(r, g, b, 0.2);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
|
||||||
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaterfallContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
|
|
||||||
DemodulatorInstance *demod = wxGetApp().getDemodTest();
|
|
||||||
|
|
||||||
if (!demod) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
|
||||||
glColor4f(r, g, b, 0.6);
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
|
||||||
|
|
||||||
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
|
|
||||||
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
|
||||||
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
|
||||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaterfallContext::EndDraw() {
|
|
||||||
glFlush();
|
|
||||||
|
|
||||||
CheckGLError();
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "PrimaryGLContext.h"
|
#include "PrimaryGLContext.h"
|
||||||
#include "Gradient.h"
|
#include "Gradient.h"
|
||||||
#include "DemodulatorMgr.h"
|
|
||||||
|
|
||||||
#define NUM_WATERFALL_LINES 512
|
#define NUM_WATERFALL_LINES 512
|
||||||
|
|
||||||
@ -12,11 +11,8 @@ class WaterfallContext: public PrimaryGLContext {
|
|||||||
public:
|
public:
|
||||||
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
|
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
|
||||||
|
|
||||||
void BeginDraw();
|
|
||||||
void Draw(std::vector<float> &points);
|
void Draw(std::vector<float> &points);
|
||||||
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1);
|
|
||||||
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
|
||||||
void EndDraw();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gradient grad;
|
Gradient grad;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user