Added frequency labels, 100khz intervals

This commit is contained in:
Charles J. Cliffe
2014-12-09 21:28:08 -05:00
parent 33e2e18c57
commit 34a6d3f5e0
26 changed files with 1423 additions and 197 deletions
+11 -14
View File
@@ -5,7 +5,7 @@
#include <algorithm>
GLFontChar::GLFontChar() :
id(0), x(0), y(0), width(0), height(0), xadvance(0), xoffset(0), yoffset(0), index(0) {
id(0), x(0), y(0), width(0), height(0), xadvance(0), xoffset(0), yoffset(0), index(0), aspect(1) {
}
@@ -96,7 +96,7 @@ int GLFontChar::getIndex() {
}
GLFont::GLFont() :
numCharacters(0), imageHeight(0), imageWidth(0), base(0), lineHeight(0), texId(0) {
numCharacters(0), imageHeight(0), imageWidth(0), base(0), lineHeight(0), texId(0), loaded(false) {
}
@@ -277,8 +277,8 @@ void GLFont::loadFont(std::string fontFile) {
glGenTextures(1, &texId);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image[0]);
glDisable(GL_TEXTURE_2D);
@@ -303,29 +303,21 @@ void GLFont::loadFont(std::string fontFile) {
gl_vertices[ofs + 1] = 0;
gl_uv[ofs] = uv_xpos;
gl_uv[ofs + 1] = uv_ypos + uv_yofs;
// gl_uv[ofs] = 0;
// gl_uv[ofs + 1] = 1;
gl_vertices[ofs + 2] = faspect;
gl_vertices[ofs + 3] = 0;
gl_uv[ofs + 2] = uv_xpos + uv_xofs;
gl_uv[ofs + 3] = uv_ypos + uv_yofs;
// gl_uv[ofs + 2] = 1;
// gl_uv[ofs + 3] = 1;
gl_vertices[ofs + 4] = faspect;
gl_vertices[ofs + 5] = 1;
gl_uv[ofs + 4] = uv_xpos + uv_xofs;
gl_uv[ofs + 5] = uv_ypos;
// gl_uv[ofs + 4] = 1;
// gl_uv[ofs + 5] = 0;
gl_vertices[ofs + 6] = 0;
gl_vertices[ofs + 7] = 1;
gl_uv[ofs + 6] = uv_xpos;
gl_uv[ofs + 7] = uv_ypos;
// gl_uv[ofs + 6] = 0;
// gl_uv[ofs + 7] = 0;
fchar->setIndex(ofs);
@@ -333,6 +325,7 @@ void GLFont::loadFont(std::string fontFile) {
}
std::cout << "Loaded font '" << fontName << "' from '" << fontFileSource << "', parsed " << characters.size() << " characters." << std::endl;
loaded = true;
} else {
std::cout << "Error loading font file " << fontFileSource << std::endl;
}
@@ -340,6 +333,10 @@ void GLFont::loadFont(std::string fontFile) {
input.close();
}
bool GLFont::isLoaded() {
return loaded;
}
float GLFont::getStringWidth(std::string str, float size, float viewAspect) {
float scalex = size / viewAspect;
@@ -362,7 +359,7 @@ float GLFont::getStringWidth(std::string str, float size, float viewAspect) {
advx = characters['_']->getAspect();
}
width += fchar->getAspect() + advx - ofsx;
width += fchar->getAspect() + advx + ofsx;
}
width *= scalex;
@@ -437,7 +434,7 @@ void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, A
advx = characters['_']->getAspect();
}
glTranslatef(-ofsx, 0.0, 0.0);
glTranslatef(ofsx, 0.0, 0.0);
glDrawArrays(GL_QUADS, fchar->getIndex() / 2, 4);
glTranslatef(fchar->getAspect() + advx, 0.0, 0.0);
}
+2
View File
@@ -63,6 +63,7 @@ public:
GLFont();
~GLFont();
void loadFont(std::string fontFile);
bool isLoaded();
float getStringWidth(std::string str, float size, float viewAspect);
void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP);
@@ -76,6 +77,7 @@ private:
int lineHeight;
int base;
int imageWidth, imageHeight;
bool loaded;
std::map<int, GLFontChar *> characters;
+51 -8
View File
@@ -15,7 +15,7 @@
#include "AppFrame.h"
#include <algorithm>
GLFont *PrimaryGLContext::font = NULL;
GLFont PrimaryGLContext::fonts[GLFONT_MAX];
wxString PrimaryGLContext::glGetwxString(GLenum name) {
const GLubyte *v = glGetString(name);
@@ -58,15 +58,60 @@ PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContex
CheckGLError();
}
GLFont *PrimaryGLContext::getFont() {
if (font == NULL) {
font = new GLFont();
font->loadFont("vera_sans_mono.fnt");
GLFont &PrimaryGLContext::getFont(GLFontSize esize) {
if (!fonts[esize].isLoaded()) {
std::string fontName;
switch (esize) {
case GLFONT_SIZE12: fontName = "vera_sans_mono12.fnt";
break;
case GLFONT_SIZE16: fontName = "vera_sans_mono16.fnt";
break;
case GLFONT_SIZE18: fontName = "vera_sans_mono18.fnt";
break;
case GLFONT_SIZE24: fontName = "vera_sans_mono24.fnt";
break;
case GLFONT_SIZE32: fontName = "vera_sans_mono32.fnt";
break;
case GLFONT_SIZE48: fontName = "vera_sans_mono48.fnt";
break;
}
fonts[esize].loadFont(fontName);
}
return font;
return fonts[esize];
}
void PrimaryGLContext::DrawDemodInfo(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);
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
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::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
if (!demod) {
@@ -108,7 +153,6 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
@@ -150,7 +194,6 @@ void PrimaryGLContext::BeginDraw() {
glLoadIdentity();
}
void PrimaryGLContext::EndDraw() {
glFlush();
+4 -2
View File
@@ -12,6 +12,7 @@
class PrimaryGLContext: public wxGLContext {
public:
enum GLFontSize { GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX };
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
static wxString glGetwxString(GLenum name);
@@ -22,9 +23,10 @@ public:
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 DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
static GLFont *getFont();
static GLFont &getFont(GLFontSize esize);
private:
static GLFont *font;
static GLFont fonts[GLFONT_MAX];
};
+1 -1
View File
@@ -67,7 +67,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
glContext->DrawDemod(demods[i]);
glContext->DrawDemodInfo(demods[i]);
}
glContext->EndDraw();
+53 -1
View File
@@ -1,6 +1,9 @@
#include "SpectrumContext.h"
#include "SpectrumCanvas.h"
#include "CubicSDR.h"
#include <sstream>
#include <iostream>
SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext) {
@@ -28,7 +31,56 @@ void SpectrumContext::Draw(std::vector<float> &points) {
glPopMatrix();
}
getFont()->drawString("Welcome to CubicSDR -- This is a test string. 01234567890!@#$%^&*()_[]",0.0,0.0,31,GLFont::GLFONT_ALIGN_CENTER,GLFont::GLFONT_ALIGN_CENTER);
GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3];
float leftFreq = (float) wxGetApp().getFrequency() - ((float) SRATE / 2.0);
float rightFreq = leftFreq + (float) SRATE;
float firstMhz = floor(leftFreq / 1000000.0) * 1000000.0;
float mhzStart = ((firstMhz - leftFreq) / (rightFreq - leftFreq)) * 2.0;
float mhzStep = (100000.0 / (rightFreq - leftFreq)) * 2.0;
double currentMhz = trunc(floor(firstMhz / 1000000.0));
std::stringstream label;
label.precision(2);
float hPos = 1.0 - (16.0 / viewHeight);
float lMhzPos = 1.0 - (5.0 / viewHeight);
for (float m = -1.0 + mhzStart, mMax = 1.0 + fabs(mhzStart); m <= mMax; m += mhzStep) {
label << std::fixed << currentMhz;
double fractpart, intpart;
fractpart = modf(currentMhz, &intpart);
if (fractpart < 0.001) {
glLineWidth(4.0);
glColor3f(1.0, 1.0, 1.0);
} else {
glLineWidth(1.0);
glColor3f(0.55, 0.55, 0.55);
}
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2f(m, lMhzPos);
glVertex2f(m, 1);
glEnd();
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
label.str(std::string());
currentMhz += 0.1f;
}
glLineWidth(1.0);
// getFont(PrimaryGLContext::GLFONT_SIZE16).drawString("Welcome to CubicSDR -- This is a test string. 01234567890!@#$%^&*()_[]",0.0,0.0,16,GLFont::GLFONT_ALIGN_CENTER,GLFont::GLFONT_ALIGN_CENTER);
CheckGLError();
}