Fix Hud display for higher DPI (MBP retina)

This commit is contained in:
Takahito Tejima 2014-05-23 13:24:31 -07:00
parent 7f2b65ba46
commit 9a6c37b86d
5 changed files with 32 additions and 16 deletions

View File

@ -113,9 +113,9 @@ GLhud::~GLhud()
}
void
GLhud::Init(int width, int height)
GLhud::Init(int width, int height, int frameBufferWidth, int frameBufferHeight)
{
Hud::Init(width, height);
Hud::Init(width, height, frameBufferWidth, frameBufferHeight);
glGenTextures(1, &_fontTexture);
glBindTexture(GL_TEXTURE_2D, _fontTexture);
@ -195,9 +195,9 @@ GLhud::Init(int width, int height)
}
void
GLhud::Rebuild(int width, int height)
GLhud::Rebuild(int width, int height, int framebufferWidth, int framebufferHeight)
{
Hud::Rebuild(width, height);
Hud::Rebuild(width, height, framebufferWidth, framebufferHeight);
if (not _staticVbo)
return;
@ -209,7 +209,7 @@ GLhud::Rebuild(int width, int height)
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (GetFrameBuffer()) {
GetFrameBuffer()->Reshape(width, height);
GetFrameBuffer()->Reshape(framebufferWidth, framebufferHeight);
}
}

View File

@ -37,9 +37,18 @@ public:
GLhud();
~GLhud();
virtual void Init(int width, int height);
void Init(int width, int height) {
Init(width, height, width, height);
}
virtual void Rebuild(int width, int height);
void Rebuild(int width, int height) {
Rebuild(width, height, width, height);
}
virtual void Init(int width, int height, int framebufferWidth, int framebufferHeight);
virtual void Rebuild(int width, int height,
int framebufferWidth, int framebufferHeight);
virtual bool Flush();

View File

@ -35,6 +35,7 @@
#endif
Hud::Hud() : _visible(true), _windowWidth(0), _windowHeight(0),
_framebufferWidth(0), _framebufferHeight(0),
_requiresRebuildStatic(true)
{
_capturedSlider = -1;
@ -45,10 +46,12 @@ Hud::~Hud()
}
void
Hud::Init(int width, int height)
Hud::Init(int width, int height, int framebufferWidth, int framebufferHeight)
{
_windowWidth = width;
_windowHeight = height;
_framebufferWidth = framebufferWidth;
_framebufferHeight = framebufferHeight;
}
int
@ -460,11 +463,13 @@ Hud::DrawString(int x, int y, float r, float g, float b, const char *fmt, ...)
}
void
Hud::Rebuild(int width, int height)
Hud::Rebuild(int width, int height, int framebufferWidth, int framebufferHeight)
{
_requiresRebuildStatic = false;
_windowWidth = width;
_windowHeight = height;
_framebufferWidth = framebufferWidth;
_framebufferHeight = framebufferHeight;
_staticVboSource.clear();
@ -562,7 +567,7 @@ Hud::Flush()
}
if (_requiresRebuildStatic)
Rebuild(_windowWidth, _windowHeight);
Rebuild(_windowWidth, _windowHeight, _framebufferWidth, _framebufferHeight);
return true;
}

View File

@ -43,9 +43,10 @@ public:
Hud();
virtual ~Hud();
virtual void Init(int width, int height);
virtual void Init(int width, int height, int framebufferWidth, int framebufferHeight);
virtual void Rebuild(int width, int height);
virtual void Rebuild(int width, int height,
int framebufferWidth, int framebufferHeight);
virtual bool Flush();
@ -173,6 +174,7 @@ private:
bool _visible;
std::vector<float> _vboSource, _staticVboSource;
int _windowWidth, _windowHeight;
int _framebufferWidth, _framebufferHeight;
bool _requiresRebuildStatic;
std::vector<Item> _labels;
std::vector<RadioButton> _radioButtons;

View File

@ -1560,7 +1560,6 @@ reshape(GLFWwindow *, int width, int height) {
#else
reshape(int width, int height) {
#endif
g_width = width;
g_height = height;
@ -1569,7 +1568,7 @@ reshape(int width, int height) {
// window size might not match framebuffer size on a high DPI display
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
#endif
g_hud.Rebuild(windowWidth, windowHeight);
g_hud.Rebuild(windowWidth, windowHeight, width, height);
}
//------------------------------------------------------------------------------
@ -1722,14 +1721,15 @@ static void
initHUD()
{
int windowWidth = g_width, windowHeight = g_height;
int frameBufferWidth = g_width, frameBufferHeight = g_height;
#if GLFW_VERSION_MAJOR>=3
// window size might not match framebuffer size on a high DPI display
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
glfwGetFramebufferSize(g_window, &frameBufferWidth, &frameBufferHeight);
#endif
g_hud.Init(windowWidth, windowHeight, frameBufferWidth, frameBufferHeight);
g_hud.Init(windowWidth, windowHeight);
g_hud.SetFrameBuffer(new SSAOGLFrameBuffer);
g_hud.AddCheckBox("Cage Edges (H)", g_drawCageEdges != 0,