summaryrefslogtreecommitdiffstats
path: root/Project/OpenGLText.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-06-02 21:47:06 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-06-02 21:47:06 -0300
commit113a35d0fe8938973fa1c100b77f456ed250e61b (patch)
tree586d1c3113082cbb2b92cd46c3c96a25a0e75e67 /Project/OpenGLText.cpp
parent6ce2bdcf85dffee6b6ef7b95b888b8b96372a3d6 (diff)
downloadPSP.git-113a35d0fe8938973fa1c100b77f456ed250e61b.tar.gz
PSP.git-113a35d0fe8938973fa1c100b77f456ed250e61b.tar.xz
PSP.git-113a35d0fe8938973fa1c100b77f456ed250e61b.zip
OpenGL bugfixes and wxGC port alternative init
OpenGL major bugfixes; Device context port alternative to OpenGL code init (WorkspaceDC). Some machines don't support OpenGL 3+; Fixed some issues with MSVC.
Diffstat (limited to 'Project/OpenGLText.cpp')
-rw-r--r--Project/OpenGLText.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/Project/OpenGLText.cpp b/Project/OpenGLText.cpp
index 5e1c40b..0dca4eb 100644
--- a/Project/OpenGLText.cpp
+++ b/Project/OpenGLText.cpp
@@ -16,7 +16,9 @@
*/
#include <wx/log.h>
+#include <wx/graphics.h>
#include "OpenGLText.h"
+#include <algorithm>
OpenGLText::OpenGLText() { Init(); }
OpenGLText::OpenGLText(wxString text)
@@ -69,11 +71,40 @@ void OpenGLText::Draw(wxPoint2DDouble position, double angle) const
}
}
+void OpenGLText::DrawDC(wxPoint2DDouble position, wxGraphicsContext* gc, double angle) const
+{
+ gc->SetFont(wxFont(m_fontSize, m_fontFamily, m_fontStyle, m_fontWeight), wxColour(0, 0 , 0 , 255));
+ gc->DrawText(m_text, position.m_x, position.m_y, angle);
+}
+
void OpenGLText::SetText(wxString text)
{
m_text = text;
- TextToBitmap();
- LoadTextTexture();
+ bool contextValid = false;
+#ifdef __LINUX__
+ if(glXGetCurrentContext()) contextValid = true;
+#endif
+#ifdef __APPLE__
+ if(aglGetCurrentContext()) contextValid = true;
+#endif
+#ifdef __WINDOWS__
+ if (wglGetCurrentContext()) contextValid = true;
+#endif
+
+ if (contextValid) {
+ TextToBitmap();
+ LoadTextTexture();
+ }
+ else
+ {
+ // If the context is not valid, the text still can be rendered using wxDC.
+ // So, the text size must be calculated
+ wxFont font = wxFont(m_fontSize, m_fontFamily, m_fontStyle, m_fontWeight);
+
+ wxMemoryDC memDC;
+ memDC.SetFont(font);
+ m_bitmapSize = memDC.GetTextExtent(m_text);
+ }
}
int OpenGLText::RoundToPowerOfTwo(int value, int min)
@@ -81,7 +112,8 @@ int OpenGLText::RoundToPowerOfTwo(int value, int min)
//[Ref] https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2
double baseOfTwo = std::log(static_cast<double>(value)) / std::log(2.0);
int powerOfTwo = static_cast<int>(std::pow(2.0, static_cast<int>(std::ceil(baseOfTwo))));
- return std::max(min, powerOfTwo);
+ //return std::max(min, powerOfTwo);
+ return min > powerOfTwo ? min : powerOfTwo;
}
void OpenGLText::TextToBitmap()