Calling all you openGL gurus.. I'm trying to figure out how to copy the contents of the processing window into a GLTexture.
The reason I want to do this is to work around the issues regarding
GLGraphicOffScreen and partially transparent pixels, but now I'm hoping it can be a good experience to learn a little more about openGL too. I've tried a bunch of different things but have either had no luck, or have run into strange error messages that lead me to dead-end google searching..
Here's my simple sketch which exhibits the problem, but I don't know why it's not working.
- import codeanticode.glgraphics.*;
- import javax.media.opengl.*;
- import processing.opengl.*;
- GLTexture tex;
- PGraphicsOpenGL pgl;
- void setup() {
- size(800, 600, OPENGL);
- tex = new GLTexture(this, 512, 512);
- tex.init(512,512);
- PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
- }
- void draw() {
- background(255);
- fill(0);
- ellipse(mouseX, mouseY, 30, 30);
- GL gl = pgl.beginGL();
- gl.glBindTexture(gl.GL_TEXTURE_2D, tex.getTextureID());
- gl.glCopyTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);
- pgl.endGL();
- // The image appears to be blank (transparent) instead of a copy of the main screen.
- image(tex, 0, 0, 128, 128);
- }
So, lines 23 - 28 are the important ones. I bind the texture, and then copy a 512x512 region into it.. Seems simple but the "tex" instance of GLTexture always seems to be blank (transparent) instead of containing a copy of what was just drawn..
Any help would be greatly appreciated, I've searched all over the forums and internet and am out of ideas..
-Ben
1