Skip to content

Commit b20e667

Browse files
committed
set viewport in PGL.drawTexture(), fixes #1869
1 parent 2b7eef7 commit b20e667

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

core/src/processing/opengl/PGL.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public class PGL {
407407

408408
protected ByteBuffer byteBuffer;
409409
protected IntBuffer intBuffer;
410+
protected IntBuffer viewBuffer;
410411

411412
protected IntBuffer colorBuffer;
412413
protected FloatBuffer depthBuffer;
@@ -465,6 +466,7 @@ public PGL(PGraphicsOpenGL pg) {
465466

466467
byteBuffer = allocateByteBuffer(1);
467468
intBuffer = allocateIntBuffer(1);
469+
viewBuffer = allocateIntBuffer(4);
468470
}
469471

470472

@@ -1448,7 +1450,7 @@ protected void initTexture(int target, int format, int width, int height) {
14481450

14491451

14501452
protected void initTexture(int target, int format, int width, int height,
1451-
int initColor) {
1453+
int initColor) {
14521454
int[] glcolor = new int[16 * 16];
14531455
Arrays.fill(glcolor, javaToNativeARGB(initColor));
14541456
IntBuffer texels = PGL.allocateDirectIntBuffer(16 * 16);
@@ -1544,6 +1546,11 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
15441546
boolean depthMask = getDepthWriteMask();
15451547
depthMask(false);
15461548

1549+
// Making sure that the viewport matches the provided screen dimensions
1550+
viewBuffer.rewind();
1551+
getIntegerv(VIEWPORT, viewBuffer);
1552+
viewport(0, 0, scrW, scrH);
1553+
15471554
useProgram(tex2DShaderProgram);
15481555

15491556
enableVertexAttribArray(tex2DVertLoc);
@@ -1610,6 +1617,9 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
16101617
disable(DEPTH_TEST);
16111618
}
16121619
depthMask(depthMask);
1620+
1621+
viewport(viewBuffer.get(0), viewBuffer.get(1),
1622+
viewBuffer.get(2),viewBuffer.get(3));
16131623
}
16141624
}
16151625

@@ -1649,6 +1659,11 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
16491659
boolean depthMask = getDepthWriteMask();
16501660
depthMask(false);
16511661

1662+
// Making sure that the viewport matches the provided screen dimensions
1663+
viewBuffer.rewind();
1664+
getIntegerv(VIEWPORT, viewBuffer);
1665+
viewport(0, 0, scrW, scrH);
1666+
16521667
useProgram(texRectShaderProgram);
16531668

16541669
enableVertexAttribArray(texRectVertLoc);
@@ -1715,6 +1730,9 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
17151730
disable(DEPTH_TEST);
17161731
}
17171732
depthMask(depthMask);
1733+
1734+
viewport(viewBuffer.get(0), viewBuffer.get(1),
1735+
viewBuffer.get(2),viewBuffer.get(3));
17181736
}
17191737
}
17201738

@@ -2124,12 +2142,14 @@ protected boolean hasShaders() {
21242142

21252143

21262144
protected int maxSamples() {
2145+
intBuffer.rewind();
21272146
getIntegerv(MAX_SAMPLES, intBuffer);
21282147
return intBuffer.get(0);
21292148
}
21302149

21312150

21322151
protected int getMaxTexUnits() {
2152+
intBuffer.rewind();
21332153
getIntegerv(MAX_TEXTURE_IMAGE_UNITS, intBuffer);
21342154
return intBuffer.get(0);
21352155
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,10 +3372,8 @@ protected void textCharModelImpl(FontTexture.TextureInfo info,
33723372
if (textTex.currentTex != info.texIndex) {
33733373
textTex.setTexture(info.texIndex);
33743374
}
3375-
PImage tex = textTex.getCurrentTexture();
3376-
33773375
beginShape(QUADS);
3378-
texture(tex);
3376+
texture(textTex.getCurrentTexture());
33793377
vertex(x0, y0, info.u0, info.v0);
33803378
vertex(x1, y0, info.u1, info.v0);
33813379
vertex(x1, y1, info.u1, info.v1);

core/src/processing/opengl/Texture.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,8 @@ protected void copyTexture(Texture tex, int x, int y, int w, int h,
12351235
// FBO copy:
12361236
PGraphicsOpenGL.pushFramebuffer();
12371237
PGraphicsOpenGL.setFramebuffer(tempFbo);
1238-
// Clear the color buffer to make sure that the alpha of the
1238+
// Clear the color buffer to make sure that the alpha channel is set to
1239+
// full transparency
12391240
pgl.clearColor(0, 0, 0, 0);
12401241
pgl.clear(PGL.COLOR_BUFFER_BIT);
12411242
if (scale) {
@@ -1254,6 +1255,7 @@ protected void copyTexture(Texture tex, int x, int y, int w, int h,
12541255
x, y, w, h, x, y, w, h);
12551256
}
12561257
PGraphicsOpenGL.popFramebuffer();
1258+
12571259
updateTexels(x, y, w, h);
12581260
}
12591261

0 commit comments

Comments
 (0)