Unify demod drawing functions

This commit is contained in:
Charles J. Cliffe 2014-12-08 21:08:03 -05:00
parent 7f9a871598
commit 33e2e18c57
6 changed files with 112 additions and 100 deletions

View File

@ -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();
}

View File

@ -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:

View File

@ -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();
}

View File

@ -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()) {

View File

@ -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();
}

View File

@ -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;