Skip to content

Commit ad5666a

Browse files
author
Ryan Gordon
committed
Patch for viewer scaling in retina displays, contributed by @pookiefoof
1 parent 72c991e commit ad5666a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

examples/viewer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,25 @@ bool Viewer::render()
152152
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
153153

154154
GLint x = 0, y = 0;
155+
int fb_width, fb_width_half, fb_height, fb_height_half;
155156

156157
std::map<std::string, libfreenect2::Frame*>::iterator iter;
157158

158159
for (iter = frames.begin(); iter != frames.end(); ++iter)
159160
{
160161
libfreenect2::Frame* frame = iter->second;
161162

162-
glViewport(x, y, win_width, win_height);
163-
x += win_width;
164-
if (x >= (win_width * 2))
163+
// Using the frame buffer size to account for screens where window.size != framebuffer.size, e.g. retina displays
164+
glfwGetFramebufferSize(window, &fb_width, &fb_height);
165+
fb_width_half = (fb_width + 1) / 2;
166+
fb_height_half = (fb_height + 1) / 2;
167+
168+
glViewport(x, y, fb_width_half, fb_height_half);
169+
x += fb_width_half;
170+
if (x >= fb_width)
165171
{
166172
x = 0;
167-
y += win_height;
173+
y += fb_height_half;
168174
}
169175

170176
float w = static_cast<float>(frame->width);

0 commit comments

Comments
 (0)