You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created this example from combining the OffscreenTest and LowLevelGL examples, but I've encountered this behavior in a lot of my own code as well.
This appears in the latest version (2.0.3) , running on Windows 7 32bit.
Pressing the spacebar toggles between drawing directly, and first drawing into PGraphics and then displaying that.
The two should be identical but are not!
In the method drawDirectly, the output is as expected for all alpha values.
In drawImage, alpha == 1.0f looks fine, but set this to 0.5f, and drawing is almost invisible!
// Keys:
// 'a': toggles between alpha == 0.5f and alpha == 1.0f.
// spacebar: toggles between rendering directly, and into a PGraphics buffer.
// BUG DESCRIPTION:
// In drawDirectly, the appearance is as expected for all alpha values.
// In drawImage, alpha == 1.0f looks fine, but set this to 0.5f, and drawing is almost invisible!
The reason is that the offscreen surface is not opaque, and when it is blended onto the main surface, it looks fainter than one would expect by simply replacing the colors. So, if you do:
Hi!
I created this example from combining the OffscreenTest and LowLevelGL examples, but I've encountered this behavior in a lot of my own code as well.
This appears in the latest version (2.0.3) , running on Windows 7 32bit.
Pressing the spacebar toggles between drawing directly, and first drawing into PGraphics and then displaying that.
The two should be identical but are not!
In the method drawDirectly, the output is as expected for all alpha values.
In drawImage, alpha == 1.0f looks fine, but set this to 0.5f, and drawing is almost invisible!
Sketch code to reproduce:
import java.nio.*;
PGL pgl;
PGraphics pg;
PShader flatShader;
int vertLoc, colorLoc;
float[] vertices, colors;
FloatBuffer vertData, colorData;
boolean drawPGraphicsImage = true;
float alpha = 0.5f;
// Keys:
// 'a': toggles between alpha == 0.5f and alpha == 1.0f.
// spacebar: toggles between rendering directly, and into a PGraphics buffer.
// BUG DESCRIPTION:
// In drawDirectly, the appearance is as expected for all alpha values.
// In drawImage, alpha == 1.0f looks fine, but set this to 0.5f, and drawing is almost invisible!
void setup() {
size(800, 800, OPENGL);
pg = createGraphics(800, 800, OPENGL);
flatShader = loadShader("frag.glsl", "vert.glsl");
vertices = new float[12];
vertData = allocateDirectFloatBuffer(12);
colors = new float[12];
colorData = allocateDirectFloatBuffer(12);
}
void draw() {
updateGeometry();
background(0);
if(drawPGraphicsImage)
drawImage();
else
drawDirectly();
}
void keyPressed() {
if (key == ' ') {
drawPGraphicsImage = !drawPGraphicsImage;
}
else if (key == 'a') {
if(alpha == 0.5f)
alpha = 1.0f;
else
alpha = 0.5f;
}
}
// This works as expected
void drawDirectly() {
pgl = beginPGL();
flatShader.bind();
vertLoc = pgl.getAttribLocation(flatShader.glProgram, "vertex");
colorLoc = pgl.getAttribLocation(flatShader.glProgram, "color");
pgl.enableVertexAttribArray(vertLoc);
pgl.enableVertexAttribArray(colorLoc);
pgl.vertexAttribPointer(vertLoc, 4, PGL.FLOAT, false, 0, vertData);
pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData);
pgl.drawArrays(PGL.TRIANGLES, 0, 3);
pgl.disableVertexAttribArray(vertLoc);
pgl.disableVertexAttribArray(colorLoc);
flatShader.unbind();
endPGL();
}
// This is most likey a bug!
void drawImage() {
pg.beginDraw();
pg.clear();
pgl = pg.beginPGL();
flatShader.bind();
vertLoc = pgl.getAttribLocation(flatShader.glProgram, "vertex");
colorLoc = pgl.getAttribLocation(flatShader.glProgram, "color");
pgl.enableVertexAttribArray(vertLoc);
pgl.enableVertexAttribArray(colorLoc);
pgl.vertexAttribPointer(vertLoc, 4, PGL.FLOAT, false, 0, vertData);
pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData);
pgl.drawArrays(PGL.TRIANGLES, 0, 3);
pgl.disableVertexAttribArray(vertLoc);
pgl.disableVertexAttribArray(colorLoc);
flatShader.unbind();
pg.endPGL();
pg.endDraw();
image(pg, 0, 0, 800, 800);
}
void updateGeometry() {
// Vertex 1
vertices[0] = 0;
vertices[1] = 0;
vertices[2] = 0;
vertices[3] = 1;
colors[0] = 1;
colors[1] = 0;
colors[2] = 0;
colors[3] = alpha;
// Corner 2
vertices[4] = width/2;
vertices[5] = height;
vertices[6] = 0;
vertices[7] = 1;
colors[4] = 0;
colors[5] = 1;
colors[6] = 0;
colors[7] = alpha;
// Corner 3
vertices[8] = width;
vertices[9] = 0;
vertices[10] = 0;
vertices[11] = 1;
colors[8] = 0;
colors[9] = 0;
colors[10] = 1;
colors[11] = alpha;
vertData.rewind();
vertData.put(vertices);
vertData.position(0);
colorData.rewind();
colorData.put(colors);
colorData.position(0);
}
FloatBuffer allocateDirectFloatBuffer(int n) {
return ByteBuffer.allocateDirect(n * Float.SIZE/8).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
The text was updated successfully, but these errors were encountered: