diff --git a/core/todo.txt b/core/todo.txt index ce9f4c57b..e31dff6cc 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,4 +1,11 @@ 0127 core +X pixel operations are broken in opengl +X get(), set(), copy(), blend(), loadPixels, updatePixels() +X set(x, y, image) y reversed in openGL +X background(image) also broken +X also textMode(SCREEN) +X http://dev.processing.org/bugs/show_bug.cgi?id=91 + _ PGraphics problem with fillColor _ http://dev.processing.org/bugs/show_bug.cgi?id=468 @@ -775,12 +782,6 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=127 PGraphicsOpenGL -_ pixel operations are broken in opengl -_ get(), set(), copy(), blend(), loadPixels, updatePixels() -_ set(x, y, image) y reversed in openGL -_ background(image) also broken -_ http://dev.processing.org/bugs/show_bug.cgi?id=91 -_ also textMode(SCREEN) _ in opengl mode, use its tesselator _ because the vertex calls can just come right back to regular vertex calls _ this way we can also implement breakShape() for opengl diff --git a/opengl/src/processing/opengl/PGraphicsOpenGL.java b/opengl/src/processing/opengl/PGraphicsOpenGL.java index 136dc5938..d162531e3 100644 --- a/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -2238,14 +2238,7 @@ public class PGraphicsOpenGL extends PGraphics3D { // and convert ARGB back to opengl RGBA components (big endian) for (int x = 0; x < width; x++) { int temp = pixels[index]; - /* - pixels[index] = - ((pixels[yindex] >> 24) & 0xff) | - ((pixels[yindex] << 8) & 0xffffff00); - pixels[yindex] = - ((temp >> 24) & 0xff) | - ((temp << 8) & 0xffffff00); - */ + pixels[index] = ((pixels[yindex] << 8) & 0xffffff00) | 0xff; pixels[yindex] = ((temp << 8) & 0xffffff00) | 0xff; @@ -2281,18 +2274,7 @@ public class PGraphicsOpenGL extends PGraphics3D { //((pixels[i] << 8) & 0xffffff00); //} - //System.out.println("running glDrawPixels"); - //gl.glRasterPos2i(width/2, height/2); - //gl.glRasterPos2i(width/2, 1); //height/3); - //gl.glRasterPos2i(1, height - 1); //1, 1); - - // for some reason, glRasterPos(0, height) won't draw anything. - // my guess is that it's getting "clipped", so adding an epsilon - // makes it work. also, height-1 would be the logical start, - // but apparently that's not how opengl coordinates work - //gl.glRasterPos2f(0.0001f, height - 0.0001f); - gl.glRasterPos2f(EPSILON, height - EPSILON); - //gl.glRasterPos2f(width/2, height/2); + setRasterPos(0, 0); // lower-left corner pixelBuffer.put(pixels); pixelBuffer.rewind(); @@ -2374,7 +2356,8 @@ public class PGraphicsOpenGL extends PGraphics3D { } getsetBuffer.put(0, getset); getsetBuffer.rewind(); - gl.glRasterPos2f(x + EPSILON, y + EPSILON); + //gl.glRasterPos2f(x + EPSILON, y + EPSILON); + setRasterPos(x, (height-y) - 1); gl.glDrawPixels(1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, getsetBuffer); } @@ -2389,30 +2372,65 @@ public class PGraphicsOpenGL extends PGraphics3D { * vertically. Both have their components all swapped to native. */ public void set(int x, int y, PImage source) { - /* - ImageCache cash = (ImageCache) source.cache; - if (cash == null) { - // this will flip the bits and make it a power of 2 - cache(source); - cash = (ImageCache) source.cache; - } - // now draw to the screen but set the scanline length - */ int backup[] = new int[source.pixels.length]; System.arraycopy(source.pixels, 0, backup, 0, source.pixels.length); javaToNativeARGB(source); + // TODO is this possible without intbuffer? IntBuffer setBuffer = BufferUtil.newIntBuffer(source.pixels.length); setBuffer.put(source.pixels); setBuffer.rewind(); - gl.glRasterPos2f(x + EPSILON, (height - y) - EPSILON); + + setRasterPos(x, (height-y) - source.height); //+source.height); gl.glDrawPixels(source.width, source.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, setBuffer); - //nativeToJavaARGB(source); + source.pixels = backup; } + /** + * Definitive method for setting raster pos, including offscreen locations. + * The raster position is tricky because it's affected by the modelview and + * projection matrices. Further, offscreen coords won't properly set the + * raster position. This code gets around both issues. + * http://www.mesa3d.org/brianp/sig97/gotchas.htm + * @param y the Y-coordinate, which is flipped upside down in OpenGL + */ + protected void setRasterPos(float x, float y) { + float z = 0; + float w = 1; + + float fx, fy; + + // Push current matrix mode and viewport attributes + gl.glPushAttrib(GL.GL_TRANSFORM_BIT | GL.GL_VIEWPORT_BIT); + + // Setup projection parameters + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glPushMatrix(); + gl.glLoadIdentity(); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glPushMatrix(); + gl.glLoadIdentity(); + + gl.glDepthRange(z, z); + gl.glViewport((int) x - 1, (int) y - 1, 2, 2); + + // set the raster (window) position + fx = x - (int) x; + fy = y - (int) y; + gl.glRasterPos4f(fx, fy, 0, w); + + // restore matrices, viewport and matrix mode + gl.glPopMatrix(); + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glPopMatrix(); + + gl.glPopAttrib(); + } + + ////////////////////////////////////////////////////////////// diff --git a/todo.txt b/todo.txt index 369674642..f54307a84 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,9 @@ 0127 pde +_ mark examples as untitled (rather than read-only) + + documentation _ added getChild(name/path), getChildren(name/path) to xml library _ add notes about these to the reference