I'm working on a little game that uses MSAFluid. Some bug in my code is causing the fluid to not display (but update!) when the mouse is not pressed. I know that the image() method is being reached because my println() statement after it is displaying messages, but the screen appears as a solid black. What am I doing wrong here?
- //Some lines that I could prove were not causing the bug are left out
- import msafluid.*;
- import processing.opengl.*;
- final float FLUID_WIDTH = 120;
- float invWidth, invHeight; // inverse of screen dimensions
- float aspectRatio, aspectRatio2;
- MSAFluidSolver2D fluidSolver;
- PImage imgFluid;
- void setup() {
- size(960, 640, OPENGL); // use OPENGL rendering for bilinear filtering on texture
- hint( ENABLE_OPENGL_4X_SMOOTH ); // Turn on 4X antialiasing
- invWidth = 1.0f/width;
- invHeight = 1.0f/height;
- aspectRatio = width * invHeight;
- aspectRatio2 = aspectRatio * aspectRatio;
- // create fluid and set options
- fluidSolver = new MSAFluidSolver2D((int)(FLUID_WIDTH), (int)(FLUID_WIDTH * height/width));
- fluidSolver.enableRGB(true).setFadeSpeed(0.003).setDeltaT(0.5).setVisc(0.0001);
- // create image to hold fluid picture
- imgFluid = createImage(fluidSolver.getWidth(), fluidSolver.getHeight(), RGB);
- }
- void draw() {
- colorMode(HSB,360,100,100);
- if(mousePressed) {
- if(mouseButton == LEFT) {
- addForce(50*invWidth,5*invHeight,0.3,0,color(frameCount%360,100,100)); //just the standard addForce
- } else { // These two lines both work //modified to take a color
- addForce(mouseX*invWidth,5*invHeight,-0.3,0,color(frameCount%360,100,100));
- }
- }
- fluidSolver.update();
- for (int i=0; i<fluidSolver.getNumCells(); i++) {
- int d = 5;
- imgFluid.pixels[i] = color(fluidSolver.r[i] * d, fluidSolver.g[i] * d, fluidSolver.b[i] * d);
- }
- imgFluid.updatePixels();
- fastblur(imgFluid.pixels, 3, fluidSolver.getWidth(),fluidSolver.getHeight()); //modified fastblur to take any width/height
- image(imgFluid, 0, 0, width, height);
- println(random(20000)); //this is always printing
- }
1