CubicSDR/src/visual/PrimaryGLContext.cpp

69 lines
1.4 KiB
C++
Raw Normal View History

#include "PrimaryGLContext.h"
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#if !wxUSE_GLCANVAS
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
#endif
#include "CubicSDR.h"
#include "CubicSDRDefs.h"
#include "AppFrame.h"
#include <algorithm>
2014-11-09 04:38:33 -05:00
2014-12-08 02:16:06 -05:00
GLFont *PrimaryGLContext::font = NULL;
wxString PrimaryGLContext::glGetwxString(GLenum name) {
const GLubyte *v = glGetString(name);
if (v == 0) {
// The error is not important. It is GL_INVALID_ENUM.
// We just want to clear the error stack.
glGetError();
return wxString();
}
return wxString((const char*) v);
}
void PrimaryGLContext::CheckGLError() {
GLenum errLast = GL_NO_ERROR;
for (;;) {
GLenum err = glGetError();
if (err == GL_NO_ERROR)
return;
if (err == errLast) {
wxLogError
(wxT("OpenGL error state couldn't be reset."));
return;
}
errLast = err;
wxLogError
(wxT("OpenGL error %d"), err);
}
}
PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext) :
wxGLContext(canvas, sharedContext) {
SetCurrent(*canvas);
CheckGLError();
}
2014-12-08 02:16:06 -05:00
GLFont *PrimaryGLContext::getFont() {
if (font == NULL) {
font = new GLFont();
font->loadFont("vera_sans_mono.fnt");
}
return font;
}