This pertains to Box2D v2.3.1 and OSX 10.9.3 on Macintosh with Retina display
See: http://www.glfw.org/faq.html section 4.3
Problem:
Testbed starts with a window that is twice as large in width and height as the viewport and the mouse pointer does not correspond with locations within the viewport. Also the control panel is positioned toward the center rather than edge of the window.
Solution:
The retina display does not have a 1:1 mapping between window size and pixels. Rather than initializing the viewport with the window size as returned by glfwGetWindowSize use the pixel count as returned by glfwGetFrameBufferSize. Also to get the mouse to work properly with the control panel you have to make a few other changes.
Modify Code as follows:
All changes are in Testbed Framework files DebugDraw.h and main.cpp
DebugDraw.h near line 32
//SES Add m_width_px and m_height_px to hold screen size in pixels
struct Camera
{
Camera()
{
m_center.Set(0.0f, 20.0f);
m_extent = 25.0f;
m_zoom = 1.0f;
m_width = 1280;
m_height = 800;
m_width_px = 1280;
m_height_px = 800;
}
main.cpp near 344
//SES Use window pixel dimensions
bool over = imguiBeginScrollArea("Testbed Controls", g_camera.m_width_px - menuWidth - 10, 10, menuWidth, g_camera.m_height_px - 20, &ui.scrollarea1);
main.cpp near line 414
//SES Use window pixel dimensions
bool over = imguiBeginScrollArea("Choose Sample", g_camera.m_width_px - menuWidth - testMenuWidth - 20, 10, testMenuWidth, g_camera.m_height_px - 20, &testScroll);
main.cpp near 443
//SES Initialize Camera members
g_camera.m_width = g_camera.m_width_px = 1024;
g_camera.m_height = g_camera.m_height_px = 640;
main.cpp near line 520
//SES Set viewport using window size in pixels and as a side effect save the pixel dimensions
// in the Camera structure.
glfwGetFramebufferSize(mainWindow, &g_camera.m_width_px, &g_camera.m_height_px);
glViewport(0, 0, g_camera.m_width_px, g_camera.m_height_px);
main.cpp near line 547
//SES Calculate the mapping factor between screen coordinates and pixels
int pixel_mapping = int(floor((g_camera.m_height_px/g_camera.m_height)+0.5f));
mousex = mousex * pixel_mapping;
mousey = mousey * pixel_mapping;
main.cpp near line 566
//SES flush using pixel dimensions
RenderGLFlush(g_camera.m_width_px, g_camera.m_height_px);
See: http://www.glfw.org/faq.html section 4.3
Problem:
Testbed starts with a window that is twice as large in width and height as the viewport and the mouse pointer does not correspond with locations within the viewport. Also the control panel is positioned toward the center rather than edge of the window.
Solution:
The retina display does not have a 1:1 mapping between window size and pixels. Rather than initializing the viewport with the window size as returned by glfwGetWindowSize use the pixel count as returned by glfwGetFrameBufferSize. Also to get the mouse to work properly with the control panel you have to make a few other changes.
Modify Code as follows:
All changes are in Testbed Framework files DebugDraw.h and main.cpp
DebugDraw.h near line 32
//SES Add m_width_px and m_height_px to hold screen size in pixels
struct Camera
{
Camera()
{
m_center.Set(0.0f, 20.0f);
m_extent = 25.0f;
m_zoom = 1.0f;
m_width = 1280;
m_height = 800;
m_width_px = 1280;
m_height_px = 800;
}
main.cpp near 344
//SES Use window pixel dimensions
bool over = imguiBeginScrollArea("Testbed Controls", g_camera.m_width_px - menuWidth - 10, 10, menuWidth, g_camera.m_height_px - 20, &ui.scrollarea1);
main.cpp near line 414
//SES Use window pixel dimensions
bool over = imguiBeginScrollArea("Choose Sample", g_camera.m_width_px - menuWidth - testMenuWidth - 20, 10, testMenuWidth, g_camera.m_height_px - 20, &testScroll);
main.cpp near 443
//SES Initialize Camera members
g_camera.m_width = g_camera.m_width_px = 1024;
g_camera.m_height = g_camera.m_height_px = 640;
main.cpp near line 520
//SES Set viewport using window size in pixels and as a side effect save the pixel dimensions
// in the Camera structure.
glfwGetFramebufferSize(mainWindow, &g_camera.m_width_px, &g_camera.m_height_px);
glViewport(0, 0, g_camera.m_width_px, g_camera.m_height_px);
main.cpp near line 547
//SES Calculate the mapping factor between screen coordinates and pixels
int pixel_mapping = int(floor((g_camera.m_height_px/g_camera.m_height)+0.5f));
mousex = mousex * pixel_mapping;
mousey = mousey * pixel_mapping;
main.cpp near line 566
//SES flush using pixel dimensions
RenderGLFlush(g_camera.m_width_px, g_camera.m_height_px);