Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • textSize causing OutOfMemoryError

    I have a program that requires textSize to increase over time. When running it gradually, i.e. textSize(4),5,6,7,etc., the number can reach a very high value without anything bad happening. However, if I try to start off with a high value (the same number as gradually approached), it throws an OutOfMemory exception:

    java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:484) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.image.BufferedImage.(BufferedImage.java:324) at processing.core.PFont.(PFont.java:232) at processing.core.PFont.(PFont.java:337) at processing.core.PGraphics.createFont(PGraphics.java:4078) at processing.core.PApplet.createFont(PApplet.java:6254) at processing.core.PApplet.createDefaultFont(PApplet.java:6188) at processing.core.PGraphics.defaultFontOrDeath(PGraphics.java:8219) at processing.core.PGraphics.textSize(PGraphics.java:4391) at processing.core.PApplet.textSize(PApplet.java:12688) at recaman.draw(recaman.java:150) at processing.core.PApplet.handleDraw(PApplet.java:2418) at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:907) at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692) at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674) at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443) at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293) at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147) at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759) at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81) at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452) at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)

    Any help would be appreciated.

  • Trying to get P2D/P3D working on ARM dev Board [Mali-400]

    I am trying to get P2d mode on a Allwinner based board having MALI-400 GPU. Default renderer works ok. But when i try P3D i get :

    Caught handled GLException: EGLGLXDrawableFactory - Could not initialize shared resources for EGLGraphicsDevice[type .egl, v0.0.0, connection :0.0, unitID 0, handle 0x0, owner true, ResourceToolkitLock[obj 0x75ff7c, isOwner true, <b21f42, 8d940c>[count 1, qsz 0, owner <main-SharedResourceRunner>]]] on thread main-SharedResourceRunner [0]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createSharedResource(EGLDrawableFactory.java:518) [1]: jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:353) [2]: java.lang.Thread.run(Thread.java:748) Caused[0] by GLException: Failed to created/initialize EGL display incl. fallback default: native 0x0, error 0x3008/0x3000 on thread main-SharedResourceRunner [0]: jogamp.opengl.egl.EGLDisplayUtil.eglGetDisplayAndInitialize(EGLDisplayUtil.java:297) [1]: jogamp.opengl.egl.EGLDisplayUtil.access$300(EGLDisplayUtil.java:58) [2]: jogamp.opengl.egl.EGLDisplayUtil$1.eglGetAndInitDisplay(EGLDisplayUtil.java:320) [3]: com.jogamp.nativewindow.egl.EGLGraphicsDevice.open(EGLGraphicsDevice.java:125) [4]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createEGLSharedResourceImpl(EGLDrawableFactory.java:532) [5]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createSharedResource(EGLDrawableFactory.java:516) [6]: jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:353) [7]: java.lang.Thread.run(Thread.java:748) libGL error: unable to load driver: mali_drm_dri.so libGL error: driver pointer missing libGL error: failed to load driver: mali_drm libGL error: unable to load driver: mali_drm_dri.so libGL error: driver pointer missing libGL error: failed to load driver: mali_drm

    I checked with lsmod - i have mali_drm driver loaded [I am running Legacy Kernel armv6hf (3.4) with fbturbo video driver for Xorg 1.18 and libMali.so binary]

    Running glmark2-es2 benchmarking software gives me 150fps+ :

    OpenGL Information GL_VENDOR: ARM GL_RENDERER: Mali-400 MP GL_VERSION: OpenGL ES 2.0 All other softwares also seems to detect OpenGLES just fine.

    Do i need to make some modifications to Processing to make it find the right libs ? eg. replace core.jar / jogamp gluegen?

  • Converting Java code to Python

    Here's my Python Mode attempt. However, it's not working yet, it's just pitch black! :-&

    This statement crashes the sketch: geombuffer.update(pg_render) within resizeScreen(). Even when following exactly what it does, it doesn't seem to render anything. :o3

    https://GitHub.com/diwi/PixelFlow/blob/master/src/com/thomasdiewald/pixelflow/java/render/skylight/DwScreenSpaceGeometryBuffer.java#L67-L79

    public void update(PGraphics3D pg_src){
      
      resize(pg_src.width, pg_src.height);
      
      pg_geom.beginDraw();
      updateMatrices(pg_src);
      pg_geom.blendMode(PConstants.REPLACE);
      pg_geom.clear();
      pg_geom.shader(shader);
      pg_geom.noStroke();
      scene_display.display(pg_geom);
      pg_geom.endDraw();
    }
    

    So I'm at loss about it! Sorry. X_X Try finding help on diwi or jdf. ^#(^

    """
     * Depth of Field (DoF) (1.20)
     * Thomas Diewald (diwi) (2017-Oct-07)
     
     * GitHub.com/diwi/PixelFlow/blob/master/examples/Miscellaneous/
     * DepthOfField_Demo/DepthOfField_Demo.java
     
     * Refactor by GoToLoop (v1.4.2) (2018-May-18) (PDE v3.3.5)
     * Forum.Processing.org/two/discussion/27905/
     * converting-java-code-to-python#Item_20
    """
    
    add_library('PixelFlow')
    add_library('peasycam')
    
    from com.jogamp.opengl import GL2
    from processing.opengl import PGL
    
    from java.util import Formatter, Locale
    from jarray import zeros
    
    formatter = Formatter(Locale.ENGLISH)
    
    POSITION = 'position: (%8.2f, %8.2f, %8.2f)\n'
    ROTATION = 'rotation: (%8.2f, %8.2f, %8.2f)\n'
    LOOK__AT = 'look-at:  (%8.2f, %8.2f, %8.2f)\n'
    DISTANCE = 'distance: (%8.2f)\n'
    
    TITLE = __file__[:-5] + '   [fps %6.2f]'
    
    BB_SIZE = 800
    BB_OFFSET = BB_SIZE >> 2
    BB_TOTAL = BB_SIZE + BB_OFFSET
    BB_COORD, BB_DIAM = -BB_TOTAL, BB_TOTAL << 1
    
    XMIN, XMAX = -BB_SIZE, BB_SIZE
    YMIN, YMAX = -BB_SIZE, BB_SIZE
    ZMIN, ZMAX = 0, BB_SIZE
    
    BOX_DIAM = BB_OFFSET + BB_OFFSET/20
    SPH_MIN_D, SPH_MAX_D = BB_OFFSET >> 2, BB_OFFSET >> 1
    
    BOXES, SPHERES = 50, 50
    BOX_RANGE, SPH_RANGE = tuple(range(BOXES)), tuple(range(SPHERES))
    
    CROSS_S, ZFAR = 10, 6000
    MULT_BLUR, FPS = 30, 60
    BLUR_POW, RAD60 = pow(MULT_BLUR, 1/3.0), 60*DEG_TO_RAD
    
    BASE_COL, CROSS_COL = 0x80FFFFFF, 0xd0FFFFFF
    
    SEED, FIXED_SEED = 0, False
    FULLSCREEN, RESIZABLE = False, False
    apply_dof, alt_render = False, False
    
    resized = zeros(1, 'z')
    cube_smooth, cube_facets = DwCube(4), DwCube(2)
    shp_scene = pg_render = pg_dof = pg_tmp = None
    
    def settings():
        if FULLSCREEN: fullScreen(P3D) 
        else: size(this.displayWidth*9/10, this.displayHeight*9/10, P3D)
        noSmooth()
    
    
    def setup():
        frameRate(FPS); cursor(CROSS)
    
        global surf, canv
        surf, canv = this.surface, this.graphics
    
        if RESIZABLE: surf.resizable = True
        surf.setLocation(this.displayWidth - width >> 1, 8)
    
        global peasy
        peasy = PeasyCam(this, -4.083, -6.096, 7, 2000)
        peasy.setRotations(1.085, -.477, 2.91)
    
        global context, dw_filter, dof, param, geombuffer, magnifier
    
        context = DwPixelFlow(this)
        dw_filter = DwFilter.get(context)
        context.print(); context.printGL()
    
        dof = DepthOfField(context)
        param = dof.param
        param.mult_blur = MULT_BLUR
    
        class SceneDisplay(DwSceneDisplay):
            def display(_, canvas): displayScene(canvas)
    
    
        geombuffer = DwScreenSpaceGeometryBuffer(context, SceneDisplay())
    
        mag_h = height/3
        magnifier = DwMagnifier(this, 4, 0, height - mag_h, mag_h, mag_h)
    
    
    def draw():
        setTitle(); resizeScreen(); displaySceneWrap(pg_render)
        dw_filter.gamma.apply(pg_render, pg_render)
    
        apply_dof and applyDoF()
        renderScene()
    
    
    def keyPressed():
        global apply_dof, alt_render, shp_scene
        k = chr(keyCode) if key != CODED else keyCode
    
        if k == 'P' or k == BACKSPACE: noLoop() if this.looping else loop()
        elif k == 'C' or k == CONTROL: printCam()
        elif k == ' ': apply_dof ^= True
        elif k == SHIFT: alt_render ^= True
        elif k == ENTER or k == RETURN: shp_scene = None
    
    
    def applyDoF():
        geom = geombuffer.pg_geom
        dw_filter.gaussblur.apply(geom, geom, pg_tmp, BLUR_POW)
    
        param.focus_pos[0] = map(mouseX + .5, 0, width, 00, 1)
        param.focus_pos[1] = map(mouseY + .5, 0, height, 1, 0)
        dof.apply(pg_render, pg_dof, geombuffer)
    
        dw_filter.copy.apply(pg_dof, pg_render)
    
    
    def renderScene():
        pg = geombuffer.pg_geom if alt_render else pg_render
    
        magnifier.apply(pg, mouseX, mouseY)
        magnifier.displayTool()
    
        DwUtils.beginScreen2D(canv)
        # peasy.beginHUD()
    
        blendMode(REPLACE); image(pg, 0, 0)
        magnifier.display(pg, 0, height - magnifier.h)
    
        fpx = param.focus_pos[0] * width
        fpy = (1 - param.focus_pos[1]) * height
    
        blendMode(EXCLUSION); strokeCap(PROJECT); stroke(CROSS_COL)
        line(fpx - CROSS_S, fpy, fpx + CROSS_S, fpy)
        line(fpx, fpy - CROSS_S, fpx, fpy + CROSS_S)
        blendMode(BLEND)
    
        # peasy.endHUD()
        DwUtils.endScreen2D(canv)
    
    
    def resizeScreen():
        global pg_render, pg_dof, pg_tmp
        w = width; h = height
    
        perspective(RAD60, float(w)/h, 2, ZFAR)
        peasy.feed()
    
        happened = resized[0] = False
        pg_render = DwUtils.changeTextureSize(this, pg_render, w, h, 8, resized)
        happened |= resized[0]
    
        resized[0] = False
        pg_dof = DwUtils.changeTextureSize(this, pg_dof, w, h, 0, resized)
        happened |= resized[0]
    
        resized[0] = False
        pg_tmp = DwUtils.changeTextureSize(this, pg_tmp, w, h, 0, resized,
        GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT)
    
        # geombuffer.update(pg_render)
    
        happened |= geombuffer.resize(pg_render.width, pg_render.height)
        geombuffer.pg_geom.beginDraw()
    
        # geombuffer.updateMatrices(pg_render)
        DwUtils.copyMatrices(pg_render, geombuffer.pg_geom)
    
        geombuffer.pg_geom.blendMode(REPLACE)
        geombuffer.pg_geom.clear()
        geombuffer.pg_geom.shader(geombuffer.shader)
        geombuffer.pg_geom.noStroke()
        geombuffer.scene_display.display(geombuffer.pg_geom)
        geombuffer.pg_geom.endDraw()
    
        return happened | resized[0]
    
    
    def displaySceneWrap(canvas):
        DwUtils.copyMatrices(canv, canvas)
        canvas.beginDraw()
        canvas.background(2)
        displayScene(canvas)
        canvas.endDraw()
    
    
    def displayScene(canvas):
        canvas.directionalLight(255, 255, 255, 200, 600, 400)
        canvas.directionalLight(255, 255, 255, -200, -600, -400)
        canvas.ambientLight(64, 64, 64)
    
        if canvas is geombuffer.pg_geom:
            canvas.background(-1)
            canvas.pgl.clearColor(1, 1, 1, ZFAR)
            canvas.pgl.clear(PGL.COLOR_BUFFER_BIT)
    
        global shp_scene
        if not shp_scene: shp_scene = makeShape()
        canvas.shape(shp_scene)
    
    
    def makeShape():
        scene = createShape(GROUP)
        FIXED_SEED and randomSeed(SEED)
    
        with pushStyle():
            colorMode(HSB, 360, 1, 1); noStroke()
    
            for i in BOX_RANGE:
                px = random(XMIN, XMAX); py = random(YMIN, YMAX)
                sx = random(BOX_DIAM, BOX_DIAM); sy = random(BOX_DIAM, BOX_DIAM)
                sz = random(ZMIN, ZMAX)
    
                fill(random(-45, 45), 1, random(.1, 1))
                shp_box = createShape(BOX, sx, sy, sz)
                shp_box.translate(px, py, sz*.5)
                scene.addChild(shp_box)
    
            for i in SPH_RANGE:
                px = random(XMIN, XMAX); py = random(YMIN, YMAX)
                pz = random(ZMIN, ZMAX); rr = random(SPH_MIN_D, SPH_MAX_D)
    
                fill(random(205, 245), 1, random(.1, 1))
                shp_sphere = createShape(PShape.GEOMETRY)
                shp_sphere.scale(rr); shp_sphere.translate(px, py, pz)
                scene.addChild(shp_sphere)
    
                DwMeshUtils.createPolyhedronShape(shp_sphere, cube_smooth, 1, 4, True)\
                if i&1 else\
                DwMeshUtils.createPolyhedronShape(shp_sphere, cube_facets, 1, 4, False)
    
            fill(BASE_COL)
            scene.addChild(createShape(RECT, BB_COORD, BB_COORD, BB_DIAM, BB_DIAM))
    
        return scene
    
    
    def clearFormatter(f): f.out().setLength(0)
    
    
    def setTitle():
        clearFormatter(formatter)
        surf.title = formatter.format(TITLE, frameRate).toString()
    
    
    def printCam():
        pos = peasy.position; rot = peasy.rotations
        lat = peasy.getLookAt(); dis = peasy.distance
    
        clearFormatter(formatter)
    
        print formatter.\
        format(POSITION, *pos).format(ROTATION, *rot).\
        format(LOOK__AT, *lat).format(DISTANCE, dis)
    
  • Converting Java code to Python

    Hi @solub! It took a long time, but I've just finished refactoring "Depth_of_Field.pde". #:-S

    Now that I've reorganized this sketch, I'm ready to convert it to a ".pyde" file. :)>-

    Just w8 a lil' more. Stay w/ the latest ".pde" file for now: :-\"

    /**
     * Depth of Field (DoF) (1.20)
     * Thomas Diewald (diwi) (2017-Oct-07)
    
     * GitHub.com/diwi/PixelFlow/blob/master/examples/Miscellaneous/
     * DepthOfField_Demo/DepthOfField_Demo.java
    
     * Refactor by GoToLoop (v1.4.2) (2018-May-18) (PDE v3.3.5)
     * Forum.Processing.org/two/discussion/27905/converting-java-code-to-python#Item_18
     */
    
    import com.thomasdiewald.pixelflow.java.DwPixelFlow;
    import com.thomasdiewald.pixelflow.java.geometry.DwIndexedFaceSetAble;
    import com.thomasdiewald.pixelflow.java.geometry.DwCube;
    import com.thomasdiewald.pixelflow.java.geometry.DwMeshUtils;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DepthOfField;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwSceneDisplay;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwScreenSpaceGeometryBuffer;
    import com.thomasdiewald.pixelflow.java.utils.DwMagnifier;
    import com.thomasdiewald.pixelflow.java.utils.DwUtils;
    
    import peasy.PeasyCam;
    
    import com.jogamp.opengl.GL2;
    
    import static java.util.Locale.ENGLISH;
    import java.util.Formatter;
    
    final Formatter formatter = new Formatter(ENGLISH);
    
    static final String POSITION = "position: (%8.2f, %8.2f, %8.2f)\n";
    static final String ROTATION = "rotation: (%8.2f, %8.2f, %8.2f)\n";
    static final String LOOK__AT = "look-at:  (%8.2f, %8.2f, %8.2f)\n";
    static final String DISTANCE = "distance: (%8.2f)\n";
    
    final String TITLE = getClass().getName() + "   [fps %6.2f]";
    
    static final int BB_SIZE = 800, BB_OFFSET = BB_SIZE >> 2;
    static final int BB_TOTAL = BB_SIZE + BB_OFFSET;
    static final int BB_COORD = -BB_TOTAL, BB_DIAM = BB_TOTAL << 1;
    
    static final int XMIN = -BB_SIZE, XMAX = BB_SIZE;
    static final int YMIN = -BB_SIZE, YMAX = BB_SIZE;
    static final int ZMIN = 0, ZMAX = BB_SIZE;
    
    static final int BOX_DIAM = BB_OFFSET + BB_OFFSET/20;
    static final int SPH_MIN_D = BB_OFFSET >> 2, SPH_MAX_D = BB_OFFSET >> 1;
    
    static final int BOXES = 50, SPHERES = 50;
    
    static final int CROSS_S = 10, ZFAR = 6000;
    static final int MULT_BLUR = 30, BLUR_POW = (int) pow(MULT_BLUR, 1/3.0);
    static final float RAD60 = 60*DEG_TO_RAD, FPS = 60;
    
    static final color BASE_COL = 0x80FFFFFF, CROSS_COL = 0xd0FFFFFF;
    
    static final long SEED = 0;
    static final boolean FIXED_SEED = false;
    
    static final boolean FULLSCREEN = false, RESIZABLE = false;
    boolean apply_dof = false, alt_render = false;
    
    final boolean[] resized = new boolean[1];
    
    final DwIndexedFaceSetAble cube_smooth = new DwCube(4), cube_facets = new DwCube(2);
    
    PGraphics3D pg_render, pg_dof, pg_tmp;
    PShape shp_scene;
    
    PeasyCam peasy;
    
    DwPixelFlow context;
    DwFilter dw_filter;
    DepthOfField dof;
    DwScreenSpaceGeometryBuffer geombuffer;
    DwMagnifier magnifier;
    
    void settings() {
      if (FULLSCREEN) fullScreen(P3D);
      else size(displayWidth*9/10, displayHeight*9/10, P3D);
      noSmooth();
    }
    
    void setup() {
      frameRate(FPS);
      cursor(CROSS);
    
      if (RESIZABLE)  getSurface().setResizable(true);
      getSurface().setLocation(displayWidth - width >> 1, 8);
    
      peasy = new PeasyCam(this, -4.083, -6.096, 7, 2000);
      peasy.setRotations(1.085, -.477, 2.91);
    
      dw_filter = DwFilter.get(context = new DwPixelFlow(this));
      context.print();
      context.printGL();
    
      dof = new DepthOfField(context);
      dof.param.mult_blur = MULT_BLUR;
    
      final DwSceneDisplay scene_display = new DwSceneDisplay() {  
        @ Override final public void display(final PGraphics3D canvas) {
          displayScene(canvas);
        }
      };
    
      geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
    
      final int mag_h = height/3;
      magnifier = new DwMagnifier(this, 4, 0, height - mag_h, mag_h, mag_h);
    }
    
    void draw() {
      final PGraphics canv = getGraphics();
      final DepthOfField.Param param = dof.param;
    
      setTitle();
      resizeScreen();
      displaySceneWrap(pg_render, canv);
      dw_filter.gamma.apply(pg_render, pg_render);
    
      if (apply_dof)  applyDoF(param);
      renderScene(param, canv);
    }
    
    void keyPressed() {
      final int k = keyCode;
    
      if (k == ENTER | k == RETURN)  shp_scene = null;
      else if (k == 'C' | k == CONTROL)  printCam();
      else if (k == 'P' | k == BACKSPACE)  looping ^= true;
      else if (k == ' ')  apply_dof ^= true;
      else if (k == SHIFT)  alt_render ^= true;
    }
    
    void applyDoF(final DepthOfField.Param param) {
      final PGraphicsOpenGL geom = geombuffer.pg_geom;
      dw_filter.gaussblur.apply(geom, geom, pg_tmp, BLUR_POW);
    
      param.focus_pos[0] = map(mouseX + .5, 0, width, 00, 1);
      param.focus_pos[1] = map(mouseY + .5, 0, height, 1, 0);
      dof.apply(pg_render, pg_dof, geombuffer);
    
      dw_filter.copy.apply(pg_dof, pg_render);
    }
    
    void renderScene(final DepthOfField.Param param, final PGraphics canv) {
      final PGraphics pg = alt_render? geombuffer.pg_geom : pg_render;
    
      magnifier.apply(pg, mouseX, mouseY);
      magnifier.displayTool();
    
      DwUtils.beginScreen2D(canv);
      //peasy.beginHUD();
    
      blendMode(REPLACE);
      image(pg, 0, 0);
      magnifier.display(pg, 0, height - magnifier.h);
    
      final float fpx = param.focus_pos[0] * width;
      final float fpy = (1 - param.focus_pos[1]) * height;
    
      blendMode(EXCLUSION);
      strokeCap(PROJECT);
      stroke(CROSS_COL);
      line(fpx - CROSS_S, fpy, fpx + CROSS_S, fpy);
      line(fpx, fpy - CROSS_S, fpx, fpy + CROSS_S);
      blendMode(BLEND);
    
      //peasy.endHUD();
      DwUtils.endScreen2D(canv);
    }
    
    boolean resizeScreen() { // dynamically resize render-targets
      final int w = width, h = height;
    
      perspective(RAD60, (float) w/h, 2, ZFAR);
      peasy.feed();
    
      boolean happened = resized[0] = false;
      pg_render = DwUtils.changeTextureSize(this, pg_render, w, h, 8, resized);
      happened |= resized[0];
    
      resized[0] = false;
      pg_dof = DwUtils.changeTextureSize(this, pg_dof, w, h, 0, resized);
      happened |= resized[0];
    
      resized[0] = false;
      pg_tmp = DwUtils.changeTextureSize(this, pg_tmp, w, h, 0, resized, 
        GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);
    
      geombuffer.update(pg_render);
      return happened | resized[0];
    }
    
    void displaySceneWrap(final PGraphics3D canvas, final PGraphics canv) {
      DwUtils.copyMatrices((PGraphicsOpenGL) canv, canvas);
      canvas.beginDraw();
      canvas.background(2);
      displayScene(canvas);
      canvas.endDraw();
    }
    
    void displayScene(final PGraphics3D canvas) {
      canvas.directionalLight(255, 255, 255, 200, 600, 400);
      canvas.directionalLight(255, 255, 255, -200, -600, -400);
      canvas.ambientLight(64, 64, 64);
    
      if (canvas == geombuffer.pg_geom) {
        canvas.background(-1);
        canvas.pgl.clearColor(1, 1, 1, ZFAR);
        canvas.pgl.clear(PGL.COLOR_BUFFER_BIT);
      }
    
      if (shp_scene == null)  shp_scene = makeShape();
      canvas.shape(shp_scene);
    }
    
    PShape makeShape() {
      final PShape scene = createShape(GROUP);
    
      pushStyle();
      colorMode(HSB, 360, 1, 1);
      noStroke();
    
      if (FIXED_SEED)  randomSeed(SEED);
    
      for (int i = 0; i < BOXES; ++i) {
        final float px = random(XMIN, XMAX), py = random(YMIN, YMAX);
        final float sx = random(BOX_DIAM, BOX_DIAM), sy = random(BOX_DIAM, BOX_DIAM);
        final float sz = random(ZMIN, ZMAX);
    
        fill(random(-45, 45), 1, random(.1, 1));
        final PShape shp_box = createShape(BOX, sx, sy, sz);
        shp_box.translate(px, py, sz*.5);
        scene.addChild(shp_box);
      }
    
      for (int i = 0; i < SPHERES; ++i) {
        final float px = random(XMIN, XMAX), py = random(YMIN, YMAX);
        final float pz = random(ZMIN, ZMAX), rr = random(SPH_MIN_D, SPH_MAX_D);
    
        fill(random(205, 245), 1, random(.1, 1));
        final PShape shp_sphere = createShape(PShape.GEOMETRY);
        shp_sphere.scale(rr);
        shp_sphere.translate(px, py, pz);
        scene.addChild(shp_sphere);
    
        if ((i&1) == 0)
          DwMeshUtils.createPolyhedronShape(shp_sphere, cube_facets, 1, 4, false);
        else
          DwMeshUtils.createPolyhedronShape(shp_sphere, cube_smooth, 1, 4, true);
      }
    
      fill(BASE_COL);
      scene.addChild(createShape(RECT, BB_COORD, BB_COORD, BB_DIAM, BB_DIAM));
    
      popStyle();
      return scene;
    }
    
    static final void clearFormatter(final Formatter f) {
      ((StringBuilder) f.out()).setLength(0);
    }
    
    void setTitle() {
      clearFormatter(formatter);
      getSurface().setTitle(formatter.format(TITLE, frameRate).toString());
    }
    
    void printCam() {
      final float[] pos = peasy.getPosition();
      final float[] rot = peasy.getRotations();
      final float[] lat = peasy.getLookAt();
      final double  dis = peasy.getDistance();
    
      clearFormatter(formatter);
    
      println(formatter.
        format(POSITION, pos[0], pos[1], pos[2]).
        format(ROTATION, rot[0], rot[1], rot[2]).
        format(LOOK__AT, lat[0], lat[1], lat[2]).
        format(DISTANCE, dis));
    }
    
  • Converting Java code to Python

    I'm back with another question, sorry. I still have a persistent issue with the resizeScreen() function and more particularly with thepg_render and pg_tmp grahics buffers variables.

    When running the .pyde script I get the following error messages:

    GammaCorrection.apply shader | GL_ERROR: invalid operation GammaCorrection.apply | GL_ERROR: invalid operation GammaCorrection.apply | GL_ERROR: invalid framebuffer operation

    This occurs at line 110 (Java script) or 58 (Python version):

    DwFilter.get(context).gamma.apply(pg_render, pg_render)

    Do you know what could be the problem here ?

    Here below, for comparison purposes:

    • a shortened version of the original DoF example sketch in Java (working)
    • the Python transcription of this version (not working)

    Java

    import java.util.Locale;
    import com.jogamp.opengl.GL2;
    import com.thomasdiewald.pixelflow.java.DwPixelFlow;
    import com.thomasdiewald.pixelflow.java.geometry.DwCube;
    import com.thomasdiewald.pixelflow.java.geometry.DwMeshUtils;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DepthOfField;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwSceneDisplay;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwScreenSpaceGeometryBuffer;
    import com.thomasdiewald.pixelflow.java.utils.DwMagnifier;
    import com.thomasdiewald.pixelflow.java.utils.DwUtils;
    
    import peasy.*;
    import processing.core.PApplet;
    import processing.core.PConstants;
    import processing.core.PShape;
    import processing.opengl.PGL;
    import processing.opengl.PGraphics3D;
    
    
      boolean START_FULLSCREEN = !true;
    
      int viewport_w = 1280;
      int viewport_h = 720;
      int viewport_x = 230;
      int viewport_y = 0;
    
      // camera control
      PeasyCam peasycam;
    
      // library context
      DwPixelFlow context;
    
      PGraphics3D pg_render;
      PGraphics3D pg_dof;
      PGraphics3D pg_tmp;
    
      DepthOfField dof;
      DwScreenSpaceGeometryBuffer geombuffer;
    
      boolean APPLY_DOF = true;
    
    
      public void settings() {
        if(START_FULLSCREEN){
          viewport_w = displayWidth;
          viewport_h = displayHeight;
          viewport_x = 0;
          viewport_y = 0;
          fullScreen(P3D);
        } else {
          size(viewport_w, viewport_h, P3D);
        }
        smooth(0);
      }
    
    
      public void setup() {
    
        // camera
        peasycam = new PeasyCam(this, -4.083,  -6.096,   7.000, 1300);
        peasycam.setRotations(  1.085,  -0.477,   2.910);
    
        // main library context
        context = new DwPixelFlow(this);
        context.print();
        context.printGL();
    
        // callback for scene display (used in GBAA)
        DwSceneDisplay scene_display = new DwSceneDisplay() {  
          @Override
          public void display(PGraphics3D canvas) {
            displayScene(canvas); 
          }
        };
    
        geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
    
        dof = new DepthOfField(context);
    
        frameRate(1000);
      }
    
    
    
      // dynamically resize render-targets
      public boolean resizeScreen(){
    
        boolean[] RESIZED = {false};
    
        pg_render = DwUtils.changeTextureSize(this, pg_render, width, height, 8, RESIZED);
        pg_dof    = DwUtils.changeTextureSize(this, pg_dof   , width, height, 0, RESIZED);
        pg_tmp    = DwUtils.changeTextureSize(this, pg_tmp   , width, height, 0, RESIZED, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);
    
    
        peasycam.feed();
        perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
    
        return RESIZED[0];
      }
    
    
    
      public void draw() {
    
        resizeScreen();
    
        displaySceneWrap(pg_render);
    
        DwFilter.get(context).gamma.apply(pg_render, pg_render);
    
        int mult_blur = 30;
        geombuffer.update(pg_render);
    
        DwFilter.get(context).gaussblur.apply(geombuffer.pg_geom, geombuffer.pg_geom, pg_tmp, (int) Math.pow(mult_blur, 0.33f));
    
    ////      dof.param.focus     = map(mouseX, 0, width, 0, 1);
        dof.param.focus_pos = new float[]{0.5f, 0.5f};
        dof.param.focus_pos[0] = map(mouseX+0.5f, 0, width , 0, 1);
        dof.param.focus_pos[1] = map(mouseY+0.5f, 0, height, 1, 0);
        dof.param.mult_blur = mult_blur;
        dof.apply(pg_render, pg_dof, geombuffer);
    
        DwFilter.get(context).copy.apply(pg_dof, pg_render);
    
    
        DwUtils.beginScreen2D(g);
        {
          blendMode(REPLACE);
          clear();
          image(pg_render, 0, 0);    
        }
        DwUtils.endScreen2D(g);
      }
    
    
    
      public void displaySceneWrap(PGraphics3D canvas){
        canvas.beginDraw();
        DwUtils.copyMatrices((PGraphics3D) this.g, canvas);
        // background
        canvas.blendMode(PConstants.BLEND);
        canvas.background(2);
        displayScene(canvas);
        canvas.endDraw();
      }
    
    
    
      // render something
      public void displayScene(PGraphics3D canvas){
        // lights
        canvas.directionalLight(255, 255, 255, 200,600,400);
        canvas.directionalLight(255, 255, 255, -200,-600,-400);
        canvas.ambientLight(64, 64, 64);
    
        if(canvas == geombuffer.pg_geom){
          canvas.background(255, 255);
          canvas.pgl.clearColor(1, 1, 1, 6000);
          canvas.pgl.clear(PGL.COLOR_BUFFER_BIT);
        }
    
    
        sceneShape(canvas);
      }
    
      PShape shp_scene;
    
      public void sceneShape(PGraphics3D canvas){
        if(shp_scene != null){
          canvas.shape(shp_scene);
          return;
        }
    
        shp_scene = createShape(GROUP);
    
        int num_spheres = 50;
        float bb_size = 800;
        float xmin = -bb_size;
        float xmax = +bb_size;
        float ymin = -bb_size;
        float ymax = +bb_size;
        float zmin =  0;
        float zmax = +bb_size;
    
        colorMode(HSB, 360, 1, 1);
    
        DwCube cube_smooth = new DwCube(4);
        DwCube cube_facets = new DwCube(2);
    
        for(int i = 0; i < num_spheres; i++){
          float px = random(xmin, xmax);
          float py = random(ymin, ymax);
          float pz = random(zmin, zmax);
          float rr = random(50) + 50;
          boolean facets = true;//(i%2 == 0);
    
          float off = 20;
          float base = 225;
          float hsb_h = base + random(-off,off);
          float hsb_s = 1;
          float hsb_b = random(0.1f,1.0f);
          int shading = color(hsb_h, hsb_s, hsb_b);
    
          PShape shp_sphere = createShape(PShape.GEOMETRY);
          if(facets){
            DwMeshUtils.createPolyhedronShape(shp_sphere, cube_facets, 1, 4, false);
          } else {
            DwMeshUtils.createPolyhedronShape(shp_sphere, cube_smooth, 1, 4, true);
          }
    
          shp_sphere.setStroke(!true);
          shp_sphere.setStroke(color(0));
          shp_sphere.setStrokeWeight(0.01f / rr);
          shp_sphere.setFill(true);
          shp_sphere.setFill(shading);
          shp_sphere.resetMatrix();
          shp_sphere.scale(rr);
          shp_sphere.translate(px, py, pz);
          shp_scene.addChild(shp_sphere);
        }
    
      }
    

    Python

    add_library('PixelFlow')
    add_library('peasycam')
    from com.jogamp.opengl import GL2
    import java.util.Locale
    
    liste = []
    viewport_w = 1280
    viewport_h = 720
    viewport_x = 0
    viewport_y = 0
    FS = False
    
    def settings():
        global viewport_w, viewport_h
        if FS:
            viewport_w = displayWidth
            viewport_h = displayHeight
            viewport_x = 0
            viewport_y = 0
            fullScreen(P3D)
        else:
            size(viewport_w, viewport_h, P3D)
        smooth(0)
    
    
    def setup():
        global context, scene_display, geombuffer, dof, cam
    
        cam = PeasyCam(this, -4.083,  -6.096,   7.000, 1300)
    
        context = DwPixelFlow(this)
        context.print()
        context.printGL()
    
        scene_display = MySceneDisplay() 
        geombuffer = DwScreenSpaceGeometryBuffer(context, scene_display)
        dof = DepthOfField(context)
    
    
    def resizeScreen():
        global pg_render, pg_dof, pg_tmp
        RESIZED = [False]
        pg_render = DwUtils.changeTextureSize(this, None, width, height, 8, RESIZED)
        pg_dof    = DwUtils.changeTextureSize(this, None, width, height, 0, RESIZED)
        pg_tmp    = DwUtils.changeTextureSize(this, None, width, height, 0, RESIZED, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT)
    
        cam.feed()
        perspective(60 * DEG_TO_RAD, width/float(height), 2, 6000)
    
        return RESIZED[0]
    
    
    def draw():
        resizeScreen()
    
        displaySceneWrap(pg_render)
    
        DwFilter.get(context).gamma.apply(pg_render, pg_render)
    
        mult_blur = 30
    
        geombuffer.update(pg_render)
    
        DwFilter.get(context).gaussblur.apply(geombuffer.pg_geom, geombuffer.pg_geom, pg_tmp, int(Math.pow(mult_blur, 0.33)))
    
        dof.param.focus_pos = float(0.5, 0.5)
        dof.param.focus_pos[0] = map(mouseX+0.5, 0, width, 0, 1)
        dof.param.focus_pos[1] = map(mouseY+0.5, 0, height, 1, 0)
        dof.param.mult_blur = mult_blur
        dof.apply(pg_render, pg_dof, geombuffer)
    
        DwFilter.get(context).copy.apply(pg_dof, pg_render)
    
        DwUtils.beginScreen2D(g)
        blendMode(REPLACE)
        clear()
        image(pg.render,0,0)
        DwUtils.endScreen2D(g)
    
    
    def displaySceneWrap(canvas):
        canvas.beginDraw()
        DwUtils.copyMatrices(this.g, canvas)
        canvas.blendMode(PConstants.BLEND)
        canvas.background(2)
        displayScene(canvas)
        canvas.endDraw()
    
    def displayScene(canvas):
        canvas.directionalLight(255, 255, 255, 200,600,400)
        canvas.directionalLight(255, 255, 255, -200,-600,-400)
        canvas.ambientLight(64, 64, 64)
    
        if canvas == geombuffer.pg_geom:
            canvas.background(255, 255)
            canvas.pgl.clearColor(1, 1, 1, 6000)
            canvas.pgl.clear(PGL.COLOR_BUFFER_BIT)
    
        sceneShape(canvas)
    
    
    def sceneShape(canvas): 
    
        shp_scene = createShape(GROUP)
    
        if shp_scene != None:
            canvas.shape(shp_scene)
            return   
    
        num_spheres = 50
        bb_size = 800
        xmin = -bb_size
        xmax = +bb_size
        ymin = -bb_size
        ymax = +bb_size
        zmin =  0
        zmax = +bb_size
    
        colorMode(HSB, 360, 1, 1)
    
        cube_smooth = DwCube(4)
        cube_facets = DwCube(2)
    
        for i in range(num_spheres):
            px = random(xmin, xmax)
            py = random(ymin, ymax)
            pz = random(zmin, zmax)
            facets = True
    
            off = 20
            base =225
            hsb_h = base + random(-off, off)
            hsb_s = 1
            hsb_b = random(0.1, 1.0)
            shading = color(hsb_h, hsb_s, hsb_b)
    
        shp_sphere = createShape(PShape.GEOMETRY)
        if facets:
            DwMeshUtils.createPolyhedronShape(shp_sphere, cube_facets, 1, 4, False)
        else:
            DwMeshUtils.createPolyhedronShape(shp_sphere, cube_smooth, 1, 4, True)
    
        shp_sphere.setStroke(False);
        shp_sphere.setStroke(color(0));
        shp_sphere.setStrokeWeight(0.01 / rr);
        shp_sphere.setFill(True);
        shp_sphere.setFill(shading);
        shp_sphere.resetMatrix();
        shp_sphere.scale(rr);
        shp_sphere.translate(px, py, pz);
        shp_scene.addChild(shp_sphere);
    
    
    class MySceneDisplay(DwSceneDisplay): 
        def display(_, canvas): displayScene(canvas)
    
  • Converting Java code to Python

    I wonder if you 1st was able to transpile back the ".java" sketch as a ".pde" in order to run it under Java Mode? :-?

    • Like removing the statement w/ the package keyword.
    • The public class DepthOfField_Demo extends PApplet { statement & its corresponding closing curly brace.
    • And of course, the whole public static void main(String args[]) { code block. #:-S

    That whole code is æsthetically messy. But here's what I've come w/ as a ".pde" file w/o changing the original ".java" 1 much: :P

    "Depth_of_Field.pde":

    // Depth of Field (DoF) (1.20)
    // Thomas Diewald (diwi) (2017-Oct-07)
    
    // GitHub.com/diwi/PixelFlow/blob/master/examples/Miscellaneous/
    // DepthOfField_Demo/DepthOfField_Demo.java
    
    import static java.util.Locale.ENGLISH;
    
    import com.jogamp.opengl.GL2;
    
    import peasy.PeasyCam;
    
    import com.thomasdiewald.pixelflow.java.DwPixelFlow;
    import com.thomasdiewald.pixelflow.java.geometry.DwCube;
    import com.thomasdiewald.pixelflow.java.geometry.DwMeshUtils;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DepthOfField;
    import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwSceneDisplay;
    import com.thomasdiewald.pixelflow.java.render.skylight.DwScreenSpaceGeometryBuffer;
    import com.thomasdiewald.pixelflow.java.utils.DwMagnifier;
    import com.thomasdiewald.pixelflow.java.utils.DwUtils;
    
    static final String POSITION = "position: (%7.3f, %7.3f, %7.3f)\n";
    static final String ROTATION = "rotation: (%7.3f, %7.3f, %7.3f)\n";
    static final String LOOK_AT  = "look-at:  (%7.3f, %7.3f, %7.3f)\n";
    static final String DISTANCE = "distance: (%7.3f)\n";
    
    static final String FPS = "   [fps %6.2f]";
    
    boolean start_fullscreen = false;
    
    int viewport_w = 1000;
    int viewport_h = 600;
    int viewport_x = 200;
    int viewport_y = 0;
    
    // camera control
    PeasyCam peasycam;
    
    // library context
    DwPixelFlow context;
    
    PShape shp_scene;
    
    PGraphics3D pg_render;
    PGraphics3D pg_dof;
    PGraphics3D pg_tmp;
    
    DepthOfField dof;
    DwScreenSpaceGeometryBuffer geombuffer;
    
    DwMagnifier magnifier;
    
    boolean apply_dof = true;
    
    void settings() {
      if (!start_fullscreen)  size(viewport_w, viewport_h, P3D);
      else {
        fullScreen(P3D);
        viewport_w = displayWidth;
        viewport_h = displayHeight;
        viewport_x = 0;
        viewport_y = 0;
      }
    
      noSmooth();
    }
    
    void setup() {
      surface.setResizable(true);
      surface.setLocation(viewport_x, viewport_y);
    
      // camera
      peasycam = new PeasyCam(this, -4.083, -6.096, 7.000, 1300);
      peasycam.setRotations(1.085, -0.477, 2.910);
    
      // main library context
      context = new DwPixelFlow(this);
      context.print();
      context.printGL();
    
      // callback for scene display (used in GBAA)
      DwSceneDisplay scene_display = new DwSceneDisplay() {  
        @ Override public void display(PGraphics3D canvas) {
          displayScene(canvas);
        }
      };
    
      geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
    
      dof = new DepthOfField(context);
    
      int mag_h = height/3;
      magnifier = new DwMagnifier(this, 4, 0, height - mag_h, mag_h, mag_h);
    
      frameRate(1000);
    }
    
    void draw() {
      resizeScreen();
      displaySceneWrap(pg_render);
      DwFilter.get(context).gamma.apply(pg_render, pg_render);
    
      int mult_blur = 30;
    
      if (apply_dof) {
        geombuffer.update(pg_render);
    
        DwFilter.get(context).gaussblur.apply(geombuffer.pg_geom, geombuffer.pg_geom, 
          pg_tmp, (int) Math.pow(mult_blur, 0.33));
    
        //      dof.param.focus     = map(mouseX, 0, width, 0, 1);
        dof.param.focus_pos = new float[]{0.5, 0.5};
        dof.param.focus_pos[0] = map(mouseX+0.5, 0, width, 0, 1);
        dof.param.focus_pos[1] = map(mouseY+0.5, 0, height, 1, 0);
        dof.param.mult_blur = mult_blur;
        dof.apply(pg_render, pg_dof, geombuffer);
    
        DwFilter.get(context).copy.apply(pg_dof, pg_render);
      }
    
      magnifier.apply(pg_render, mouseX, mouseY);
      magnifier.displayTool();
    
      DwUtils.beginScreen2D(g);
      //    peasycam.beginHUD();
      {
        blendMode(REPLACE);
        clear();
        image(pg_render, 0, 0);
        //      image(geombuffer.pg_geom, 0, 0);
    
        magnifier.display(g, 0, height-magnifier.h);
    
        blendMode(BLEND);
    
        pushMatrix();
        float cursor_s = 10;
    
        float fpx = dof.param.focus_pos[0] * width;
        float fpy = (1.0 - dof.param.focus_pos[1]) * height;
    
        blendMode(EXCLUSION);
        translate(fpx, fpy);
        strokeWeight(1);
        stroke(255, 200);
        line(-cursor_s, 0, +cursor_s, 0);
        line(0, -cursor_s, 0, +cursor_s);
        blendMode(BLEND);
        popMatrix();
      }
      //    peasycam.endHUD();
      DwUtils.endScreen2D(g);
    
      String txt_fps = String.format(getClass().getName() + FPS, frameRate);
      surface.setTitle(txt_fps);
    }
    
    void keyReleased() {
      if (keyCode == 'C') printCam();
      else if (key == ' ') apply_dof = !apply_dof;
    }
    
    boolean resizeScreen() { // dynamically resize render-targets
      final boolean[] resized = { false };
    
      pg_render = DwUtils.changeTextureSize(this, pg_render, width, height, 8, resized);
      pg_dof    = DwUtils.changeTextureSize(this, pg_dof, width, height, 0, resized);
      pg_tmp    = DwUtils.changeTextureSize(this, pg_tmp, width, height, 0, resized, 
        GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);
    
      //    geombuffer.resize(width, height)
    
      if (resized[0]) {
        // nothing here
      }
    
      peasycam.feed();
      perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
    
      return resized[0];
    }
    
    void displaySceneWrap(PGraphics3D canvas) {
      canvas.beginDraw();
      DwUtils.copyMatrices((PGraphics3D) this.g, canvas);
    
      canvas.blendMode(PConstants.BLEND);
      canvas.background(2);
      displayScene(canvas);
      canvas.endDraw();
    }
    
    void displayScene(PGraphics3D canvas) {
      canvas.directionalLight(255, 255, 255, 200, 600, 400);
      canvas.directionalLight(255, 255, 255, -200, -600, -400);
      canvas.ambientLight(64, 64, 64);
    
      if (canvas == geombuffer.pg_geom) {
        canvas.background(255, 255);
        canvas.pgl.clearColor(1, 1, 1, 6000);
        canvas.pgl.clear(PGL.COLOR_BUFFER_BIT);
      }
    
      sceneShape(canvas);
    }
    
    void sceneShape(PGraphics3D canvas) {
      if (shp_scene != null) {
        canvas.shape(shp_scene);
        return;
      }
    
      shp_scene = createShape(GROUP);
    
      int num_boxes = 50;
      int num_spheres = 50;
      float bb_size = 800;
      float xmin = -bb_size;
      float xmax = +bb_size;
      float ymin = -bb_size;
      float ymax = +bb_size;
      float zmin =  0;
      float zmax = +bb_size;
    
      colorMode(HSB, 360, 1, 1);
      randomSeed(0);
    
      for (int i = 0; i < num_boxes; i++) {
        float px = random(xmin, xmax);
        float py = random(ymin, ymax);
        float sx = random(200) + 10;
        float sy = random(200) + 10;
        float sz = random(zmin, zmax);
    
        float off = 45;
        float base = 0;
        float hsb_h = base + random(-off, off);
        float hsb_s = 1;
        float hsb_b = random(0.1, 1.0);
        int shading = color(hsb_h, hsb_s, hsb_b);
    
        PShape shp_box = createShape(BOX, sx, sy, sz);
        shp_box.setFill(true);
        shp_box.setStroke(false);
        shp_box.setFill(shading);
        shp_box.translate(px, py, sz*.5);
        shp_scene.addChild(shp_box);
      }
    
      DwCube cube_smooth = new DwCube(4);
      DwCube cube_facets = new DwCube(2);
    
      for (int i = 0; i < num_spheres; i++) {
        float px = random(xmin, xmax);
        float py = random(ymin, ymax);
        float pz = random(zmin, zmax);
        float rr = random(50) + 50;
        boolean facets = true;//(i%2 == 0);
    
        float off = 20;
        float base = 225;
        float hsb_h = base + random(-off, off);
        float hsb_s = 1;
        float hsb_b = random(0.1, 1.0);
        int shading = color(hsb_h, hsb_s, hsb_b);
    
        PShape shp_sphere = createShape(PShape.GEOMETRY);
        if (facets) {
          DwMeshUtils.createPolyhedronShape(shp_sphere, cube_facets, 1, 4, false);
        } else {
          DwMeshUtils.createPolyhedronShape(shp_sphere, cube_smooth, 1, 4, true);
        }
    
        shp_sphere.setStroke(!true);
        shp_sphere.setStroke(color(0));
        shp_sphere.setStrokeWeight(0.01 / rr);
        shp_sphere.setFill(true);
        shp_sphere.setFill(shading);
        shp_sphere.resetMatrix();
        shp_sphere.scale(rr);
        shp_sphere.translate(px, py, pz);
        shp_scene.addChild(shp_sphere);
      }
    
      colorMode(RGB, 255, 255, 255);
    
      PShape shp_rect = createShape(RECT, -1000, -1000, 2000, 2000);
      shp_rect.setStroke(false);
      shp_rect.setFill(true);
      shp_rect.setFill(color(255));
    
      shp_scene.addChild(shp_rect);
    }
    
    PShape createGridXY(int lines, float s) {
      PShape shp_gridxy = createShape();
      shp_gridxy.beginShape(LINES);
      shp_gridxy.stroke(0);
      shp_gridxy.strokeWeight(1);
      float d = lines*s;
    
      for (int i = 0; i <= lines; i++) {
        shp_gridxy.vertex(-d, -i*s, 0); 
        shp_gridxy.vertex(d, -i*s, 0);
        shp_gridxy.vertex(-d, +i*s, 0); 
        shp_gridxy.vertex(d, +i*s, 0);
    
        shp_gridxy.vertex(-i*s, -d, 0); 
        shp_gridxy.vertex(-i*s, d, 0);
        shp_gridxy.vertex(+i*s, -d, 0); 
        shp_gridxy.vertex(+i*s, d, 0);
      }
    
      shp_gridxy.endShape();
      return shp_gridxy;
    }
    
    void printCam() {
      float[] pos = peasycam.getPosition();
      float[] rot = peasycam.getRotations();
      float[] lat = peasycam.getLookAt();
      float   dis = (float) peasycam.getDistance();
    
      System.out.printf(ENGLISH, POSITION, pos[0], pos[1], pos[2]);
      System.out.printf(ENGLISH, ROTATION, rot[0], rot[1], rot[2]);
      System.out.printf(ENGLISH, LOOK_AT, lat[0], lat[1], lat[2]);
      System.out.printf(ENGLISH, DISTANCE, dis);
    }
    
  • Converting Java code to Python

    Thank you for pointing out this omission. Unfortunately, I'm still stuck on line 43:

    for some reason geombuffer.update(pg_render) prevents the sketch from running correctly. I suspect pg_render not to be correctly instantiated...

    add_library('PixelFlow')
    add_library('peasycam')
    from com.jogamp.opengl import GL2
    import java.util.Locale
    
    liste = []
    
    def setup():
        global geombuffer, context, scene_display, dof, magnifier, pg_render, pg_dof, pg_tmp
        size(800, 600, P3D)
        cam = PeasyCam(this, 1000)
        context = DwPixelFlow(this)
        scene_display = MySceneDisplay() 
        geombuffer = DwScreenSpaceGeometryBuffer(context, scene_display)
        dof = DepthOfField(context)
    
        mag_h = int(height/3)
        magnifier = DwMagnifier(this, 4, 0, height - mag_h, mag_h, mag_h)
    
        pg_render = DwUtils.changeTextureSize(this, None, width, height, 8, [False])
        pg_dof    = DwUtils.changeTextureSize(this, None, width, height, 0, [False])
        pg_tmp    = DwUtils.changeTextureSize(this, None, width, height, 0, [False], GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT)
    
        for e in range(100):
            liste.append(PVector(random(width), random(height), random(height)))
    
        cam.feed()
        perspective(60 * DEG_TO_RAD, width/float(height), 2, 6000)
    
        stroke(255)
        strokeWeight(10)
    
    
    def draw():
        background(0)
    
        displaySceneWrap(pg_render)
    
        geombuffer.update(pg_render)
    
    
    def displaySceneWrap(canvas):
        canvas.beginDraw()
        DwUtils.copyMatrices(this.g, canvas)
        canvas.blendMode(PConstants.BLEND)
        canvas.background(2)
        displayScene(canvas)
        canvas.endDraw()
    
    
    def displayScene(canvas):
        canvas.directionalLight(255, 255, 255, 200,600,400)
        canvas.directionalLight(255, 255, 255, -200,-600,-400)
        canvas.ambientLight(64, 64, 64)
    
        if canvas == geombuffer.pg_geom:
            canvas.background(255, 255)
            canvas.pgl.clearColor(1, 1, 1, 6000)
            canvas.pgl.clear(PGL.COLOR_BUFFER_BIT)
    
        sceneShape(canvas)
    
    
    def sceneShape(canvas):
        translate(-width/2, -height/2)
        for e in liste:
            point(e.x, e.y, e.z)
    
    
    class MySceneDisplay(DwSceneDisplay): 
        def display(_, canvas): displayScene(canvas)
    
  • Converting Java code to Python

    ... GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT don't seem to work.

    Have you imported the interface GL2 from package com.jogamp.opengl before using its constants? :-\"
    http://JogAmp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GL2.html

    import com.jogamp.opengl.GL2; --> from com.jogamp.opengl import GL2

    (because there's no such thing as PGraphics3D pg_render; in Python)

    PGraphics3D is the declared datatype which variable pg_render accepts to be assigned w/ under Java.

    Under Python however, variables hold any datatype reference. No restriction at all! 8->

    Under Java, all reference datatype fields are initialized w/ null by default. ~O)

    Under Python, simply assign them w/ None in order to have the same default behavior. :\">

    PGraphics3D pg_render; --> pg_render = None

    Take a look at the link below in order to learn the default initial value for each Java datatype: ~O)
    https://Docs.Oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

  • Render depth buffer onto 2d PGraphics

    Hi

    gl_FragCoord.z / gl_FragCoord.w

    would be nice if it would be that easy.

    this is serious math i save for a rainy, lonely sunday.

    https://www.opengl.org/discussion_boards/showthread.php/179953-(gl_FragCoord-z-gl_FragCoord-w)-for-quick-depth-calculation-camera-to-fragment

    https://stackoverflow.com/a/13731548

    Modern OpenGL has actualy build in functions like a precalculated Depth Texture, also gl_FragDepth will saves some headache. In native JOGL mode with modern Hardware, i can image, - it could be done. (Also thinking of times when people has to calculate Perspective-Correct Texture Mapping and such things ...)

    Reimplement the hole thing is paintful, but yes and some point, - and also in mind of backward compatibility, i think, people had to do it in in someway, unfortunately i can't find some good copy +paste examples.

    What you can do is experiment on the CPU and then paste your code to the shader GPU version.

    Don't forget to share your results : )

    Good Luck.

    // forum.processing.org/two/discussion/comment/122724
    // based on: 
    // Alasdair Turner 2009
    // openprocessing.org/sketch/2950#
    
    
    import com.jogamp.opengl.GL2ES2;
    import com.jogamp.opengl.util.GLBuffers;
    import java.nio.FloatBuffer;
    
    GL2ES2 gl;
    FloatBuffer zbuff;
    
    void setup() {
      size(640, 360, P3D);
      noStroke();
    
      zbuff = GLBuffers.newDirectFloatBuffer(new float[]{1f});
    }
    
    void draw() {
    
      float aspect = float(width)/float(height);
      float fovy =PI/3.; 
    
      float cameraZ =(height/2.0) / tan(degrees(fovy)*PI / 360.0);  
    
      float zNear =  cameraZ/10.0; 
      float zFar=cameraZ*10.0;
    
      // processings default ? 
      // processing.org/reference/camera_.html
      // processing.org/reference/perspective_.html
    
      // perspective(fovy, aspect, zNear, zFar);
      // camera(width/2, height/2, cameraZ, width/2, height/2, 0, 0, 1, 0);
    
      // printCamera();
    
      background(203);
      lights();
      pushMatrix();
    
      translate(width/2.0, height/2.0, -100. );
      fill(155);
      box(200, 100, 0.1 );
      fill(255);
      sphere(50);
      popMatrix();
    
      gl = ((PJOGL) beginPGL()).gl.getGL2ES2();
      endPGL();
      // not optimatl but enough for your porposes 
      // khronos.org/opengl/wiki/Common_Mistakes#Depth_Buffer_Precision
      // note in case you want multiple objects: detph texture is native opengl means it's flipped on the y axis in jogl
      gl.glReadPixels( mouseX, mouseY, 1, 1, GL2ES2.GL_DEPTH_COMPONENT, GL2ES2.GL_FLOAT, zbuff);
    
      float z = 2.0 * ( zbuff.get(0) - 0.5f);
      float worldZ =  2.0f*zFar * zNear / (z*(zFar-zNear)-(zFar+zNear) );
    
      fill(0, 102, 153, 250);
      textSize(24);
      text(nf(cameraZ+worldZ, 0, 1), mouseX, mouseY);
    }
    
  • P2D/P3D issues on ODROID-XU4

    Hi @gohai,

    I'm sorry for my late response. I had a day off yesterday :)

    Here's the output of a108bd998432b7b544ce0e1d0ad73376.

    GLDebugEvent[ id 0x32
        type Error
        severity High: dangerous undefined behavior
        source GL API
        msg Error:glEnable::<cap> is not one of the accepted values
        when 1524184964512
        source 3.1 (ES profile, arb, debug, compat[ES2, ES3, ES31], FBO, hardware) - OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e - hash 0x1f928e9]
        [2]: jogamp.opengl.GLDebugMessageHandler$StdErrGLDebugListener.messageSent(GLDebugMessageHandler.java:347)
        [3]: jogamp.opengl.GLDebugMessageHandler.sendMessage(GLDebugMessageHandler.java:332)
        [4]: jogamp.opengl.GLDebugMessageHandler.glDebugMessageARB(GLDebugMessageHandler.java:358)
        [5]: jogamp.opengl.es3.GLES3Impl.dispatch_glEnable1(Native Method)
        [6]: jogamp.opengl.es3.GLES3Impl.glEnable(GLES3Impl.java:734)
        [7]: com.jogamp.opengl.DebugGLES3.glEnable(DebugGLES3.java:2121)
        [8]: processing.opengl.PJOGL.enable(PJOGL.java:1068)
        [9]: processing.opengl.PGraphicsOpenGL.setGLSettings(PGraphicsOpenGL.java:6784)
        [10]: processing.opengl.PGraphicsOpenGL.checkSettings(PGraphicsOpenGL.java:6740)
        [11]: processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1463)
        [12]: processing.core.PApplet.handleDraw(PApplet.java:2388)
        [13]: processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        [14]: jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        [15]: jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        [16]: jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        [17]: jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        [18]: jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        [19]: com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        [20]: com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        [21]: com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        [22]: com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        [23]: java.util.TimerThread.mainLoop(Timer.java:555)
        [24]: java.util.TimerThread.run(Timer.java:505)
    com.jogamp.opengl.GLException: Thread[main-FPSAWTAnimator#00-Timer0,5,main] glGetError() returned the following error codes after a call to glEnable(<int> 0x809D): GL_INVALID_ENUM ( 1280 0x500), 
        at com.jogamp.opengl.DebugGLES3.writeGLError(DebugGLES3.java:8241)
        at com.jogamp.opengl.DebugGLES3.glEnable(DebugGLES3.java:2124)
        at processing.opengl.PJOGL.enable(PJOGL.java:1068)
        at processing.opengl.PGraphicsOpenGL.setGLSettings(PGraphicsOpenGL.java:6784)
        at processing.opengl.PGraphicsOpenGL.checkSettings(PGraphicsOpenGL.java:6740)
        at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1463)
        at processing.core.PApplet.handleDraw(PApplet.java:2388)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    
  • P2D/P3D issues on ODROID-XU4

    @gohai, as you instructed, I modified ~/.processing/preferences.txt and ran the following simple sketch.

    void setup() {
      size(300, 300, P3D);
    }
    
    void draw() {
      background(0);
    }
    

    And I got the following console output:

    GLDebugEvent[ id 0xb
        type Error
        severity High: dangerous undefined behavior
        source GL API
        msg Error:glGetFloatv::<pname> is not an accepted value
        when 1524036153380
        source 3.1 (ES profile, arb, debug, compat[ES2, ES3, ES31], FBO, hardware) - OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e - hash 0xc39cf5]
        [2]: jogamp.opengl.GLDebugMessageHandler$StdErrGLDebugListener.messageSent(GLDebugMessageHandler.java:347)
        [3]: jogamp.opengl.GLDebugMessageHandler.sendMessage(GLDebugMessageHandler.java:332)
        [4]: jogamp.opengl.GLDebugMessageHandler.glDebugMessageARB(GLDebugMessageHandler.java:358)
        [5]: jogamp.opengl.es3.GLES3Impl.dispatch_glGetFloatv1(Native Method)
        [6]: jogamp.opengl.es3.GLES3Impl.glGetFloatv(GLES3Impl.java:1157)
        [7]: com.jogamp.opengl.DebugGLES3.glGetFloatv(DebugGLES3.java:3260)
        [8]: processing.opengl.PJOGL.getFloatv(PJOGL.java:1106)
        [9]: processing.opengl.PGraphicsOpenGL.getGLParameters(PGraphicsOpenGL.java:6892)
        [10]: processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1454)
        [11]: processing.core.PApplet.handleDraw(PApplet.java:2388)
        [12]: processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        [13]: jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        [14]: jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        [15]: jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        [16]: jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        [17]: jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        [18]: com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        [19]: com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        [20]: com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        [21]: com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        [22]: java.util.TimerThread.mainLoop(Timer.java:555)
        [23]: java.util.TimerThread.run(Timer.java:505)
    

    Can you point out what causes the error from this clue?

  • P2D/P3D issues on ODROID-XU4

    @gohai, it doesn't seem to work unfortunately :( Please take a look at the output.

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    java.lang.RuntimeException: Cannot compile fragment shader:
    0:28: S0028: Expected type for precision qualifier, got 'vec2'
    0:29: S0028: Expected type for precision qualifier, got 'vec3'
    0:30: S0028: Expected type for precision qualifier, got 'vec4'
        at processing.core.PGraphics.showException(PGraphics.java:8211)
        at processing.opengl.PShader.compileFragmentShader(PShader.java:1000)
        at processing.opengl.PShader.compile(PShader.java:924)
        at processing.opengl.PShader.init(PShader.java:894)
        at processing.opengl.PShader.getAttributeLoc(PShader.java:595)
        at processing.opengl.PShader.loadAttributes(PShader.java:1123)
        at processing.opengl.PGraphicsOpenGL.getPolyShader(PGraphicsOpenGL.java:7082)
        at processing.opengl.PGraphicsOpenGL.flushPolys(PGraphicsOpenGL.java:2377)
        at processing.opengl.PGraphicsOpenGL.flush(PGraphicsOpenGL.java:2314)
        at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1480)
        at processing.core.PApplet.handleDraw(PApplet.java:2444)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    
  • P2D/P3D issues on ODROID-XU4

    Hi @gohai,

    I DO have time to do more tests and I love to see Processing becoming better and better :) So, please let me know anytime if there's something I can test more.

    Here's the output from testing core.jar with MD5 of 5601a9174287d2b83c6979bd23164a7d.

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    ARM
    Mali-T628
    OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e
    OpenGL ES GLSL ES 3.10
    GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth24 GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_EXT_read_format_bgra GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_required_internalformat GL_OES_vertex_array_object GL_OES_mapbuffer GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_type_2_10_10_10_REV GL_OES_fbo_render_mipmap GL_OES_element_index_uint GL_EXT_shadow_samplers GL_OES_texture_compression_astc GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_sliced_3d GL_KHR_debug GL_EXT_occlusion_query_boolean GL_EXT_disjoint_timer_query GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_OES_get_program_binary GL_OES_texture_3D GL_EXT_texture_storage GL_EXT_multisampled_render_to_texture GL_OES_surfaceless_context GL_OES_texture_stencil8 GL_EXT_shader_pixel_local_storage GL_ARM_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_ARM_mali_program_binary GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_RG8 GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OES_texture_storage_multisample_2d_array GL_OES_shader_image_atomic GL_EXT_robustness GL_EXT_texture_border_clamp GL_OES_texture_border_clamp GL_EXT_texture_cube_map_array GL_OES_texture_cube_map_array GL_OES_sample_variables GL_OES_sample_shading GL_OES_shader_multisample_interpolation GL_EXT_shader_io_blocks GL_OES_shader_io_blocks GL_EXT_gpu_shader5 GL_OES_gpu_shader5 GL_EXT_texture_buffer GL_OES_texture_buffer GL_EXT_copy_image GL_OES_copy_image
    java.lang.RuntimeException: GL function glBlitFramebuffer() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.
        at processing.opengl.PJOGL.blitFramebuffer(PJOGL.java:1939)
        at processing.opengl.PGL.syncBackTexture(PGL.java:595)
        at processing.opengl.PGL.endRender(PGL.java:769)
        at processing.opengl.PGraphicsOpenGL.endOnscreenDraw(PGraphicsOpenGL.java:6598)
        at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1483)
        at processing.core.PApplet.handleDraw(PApplet.java:2444)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    

    Many thanks,
    Scott

  • P2D/P3D issues on ODROID-XU4

    Hi @gohai,

    I just downloaded core.jar again and found that its MD5 checksum is identical (081feb5fff944b9a84640234cd79c70f).

    I ran the test script (i.e., modes/java/examples/Demos/Tests/SpecsTest/SpecsTest.pde) and got the following output:

    ARM
    Mali-T628
    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e
    OpenGL ES GLSL ES 3.10
    GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth24 GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_EXT_read_format_bgra GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_required_internalformat GL_OES_vertex_array_object GL_OES_mapbuffer GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_type_2_10_10_10_REV GL_OES_fbo_render_mipmap GL_OES_element_index_uint GL_EXT_shadow_samplers GL_OES_texture_compression_astc GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_sliced_3d GL_KHR_debug GL_EXT_occlusion_query_boolean GL_EXT_disjoint_timer_query GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_OES_get_program_binary GL_OES_texture_3D GL_EXT_texture_storage GL_EXT_multisampled_render_to_texture GL_OES_surfaceless_context GL_OES_texture_stencil8 GL_EXT_shader_pixel_local_storage GL_ARM_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_ARM_mali_program_binary GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_RG8 GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OES_texture_storage_multisample_2d_array GL_OES_shader_image_atomic GL_EXT_robustness GL_EXT_texture_border_clamp GL_OES_texture_border_clamp GL_EXT_texture_cube_map_array GL_OES_texture_cube_map_array GL_OES_sample_variables GL_OES_sample_shading GL_OES_shader_multisample_interpolation GL_EXT_shader_io_blocks GL_OES_shader_io_blocks GL_EXT_gpu_shader5 GL_OES_gpu_shader5 GL_EXT_texture_buffer GL_OES_texture_buffer GL_EXT_copy_image GL_OES_copy_image
    numSamples is: 1
    java.lang.RuntimeException: GL function glReadBuffer() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.
        at processing.opengl.PJOGL.readBuffer(PJOGL.java:1954)
        at processing.opengl.PJOGL.initFBOLayerES(PJOGL.java:310)
        at processing.opengl.PJOGL.initFBOLayer(PJOGL.java:301)
        at processing.opengl.PGL.createFBOLayer(PGL.java:988)
        at processing.opengl.PGL.beginRender(PGL.java:727)
        at processing.opengl.PGraphicsOpenGL.beginOnscreenDraw(PGraphicsOpenGL.java:6576)
        at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1459)
        at processing.core.PApplet.handleDraw(PApplet.java:2388)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    

    Please verify this for me.

    Thanks,
    Scott

  • P2D/P3D issues on ODROID-XU4

    Hi @gohai,

    As you instructed, I replaced /core/library/core.jar with the file you uploaded.

    I ran the modes/java/examples/Demos/Tests/SpecsTest/SpecsTest.pde and I got the following output which looks quite similar to the old output.

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    ARM
    Mali-T628
    OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e
    OpenGL ES GLSL ES 3.10
    GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth24 GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_EXT_read_format_bgra GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_required_internalformat GL_OES_vertex_array_object GL_OES_mapbuffer GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_type_2_10_10_10_REV GL_OES_fbo_render_mipmap GL_OES_element_index_uint GL_EXT_shadow_samplers GL_OES_texture_compression_astc GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_sliced_3d GL_KHR_debug GL_EXT_occlusion_query_boolean GL_EXT_disjoint_timer_query GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_OES_get_program_binary GL_OES_texture_3D GL_EXT_texture_storage GL_EXT_multisampled_render_to_texture GL_OES_surfaceless_context GL_OES_texture_stencil8 GL_EXT_shader_pixel_local_storage GL_ARM_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_ARM_mali_program_binary GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_RG8 GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OES_texture_storage_multisample_2d_array GL_OES_shader_image_atomic GL_EXT_robustness GL_EXT_texture_border_clamp GL_OES_texture_border_clamp GL_EXT_texture_cube_map_array GL_OES_texture_cube_map_array GL_OES_sample_variables GL_OES_sample_shading GL_OES_shader_multisample_interpolation GL_EXT_shader_io_blocks GL_OES_shader_io_blocks GL_EXT_gpu_shader5 GL_OES_gpu_shader5 GL_EXT_texture_buffer GL_OES_texture_buffer GL_EXT_copy_image GL_OES_copy_image
    java.lang.RuntimeException: GL function glRenderbufferStorageMultisample() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.
        at processing.opengl.PJOGL.renderbufferStorageMultisample(PJOGL.java:1941)
        at processing.opengl.PGL.createFBOLayer(PGL.java:955)
        at processing.opengl.PGL.beginRender(PGL.java:727)
        at processing.opengl.PGraphicsOpenGL.beginOnscreenDraw(PGraphicsOpenGL.java:6576)
        at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1459)
        at processing.core.PApplet.handleDraw(PApplet.java:2388)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    

    However, I got something different for the following original code.

    void setup() {
      size(300, 300);
    }
    
    void draw() {
      background(0);
    }
    

    The output is just:

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    

    without the error that I used to have :) Is this a right sign for me to go with P3D on ODROID-XU4?

    Many thanks,
    Scott

  • P2D/P3D issues on ODROID-XU4

    Hi @gohai,

    Sorry for my belated response. Here is the output I got from Demos/Tests/SpecsTest.pde as it is.

    Many thanks!

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    ARM
    Mali-T628
    OpenGL ES 3.1 v1.r17p0-01rel0.a881d28363cdb20f0017ed13c980967e
    OpenGL ES GLSL ES 3.10
    GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth24 GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_EXT_read_format_bgra GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_required_internalformat GL_OES_vertex_array_object GL_OES_mapbuffer GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_type_2_10_10_10_REV GL_OES_fbo_render_mipmap GL_OES_element_index_uint GL_EXT_shadow_samplers GL_OES_texture_compression_astc GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_sliced_3d GL_KHR_debug GL_EXT_occlusion_query_boolean GL_EXT_disjoint_timer_query GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_OES_get_program_binary GL_OES_texture_3D GL_EXT_texture_storage GL_EXT_multisampled_render_to_texture GL_OES_surfaceless_context GL_OES_texture_stencil8 GL_EXT_shader_pixel_local_storage GL_ARM_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_ARM_mali_program_binary GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_RG8 GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OES_texture_storage_multisample_2d_array GL_OES_shader_image_atomic GL_EXT_robustness GL_EXT_texture_border_clamp GL_OES_texture_border_clamp GL_EXT_texture_cube_map_array GL_OES_texture_cube_map_array GL_OES_sample_variables GL_OES_sample_shading GL_OES_shader_multisample_interpolation GL_EXT_shader_io_blocks GL_OES_shader_io_blocks GL_EXT_gpu_shader5 GL_OES_gpu_shader5 GL_EXT_texture_buffer GL_OES_texture_buffer GL_EXT_copy_image GL_OES_copy_image
    java.lang.RuntimeException: GL function glRenderbufferStorageMultisample() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.
        at processing.opengl.PJOGL.renderbufferStorageMultisample(PJOGL.java:1941)
        at processing.opengl.PGL.createFBOLayer(PGL.java:955)
        at processing.opengl.PGL.beginRender(PGL.java:727)
        at processing.opengl.PGraphicsOpenGL.beginOnscreenDraw(PGraphicsOpenGL.java:6577)
        at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1459)
        at processing.core.PApplet.handleDraw(PApplet.java:2388)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    
  • P2D/P3D issues on ODROID-XU4

    I'm trying to use Processing (3.3.7 ARMv6hf) on ODROID-XU4 on which Oracle JDK 8u162 32-bit ARM version is installed. The X11 configuration file (/etc/X11/xorg.conf) has been modified with the following lines appended to use OpenGL ES instead of OpenGL.

    Section "Module"
        Disable "glx"
    EndSection
    

    For a simple test, I made the following sketch which is running without any problems of course.

    void setup() {
      size(300, 300);
    }
    
    void draw() {
      background(0);
    }
    

    However, if I make a change in size(300, 300) like the following,

    size(300, 300, P3D);
    

    I get the following error messages.

    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    java.lang.RuntimeException: GL function glRenderbufferStorageMultisample() is not available on this hardware (or driver) Read http://wiki.processing.org/w/OpenGL_Issues for help.
        at processing.opengl.PJOGL.renderbufferStorageMultisample(PJOGL.java:1941)
        at processing.opengl.PGL.createFBOLayer(PGL.java:955)
        at processing.opengl.PGL.beginRender(PGL.java:727)
        at processing.opengl.PGraphicsOpenGL.beginOnscreenDraw(PGraphicsOpenGL.java:6577)
        at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1459)
        at processing.core.PApplet.handleDraw(PApplet.java:2388)
        at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)
    

    Would someone please help me resolve this problem?

    Many thanks,
    Scott

  • Draw points from texture stored locations?
    import com.jogamp.opengl.*;
    import  com.jogamp.opengl.GL4;
    import com.jogamp.opengl.util.GLBuffers;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    
    IntBuffer Tex;
    FloatBuffer mBuf;
    
    PJOGL pgl;
    GL4 gl4 ;
    
    final int twidth = 1;
    
    PShader shdr;
    
    void settings() {
      size(640, 360, P3D );
      PJOGL.profile = 4;
    }
    
    void setup() {
    
      /* //fragment.glsl
      #version 430
      layout(binding = 0) uniform sampler1D tex;
      layout(location = 0) uniform vec3 iResolution;
      layout(location = 0) out vec4 fragColor;
      void main() {
      vec2 uvv = (gl_FragCoord.xy*2.-iResolution.xy)/iResolution.z;
      float arr = texelFetch( tex ,0,0) .r;
      float cir=arr/length(uvv);
      fragColor = vec4(vec3(cir),1.);
      }
      */
    
      /* //vertex.glsl
      #version 430
      in vec2 position;
      void main(){
      gl_Position = vec4(position.xy,0.,1.);
      }
      */
    
      shdr = loadShader("fragment.glsl", "vertex.glsl");
    
    
    
      shader(shdr);
      shdr.set("iResolution", new PVector(width, height, Math.min(width, height)));
    
      Tex = GLBuffers.newDirectIntBuffer(1);
    
      pgl = (PJOGL) beginPGL();  
      gl4 = pgl.gl.getGL4();
    
      gl4.glGenTextures(1, Tex);
    
      gl4.glBindTexture(GL4.GL_TEXTURE_1D, Tex.get(0));
    
      mBuf = GLBuffers.newDirectFloatBuffer(twidth);
    
      shdr.bind();
      gl4.glTexImage1D( GL4.GL_TEXTURE_1D, 0, GL4.GL_R32F, twidth, 0, GL4.GL_RED, GL4.GL_FLOAT, mBuf );
      shdr.unbind();
      endPGL();
    }
    
    void draw() {
      pgl = (PJOGL) beginPGL(); 
    
      float arr = 1./random(2, 24);
    
      gl4 = pgl.gl.getGL4();
      shdr.bind();
      if (frameCount%12==0) mBuf.put( arr ).rewind();
      println(arr);
    
      gl4.glTexSubImage1D( GL4.GL_TEXTURE_1D, 0, 0, twidth, GL4.GL_RED, GL4.GL_FLOAT, mBuf );
      shdr.unbind();
      endPGL();
      rect(0, 0, width, height);
    }
    
  • Java script error Processing/Kinect + Isadora

    The error is long but this is what is at the top java.lang.noSuchMethodError:processing.core.PApplet.registerDispose(Ljava/lang/Object;)V

    at com.jogamp.newt.opengl.GLWindow.display(GLWindow, java:759) at com.jogamp.opengl.until.AWTAnimatorImpl.display(AWTAnimatorImpl.java.81) at com.jogamp.opengl.until. Animatorbase.display(AnimatorBase.java:452) at com.jogamp.opengl.until FPSAnimator$Maintask.rung(FPSAnimator.java:178) at java.until.TimerThred.mainLoop (Timer.java:555) at java.until.TimerThred.run (Timer.java:505)

    The Isadora forum has not commented yet but the link is here:https://community.troikatronix.com/topic/5106/processing-error-with-kinect-isadora

  • glScissor

    I want to use glScissor, which works fine. But how can I end glScissor? If i use gl.glDisable(GL.GL_SCISSOR_TEST); then the scissor gets disabled for the whole draw frame.

    import processing.opengl.*;
    import com.jogamp.opengl.*; 
    
    GL gl;
    
    void setup() {
      size(500, 500, P2D);
    }
    
    
    void draw() {
      background(255);
    
      if (gl == null) {
        gl = ((PJOGL)beginPGL()).gl.getGL();
      }  
    
      gl.glEnable(GL.GL_SCISSOR_TEST);
      gl.glScissor(mouseX-50, height-mouseY-50, 100, 100);
    
      stroke(255, 0, 0);
      for (int i = -width; i < width; i += 5) {
        line(i*5, 0, width + i*5, height);  
      }
    
      // how to draw what we currently have?
      //gl.glDisable(GL.GL_SCISSOR_TEST);
      fill(255,0,0);
      rect(0, height/2, width, 10); 
    
    
    }