Skip to content

Commit 8456fcc

Browse files
committed
Merge pull request ClearVolume#3 from ClearVolume/RetinaTextRendering
Proper detection of rendering on Retina displays
2 parents 2573922 + 4106c94 commit 8456fcc

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/java/cleargl/ClearGLWindow.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.jogamp.newt.event.MouseListener;
1414
import com.jogamp.newt.event.WindowAdapter;
1515
import com.jogamp.newt.opengl.GLWindow;
16+
import com.jogamp.opengl.GL;
1617
import com.jogamp.opengl.DefaultGLCapabilitiesChooser;
1718
import com.jogamp.opengl.GLAutoDrawable;
1819
import com.jogamp.opengl.GLCapabilities;
@@ -276,12 +277,12 @@ public void setOrthoProjectionMatrix( final float left,
276277
final float zFar)
277278
{
278279
if (mProjectionMatrix != null)
279-
mProjectionMatrix.setOrthoProjectionMatrix( left,
280-
right,
281-
bottom,
282-
top,
283-
zNear,
284-
zFar);
280+
mProjectionMatrix.setOrthoProjectionMatrix(left,
281+
right,
282+
bottom,
283+
top,
284+
zNear,
285+
zFar);
285286
}
286287

287288
/* (non-Javadoc)
@@ -385,6 +386,21 @@ public void display()
385386
mGlWindow.display();
386387
}
387388

389+
public static boolean isRetina(GL pGL) {
390+
int[] trialSizes = new int[2];
391+
392+
trialSizes[0] = 512;
393+
trialSizes[1] = 512;
394+
395+
pGL.getContext().getGLDrawable().getNativeSurface().convertToPixelUnits(trialSizes);
396+
397+
if(trialSizes[0] == 512 && trialSizes[1] == 512) {
398+
return false;
399+
} else {
400+
return true;
401+
}
402+
}
403+
388404
/* (non-Javadoc)
389405
* @see cleargl.ClearGLDisplayable#setDefaultCloseOperation(javax.media.nativewindow.WindowClosingProtocol.WindowClosingMode)
390406
*/

src/java/cleargl/ClearTextRenderer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ public void drawTextAtPosition( String text,
7878
font = new JLabel().getFont();
7979
}
8080

81+
final int scaleFactor = ClearGLWindow.isRetina(mGL) ? 2 : 1;
82+
8183
final int windowSizeX = mGL.getContext()
8284
.getGLDrawable()
83-
.getSurfaceWidth() / 2;
85+
.getSurfaceWidth() / scaleFactor;
8486
final int windowSizeY = mGL.getContext()
8587
.getGLDrawable()
86-
.getSurfaceHeight() / 2;
88+
.getSurfaceHeight() / scaleFactor;
8789

8890
final int width = text.length() * font.getSize();
8991
final int height = font.getSize();

0 commit comments

Comments
 (0)