mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-04-02 17:48:42 -04:00
Unify demod drawing functions
This commit is contained in:
parent
7f9a871598
commit
33e2e18c57
@ -66,3 +66,94 @@ GLFont *PrimaryGLContext::getFont() {
|
||||
|
||||
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 "GLFont.h"
|
||||
#include "DemodulatorMgr.h"
|
||||
|
||||
class PrimaryGLContext: public wxGLContext {
|
||||
public:
|
||||
@ -16,6 +17,12 @@ public:
|
||||
static wxString glGetwxString(GLenum name);
|
||||
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();
|
||||
|
||||
private:
|
||||
|
@ -61,8 +61,17 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
glContext->SetCurrent(*this);
|
||||
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
||||
|
||||
glContext->BeginDraw();
|
||||
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();
|
||||
}
|
||||
|
||||
@ -73,13 +82,13 @@ void SpectrumCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
switch (event.GetKeyCode()) {
|
||||
case WXK_RIGHT:
|
||||
freq = wxGetApp().getFrequency();
|
||||
freq += SRATE/2;
|
||||
freq += SRATE / 2;
|
||||
wxGetApp().setFrequency(freq);
|
||||
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
||||
break;
|
||||
case WXK_LEFT:
|
||||
freq = wxGetApp().getFrequency();
|
||||
freq -= SRATE/2;
|
||||
freq -= SRATE / 2;
|
||||
wxGetApp().setFrequency(freq);
|
||||
((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq));
|
||||
break;
|
||||
@ -119,12 +128,12 @@ void SpectrumCanvas::setData(std::vector<signed char> *data) {
|
||||
|
||||
int n;
|
||||
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 b = out[n][1];
|
||||
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 y = out[FFT_SIZE / 2 + n][1];
|
||||
double z = sqrt(x * x + y * y);
|
||||
|
@ -13,13 +13,8 @@ SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedCont
|
||||
}
|
||||
|
||||
void SpectrumContext::Draw(std::vector<float> &points) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
|
||||
if (points.size()) {
|
||||
|
@ -37,12 +37,6 @@ WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedC
|
||||
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) {
|
||||
|
||||
@ -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 "Gradient.h"
|
||||
#include "DemodulatorMgr.h"
|
||||
|
||||
#define NUM_WATERFALL_LINES 512
|
||||
|
||||
@ -12,11 +11,8 @@ class WaterfallContext: public PrimaryGLContext {
|
||||
public:
|
||||
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
|
||||
|
||||
void BeginDraw();
|
||||
|
||||
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:
|
||||
Gradient grad;
|
||||
|
Loading…
Reference in New Issue
Block a user