2014-11-15 23:41:41 -05:00
|
|
|
#include "WaterfallContext.h"
|
|
|
|
#include "WaterfallCanvas.h"
|
2014-11-25 22:51:14 -05:00
|
|
|
#include "CubicSDR.h"
|
2014-11-15 23:41:41 -05:00
|
|
|
|
|
|
|
WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) :
|
|
|
|
PrimaryGLContext(canvas, sharedContext) {
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glGenTextures(1, &waterfall);
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, waterfall);
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
|
|
|
|
|
|
|
grad.addColor(GradientColor(0, 0, 0));
|
|
|
|
grad.addColor(GradientColor(0, 0, 1.0));
|
|
|
|
grad.addColor(GradientColor(0, 1.0, 0));
|
|
|
|
grad.addColor(GradientColor(1.0, 1.0, 0));
|
|
|
|
grad.addColor(GradientColor(1.0, 0.2, 0.0));
|
|
|
|
|
|
|
|
grad.generate(256);
|
|
|
|
|
|
|
|
glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
|
|
|
|
glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, &(grad.getRed())[0]);
|
|
|
|
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, &(grad.getGreen())[0]);
|
|
|
|
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]);
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:51:14 -05:00
|
|
|
void WaterfallContext::BeginDraw() {
|
2014-11-15 23:41:41 -05:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2014-11-25 22:51:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaterfallContext::Draw(std::vector<float> &points) {
|
2014-11-15 23:41:41 -05:00
|
|
|
|
|
|
|
if (points.size()) {
|
|
|
|
memmove(waterfall_tex + FFT_SIZE, waterfall_tex, (NUM_WATERFALL_LINES - 1) * FFT_SIZE);
|
|
|
|
|
|
|
|
for (int i = 0, iMax = FFT_SIZE; i < iMax; i++) {
|
|
|
|
float v = points[i * 2 + 1];
|
|
|
|
|
|
|
|
float wv = v;
|
|
|
|
if (wv < 0.0)
|
|
|
|
wv = 0.0;
|
|
|
|
if (wv > 1.0)
|
|
|
|
wv = 1.0;
|
|
|
|
waterfall_tex[i] = (unsigned char) floor(wv * 255.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:51:14 -05:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
glBindTexture(GL_TEXTURE_2D, waterfall);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, FFT_SIZE, NUM_WATERFALL_LINES, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid *) waterfall_tex);
|
|
|
|
|
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, waterfall);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f(0.0, 1.0);
|
|
|
|
glVertex3f(-1.0, -1.0, 0.0);
|
|
|
|
glTexCoord2f(1.0, 1.0);
|
|
|
|
glVertex3f(1.0, -1.0, 0.0);
|
|
|
|
glTexCoord2f(1.0, 0.0);
|
|
|
|
glVertex3f(1.0, 1.0, 0.0);
|
|
|
|
glTexCoord2f(0.0, 0.0);
|
|
|
|
glVertex3f(-1.0, 1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
|
2014-11-25 22:51:14 -05:00
|
|
|
}
|
|
|
|
|
2014-11-30 18:54:13 -05:00
|
|
|
void WaterfallContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
|
2014-11-26 21:05:19 -05:00
|
|
|
if (!demod) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE;
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
2014-11-30 17:59:24 -05:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
2014-11-30 18:54:13 -05:00
|
|
|
glColor4f(r, g, b, 0.6);
|
2014-11-26 21:05:19 -05:00
|
|
|
|
|
|
|
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();
|
2014-11-30 17:59:24 -05:00
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
2014-11-30 18:54:13 -05:00
|
|
|
glColor4f(r, g, b, 0.2);
|
2014-11-30 17:59:24 -05:00
|
|
|
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);
|
2014-11-26 21:05:19 -05:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-30 18:54:13 -05:00
|
|
|
void WaterfallContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
|
2014-11-25 22:51:14 -05:00
|
|
|
DemodulatorInstance *demod = wxGetApp().getDemodTest();
|
|
|
|
|
|
|
|
if (!demod) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-26 21:05:19 -05:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2014-11-25 22:51:14 -05:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
2014-11-30 17:59:24 -05:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
|
|
|
glColor4f(r, g, b, 0.6);
|
2014-11-25 22:51:14 -05:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
|
|
|
|
2014-11-26 21:05:19 -05:00
|
|
|
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
|
2014-11-25 22:51:14 -05:00
|
|
|
|
|
|
|
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();
|
2014-11-30 17:59:24 -05:00
|
|
|
glDisable(GL_BLEND);
|
2014-11-26 21:05:19 -05:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2014-11-25 22:51:14 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaterfallContext::EndDraw() {
|
2014-11-15 23:41:41 -05:00
|
|
|
glFlush();
|
|
|
|
|
|
|
|
CheckGLError();
|
|
|
|
}
|