Skip to content

Commit b01a1aa

Browse files
committed
handle upwards y axis
1 parent a0fcdb0 commit b01a1aa

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ protected Texture wrapBackTexture(Texture texture) {
544544
glColorTex.get(backTex), TEXTURE_2D, RGBA,
545545
fboWidth, fboHeight, NEAREST, NEAREST,
546546
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
547-
texture.invertedY(true);
547+
texture.invertedY(PGraphicsOpenGL.Y_AXIS_DOWN);
548548
texture.colorBuffer(true);
549549
graphics.setCache(graphics, texture);
550550
} else {
@@ -561,7 +561,7 @@ protected Texture wrapFrontTexture(Texture texture) {
561561
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
562562
fboWidth, fboHeight, NEAREST, NEAREST,
563563
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
564-
texture.invertedY(true);
564+
texture.invertedY(PGraphicsOpenGL.Y_AXIS_DOWN);
565565
texture.colorBuffer(true);
566566
} else {
567567
texture.glName = glColorTex.get(frontTex);

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public void dispose() {
105105
/** Current flush mode. */
106106
protected int flushMode = FLUSH_WHEN_FULL;
107107

108+
/** Orientation of Y axis. */
109+
static protected boolean Y_AXIS_DOWN = true;
110+
108111
// ........................................................
109112

110113
// VBOs for immediate rendering:
@@ -3577,10 +3580,14 @@ protected void textCharImpl(char ch, float x, float y) {
35773580
float lextent = glyph.leftExtent / (float) textFont.getSize();
35783581
float textent = glyph.topExtent / (float) textFont.getSize();
35793582

3583+
// The default text setting assumes an Y axis pointing down, so
3584+
// inverting in the the case Y points up
3585+
int sign = Y_AXIS_DOWN ? +1 : -1;
3586+
35803587
float x1 = x + lextent * textSize;
3581-
float y1 = y - textent * textSize;
3588+
float y1 = y - sign * textent * textSize;
35823589
float x2 = x1 + bwidth * textSize;
3583-
float y2 = y1 + high * textSize;
3590+
float y2 = y1 + sign * high * textSize;
35843591

35853592
textCharModelImpl(tinfo, x1, y1, x2, y2);
35863593
} else if (textMode == SHAPE) {
@@ -5875,7 +5882,7 @@ protected void loadTextureImpl(int sampling, boolean mipmap) {
58755882
Texture.Parameters params = new Texture.Parameters(ARGB,
58765883
sampling, mipmap);
58775884
texture = new Texture(this, pixelWidth, pixelHeight, params);
5878-
texture.invertedY(true);
5885+
texture.invertedY(Y_AXIS_DOWN);
58795886
texture.colorBuffer(true);
58805887
setCache(this, texture);
58815888
}
@@ -5886,7 +5893,7 @@ protected void createPTexture() {
58865893
updatePixelSize();
58875894
if (texture != null) {
58885895
ptexture = new Texture(this, pixelWidth, pixelHeight, texture.getParameters());
5889-
ptexture.invertedY(true);
5896+
ptexture.invertedY(Y_AXIS_DOWN);
58905897
ptexture.colorBuffer(true);
58915898
}
58925899
}
@@ -6026,7 +6033,7 @@ public void filter(PShader shader) {
60266033
if (filterTexture == null || filterTexture.contextIsOutdated()) {
60276034
filterTexture = new Texture(this, texture.width, texture.height,
60286035
texture.getParameters());
6029-
filterTexture.invertedY(true);
6036+
filterTexture.invertedY(Y_AXIS_DOWN);
60306037
filterImage = wrapTexture(filterTexture);
60316038
}
60326039
filterTexture.set(texture);
@@ -6096,7 +6103,7 @@ public void copy(int sx, int sy, int sw, int sh,
60966103
loadTexture();
60976104
if (filterTexture == null || filterTexture.contextIsOutdated()) {
60986105
filterTexture = new Texture(this, texture.width, texture.height, texture.getParameters());
6099-
filterTexture.invertedY(true);
6106+
filterTexture.invertedY(Y_AXIS_DOWN);
61006107
filterImage = wrapTexture(filterTexture);
61016108
}
61026109
filterTexture.put(texture, sx, height - (sy + sh), sw, height - sy);
@@ -6416,6 +6423,7 @@ protected Texture addTexture(PImage img, Texture.Parameters params) {
64166423
img.parent = parent;
64176424
}
64186425
Texture tex = new Texture(this, img.pixelWidth, img.pixelHeight, params);
6426+
tex.invertedY(!Y_AXIS_DOWN); // Pixels are read upside down
64196427
setCache(img, tex);
64206428
return tex;
64216429
}

libraries/vr/src/processing/vr/PGraphicsVR.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public class PGraphicsVR extends PGraphics3D {
5252
private float[] eyePerspective;
5353
private PMatrix3D eyeMatrix;
5454

55+
static {
56+
Y_AXIS_DOWN = false;
57+
}
58+
5559
@Override
5660
protected PGL createPGL(PGraphicsOpenGL pg) {
5761
return new PGLES(pg);

0 commit comments

Comments
 (0)