How can I get around this difference in behavior / bug in GLGraphics GLTexture, which appears between v0.95 and v0.99-1.0?
in
Contributed Library Questions
•
1 year ago
Hi!
I found a difference in behavior in GLGraphics 1.0 which seems to be undesired / a bug:
Up until version 0.95, one could render to a texture, manipulate it, and then bind the resulting texture using the related OpenGL commands, see example in code, lines 129-146.
In versions 0.99 & 1.0 the lines 129-146 no longer work, but as you can see if you comment lines 129-146 and un-comment 127, it is still possible to successfully display the created texture, if it is accessed using the image method.
Am I doing something wrong, have I missed some change in the library?
Thank you very much, and I hope I haven't missed something glaringly obvious! :)
(I tried replacing the destTex texture source in these lines with just the before immediately created "glg1.getTexture()" but that just gave me the same behavior).
The below demo is loosely based on (an old version of) the GLGraphics "BloomEffect" example, and so uses the same files:
I found a difference in behavior in GLGraphics 1.0 which seems to be undesired / a bug:
Up until version 0.95, one could render to a texture, manipulate it, and then bind the resulting texture using the related OpenGL commands, see example in code, lines 129-146.
In versions 0.99 & 1.0 the lines 129-146 no longer work, but as you can see if you comment lines 129-146 and un-comment 127, it is still possible to successfully display the created texture, if it is accessed using the image method.
Am I doing something wrong, have I missed some change in the library?
Thank you very much, and I hope I haven't missed something glaringly obvious! :)
(I tried replacing the destTex texture source in these lines with just the before immediately created "glg1.getTexture()" but that just gave me the same behavior).
The below demo is loosely based on (an old version of) the GLGraphics "BloomEffect" example, and so uses the same files:
- import processing.opengl.*;
import java.io.File;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import codeanticode.glgraphics.*;
int squareList;
PGraphicsOpenGL pgl;
GL gl;
GLU glu;
GLGraphicsOffScreen glg1;
GLTexture tex0, tex2, tex4, tex8, tex16, bloomMask, destTex;
GLTextureFilter extractBloom, blur, blend4, toneMap;
Texture pic1;
int tex_w, tex_h;
void setup()
{
size(640, 480, GLConstants.GLGRAPHICS);
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
glu = ((PGraphicsOpenGL) g).glu;
try
{
pic1 = TextureIO.newTexture(new File(dataPath("lights.jpg")), true);
}
catch (Exception e)
{
println(e);
}
glg1 = new GLGraphicsOffScreen(this, width, height, true);
glg1.beginGL();
squareList = glg1.gl.glGenLists(1);
glg1.gl.glNewList(squareList, GL.GL_COMPILE);
glg1.gl.glBegin(GL.GL_POLYGON);
glg1.gl.glTexCoord2f(0, 0);
glg1.gl.glVertex2f(-.5f, -.5f);
glg1.gl.glTexCoord2f(1, 0);
glg1.gl.glVertex2f(.5f, -.5f);
glg1.gl.glTexCoord2f(1, 1);
glg1.gl.glVertex2f(.5f, .5f);
glg1.gl.glTexCoord2f(0, 1);
glg1.gl.glVertex2f(-.5f, .5f);
glg1.gl.glEnd();
glg1.gl.glEndList();
glg1.endGL();
tex_w = width;
tex_h = height;
// Loading required filters.
extractBloom = new GLTextureFilter(this, dataPath("ExtractBloom.xml"));
blur = new GLTextureFilter(this, dataPath("Blur.xml"));
blend4 = new GLTextureFilter(this, dataPath("Blend4.xml"));
toneMap = new GLTextureFilter(this, dataPath("ToneMap.xml"));
destTex = new GLTexture(this, tex_w, tex_h);
// Initializing bloom mask and blur textures.
bloomMask = new GLTexture(this, tex_w, tex_h, GLTexture.FLOAT);
tex0 = new GLTexture(this, tex_w, tex_h, GLTexture.FLOAT);
tex2 = new GLTexture(this, tex_w / 2, tex_h / 2, GLTexture.FLOAT);
tex4 = new GLTexture(this, tex_w / 4, tex_h / 4, GLTexture.FLOAT);
tex8 = new GLTexture(this, tex_w / 8, tex_h / 8, GLTexture.FLOAT);
tex16 = new GLTexture(this, tex_w / 16, tex_h / 16, GLTexture.FLOAT);
}
void draw()
{
background(0);
glg1.beginDraw();
glg1.pushMatrix();
glg1.translate(0.5f * width, 0.5f * height, -100);
glg1.rotateY(map(295 * 4, 0, width, 0, PI));
glg1.translate(-height / 2, -height / 2);
glg1.colorMode(RGB);
glg1.gl.glEnable(GL.GL_TEXTURE_2D);
glg1.scale(height, height, height);
pic1.bind();
pic1.enable();
glg1.beginGL();
glg1.gl.glCallList(squareList);
glg1.endGL();
pic1.disable();
glg1.popMatrix();
glg1.endDraw();
// -----------------------
float fx = (float) (mouseX) / width;
float fy = (float) (mouseY) / height;
// Extracting the bright regions from input texture.
extractBloom.setParameterValue("bright_threshold", fx);
extractBloom.apply(glg1.getTexture(), tex0);
// Downsampling with blur.
tex0.filter(blur, tex2);
tex2.filter(blur, tex4);
tex4.filter(blur, tex8);
tex8.filter(blur, tex16);
// Blending downsampled textures.
blend4.apply(new GLTexture[] { tex2, tex4, tex8, tex16 }, new GLTexture[] { bloomMask } );
// Final tone mapping into destination texture.
toneMap.setParameterValue("exposure", fy);
toneMap.setParameterValue("bright", fx);
toneMap.apply(new GLTexture[] { glg1.getTexture(), bloomMask }, new GLTexture[] { destTex } );
//image(destTex, 0, 0, width, height);
translate(width/2, height/2, 0);
pgl.beginGL();
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(destTex.getTextureTarget(), destTex.getTextureID());
gl.glEnable(destTex.getTextureTarget());
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glPushMatrix();
gl.glScalef(glg1.width, glg1.height, 1.0f);
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glCallList(squareList);
gl.glPopMatrix();
gl.glDisable(destTex.getTextureTarget());
pgl.endGL();
}
1