Loading...
Logo
Processing Forum
eduardomoriana's Profile
4 Posts
17 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hello

    why is not working? the box drawed has a strange translation error ...

    1. import codeanticode.glgraphics.*;

    2. import remixlab.proscene.*;

    3. import javax.media.opengl.*;
    4. import processing.opengl.*;

    5. GL gl;

    6. GLGraphicsOffScreen renderer = null;

    7. Scene scene;

    8. public void setup() {

    9.   size(1024, 768, GLGraphics.GLGRAPHICS);
    10.   renderer = new GLGraphicsOffScreen(this, width, height, true, 4);
    11.   // renderer = (GLGraphics) g;
    12.   noStroke();

    13.   frameRate(40);

    14.   scene = new Scene(this, renderer);
    15. }

    16. public void draw() {

    17.   renderer.beginDraw();
    18.   scene.beginDraw();
    19.   renderer.beginGL();

    20.   renderer.background(0);

    21.   renderer.pushMatrix();
    22.   renderer.fill(255);
    23.   renderer.box(50);
    24.   renderer.popMatrix();

    25.   renderer.endGL();
    26.   scene.endDraw();
    27.   renderer.endDraw();
    28.   image(renderer.getTexture(), 0, 0);

    29.   fill(255);
    30.   text(frameRate, 10, 20);
    31. }

    Thanks!!
     
    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!!!!


    1. // Off-screen rendering example using GLGraphics.
    2. // By Andres Colubri. Multisampling support in GLGraphicsOffScreen
    3. // implemented by Ilias Bergstrom (http://www.onar3d.com/) 
    4. //
    5. // Drag the mouse accross the horizontal direction to change
    6. // the mixing of the two off-screen textures.

    7. import processing.opengl.*;
    8. import codeanticode.glgraphics.*;

    9. GLGraphicsOffScreen glg1, glg2;

    10. int mixFactor = 127;


    11. // This will contain the pixels used to calculate the fire effect
    12. int[][] fire;

    13. // Flame colors
    14. color[] palette;
    15. float angle;
    16. int[] calc1,calc2,calc3,calc4,calc5;

    17. PGraphics pg;

    18. void setup() {
    19.   size(640, 480, GLConstants.GLGRAPHICS);
    20.     
    21.   // Creating an off-screen drawing surfaces. The first one has
    22.   // 4x multi-sampling enabled.
    23.   glg1 = new GLGraphicsOffScreen(this, 320, 240, true, 4);
    24.   glg2 = new GLGraphicsOffScreen(this, 640, 360, true, 4);

    25.   // Disabling stroke lines in the first off-screen surface.
    26.   glg1.beginDraw();
    27.   glg1.noStroke();
    28.   glg1.endDraw();
    29.   
    30.   //CUBE SETUP
    31.   pg = createGraphics(640, 360, P3D);

    32.   calc1 = new int[width];
    33.   calc3 = new int[width];
    34.   calc4 = new int[width];
    35.   calc2 = new int[height];
    36.   calc5 = new int[height];

    37.   colorMode(HSB);

    38.   fire = new int[width][height];
    39.   palette = new color[255];

    40.   // Generate the palette
    41.   for(int x = 0; x < palette.length; x++) {
    42.     //Hue goes from 0 to 85: red to yellow
    43.     //Saturation is always the maximum: 255
    44.     //Lightness is 0..255 for x=0..128, and 255 for x=128..255
    45.     palette[x] = color(x/3, 255, constrain(x*3, 0, 255));
    46.   }

    47.   // Precalculate which pixel values to add during animation loop
    48.   // this speeds up the effect by 10fps
    49.   for (int x = 0; x < width; x++) {
    50.     calc1[x] = x % width;
    51.     calc3[x] = (x - 1 + width) % width;
    52.     calc4[x] = (x + 1) % width;
    53.   }
    54.   
    55.   for(int y = 0; y < height; y++) {
    56.     calc2[y] = (y + 1) % height;
    57.     calc5[y] = (y + 2) % height;
    58.   }
    59. }

    60. void draw() {
    61.   background(0);
    62.   
    63.   // In the off-screen surface 1, we draw random ellipses.
    64.   glg1.beginDraw();
    65.   glg1.fill(230, 50, 20, random(50, 200));
    66.   glg1.ellipse(random(0, glg1.width), random(0, glg1.height), random(10, 50), random(10, 50));
    67.   glg1.endDraw();   

    68.   // In the off-screen surface 2, we draw random rectangles.  
    69.   glg2.beginDraw();
    70.   angle = angle + 0.05;

    71.   // Rotating wireframe cube
    72.   pg.beginDraw();
    73.   pg.translate(width >> 1, height >> 1);
    74.   pg.rotateX(sin(angle/2));
    75.   pg.rotateY(cos(angle/2));
    76.   pg.background(0);
    77.   pg.stroke(128);
    78.   pg.scale(25);
    79.   pg.noFill();
    80.   pg.box(4);
    81.   pg.endDraw();

    82.   // Randomize the bottom row of the fire buffer
    83.   for(int x = 0; x < width; x++)
    84.   {
    85.     fire[x][height-1] = int(random(0,190)) ;
    86.   }

    87.   glg2.loadPixels();

    88.   int counter = 0;
    89.   // Do the fire calculations for every pixel, from top to bottom
    90.   for (int y = 0; y < 360; y++) {
    91.     for(int x = 0; x < 640; x++) {
    92.       // Add pixel values around current pixel

    93.       fire[x][y] =
    94.           ((fire[calc3[x]][calc2[y]]
    95.           + fire[calc1[x]][calc2[y]]
    96.           + fire[calc4[x]][calc2[y]]
    97.           + fire[calc1[x]][calc5[y]]) << 5) / 129;

    98.       // Output everything to screen using our palette colors
    99.      glg2.pixels[counter] = palette[fire[x][y]];

    100.       // Extract the red value using right shift and bit mask 
    101.       // equivalent of red(pg.pixels[x+y*w])
    102.       if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) {
    103.         // Only map 3D cube 'lit' pixels onto fire array needed for next frame
    104.         fire[x][y] = 128;
    105.       }
    106.     }
    107.   }
    108.   glg2.updatePixels();
    109.   glg2.endDraw();

    110.   // We mix the images together and scale them so the occupy the entire screen.
    111.   tint(255, 255 - mixFactor);
    112.   image(glg1.getTexture(), 10, 10, width - 20, height - 20); 

    113.   tint(255, mixFactor);
    114.   image(glg2.getTexture(), 10, 10, width - 20, height - 20);

    115.   // Image border for reference.
    116.   noFill();
    117.   stroke(255);
    118.   rect(10, 10, width - 20, height - 20);  
    119.   fill(0); // 1.0.2/1.0.3 need this, because noFill() affects the tint used in image().
    120. }

    121. void mouseDragged() {
    122.   mixFactor = int(255 * float(mouseX) / width);
    123. }