Hi
Somebody can help me? I don´t understand way is vertically flipping the image , I find the problem is createGrapics, if comment pg.begindraw() and pg.endDraw(), no flip, but I need use it.
Thanks!!!!
- // Off-screen rendering example using GLGraphics.
- // By Andres Colubri. Multisampling support in GLGraphicsOffScreen
- // implemented by Ilias Bergstrom (http://www.onar3d.com/)
- //
- // Drag the mouse accross the horizontal direction to change
- // the mixing of the two off-screen textures.
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- GLGraphicsOffScreen glg1, glg2;
- int mixFactor = 127;
- // This will contain the pixels used to calculate the fire effect
- int[][] fire;
- // Flame colors
- color[] palette;
- float angle;
- int[] calc1,calc2,calc3,calc4,calc5;
- PGraphics pg;
- void setup() {
- size(640, 480, GLConstants.GLGRAPHICS);
- // Creating an off-screen drawing surfaces. The first one has
- // 4x multi-sampling enabled.
- glg1 = new GLGraphicsOffScreen(this, 320, 240, true, 4);
- glg2 = new GLGraphicsOffScreen(this, 640, 360, true, 4);
- // Disabling stroke lines in the first off-screen surface.
- glg1.beginDraw();
- glg1.noStroke();
- glg1.endDraw();
- //CUBE SETUP
- pg = createGraphics(640, 360, P3D);
- calc1 = new int[width];
- calc3 = new int[width];
- calc4 = new int[width];
- calc2 = new int[height];
- calc5 = new int[height];
- colorMode(HSB);
- fire = new int[width][height];
- palette = new color[255];
- // Generate the palette
- for(int x = 0; x < palette.length; x++) {
- //Hue goes from 0 to 85: red to yellow
- //Saturation is always the maximum: 255
- //Lightness is 0..255 for x=0..128, and 255 for x=128..255
- palette[x] = color(x/3, 255, constrain(x*3, 0, 255));
- }
- // Precalculate which pixel values to add during animation loop
- // this speeds up the effect by 10fps
- for (int x = 0; x < width; x++) {
- calc1[x] = x % width;
- calc3[x] = (x - 1 + width) % width;
- calc4[x] = (x + 1) % width;
- }
- for(int y = 0; y < height; y++) {
- calc2[y] = (y + 1) % height;
- calc5[y] = (y + 2) % height;
- }
- }
- void draw() {
- background(0);
- // In the off-screen surface 1, we draw random ellipses.
- glg1.beginDraw();
- glg1.fill(230, 50, 20, random(50, 200));
- glg1.ellipse(random(0, glg1.width), random(0, glg1.height), random(10, 50), random(10, 50));
- glg1.endDraw();
- // In the off-screen surface 2, we draw random rectangles.
- glg2.beginDraw();
- angle = angle + 0.05;
- // Rotating wireframe cube
- pg.beginDraw();
- pg.translate(width >> 1, height >> 1);
- pg.rotateX(sin(angle/2));
- pg.rotateY(cos(angle/2));
- pg.background(0);
- pg.stroke(128);
- pg.scale(25);
- pg.noFill();
- pg.box(4);
- pg.endDraw();
- // Randomize the bottom row of the fire buffer
- for(int x = 0; x < width; x++)
- {
- fire[x][height-1] = int(random(0,190)) ;
- }
- glg2.loadPixels();
- int counter = 0;
- // Do the fire calculations for every pixel, from top to bottom
- for (int y = 0; y < 360; y++) {
- for(int x = 0; x < 640; x++) {
- // Add pixel values around current pixel
- fire[x][y] =
- ((fire[calc3[x]][calc2[y]]
- + fire[calc1[x]][calc2[y]]
- + fire[calc4[x]][calc2[y]]
- + fire[calc1[x]][calc5[y]]) << 5) / 129;
- // Output everything to screen using our palette colors
- glg2.pixels[counter] = palette[fire[x][y]];
- // Extract the red value using right shift and bit mask
- // equivalent of red(pg.pixels[x+y*w])
- if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) {
- // Only map 3D cube 'lit' pixels onto fire array needed for next frame
- fire[x][y] = 128;
- }
- }
- }
- glg2.updatePixels();
- glg2.endDraw();
- // We mix the images together and scale them so the occupy the entire screen.
- tint(255, 255 - mixFactor);
- image(glg1.getTexture(), 10, 10, width - 20, height - 20);
- tint(255, mixFactor);
- image(glg2.getTexture(), 10, 10, width - 20, height - 20);
- // Image border for reference.
- noFill();
- stroke(255);
- rect(10, 10, width - 20, height - 20);
- fill(0); // 1.0.2/1.0.3 need this, because noFill() affects the tint used in image().
- }
- void mouseDragged() {
- mixFactor = int(255 * float(mouseX) / width);
- }
1