Rectangles are drawn with fill and outline in different places and with different sizes.

edited February 2016 in How To...

I an encountering a problem where rectangles have their borders drawn in a different place from the fill. They where being drawn perfectly fine, but then I turned on depth-testing and depth sorting, and I could not see the borders. I turned off dept testing and sorting, but this did not fix the problem. I then found that the borders are being drawn in a different place and are about 5x larger, and can only be seen when the screen is enlarged. I have no idea what is causing this problem, and any help is greatly appreciated. Here are some pictures, these were both taken from the same sketch, with the second one have been taken after the screen was enlarged.

Screenshot 2016-01-29 at 2.42.08 PM Screenshot 2016-01-29 at 2.41.59 PM

The large rectangles in the middle of the screen are the borders of the ones seen in the top left.

Answers

  • This applies to all shapes, not just rectangles. I am getting a bunch of errors that started after I started using a thread to create a loading bar. Here are a few of the Errors (to get it to work, I put try/catch around all the places I was getting errors, so this is just the raw error text). OpenGL error 1281 at bot beginDraw(): invalid valueOpenGL error 1281 at bot beginDraw(): invalid value

    java.lang.NullPointerException at jogamp.opengl.glu.tessellator.Mesh.__gl_meshMakeEdge(Mesh.java:274) at jogamp.opengl.glu.tessellator.Sweep.AddSentinel(Sweep.java:1126) at jogamp.opengl.glu.tessellator.Sweep.InitEdgeDict(Sweep.java:1160) at jogamp.opengl.glu.tessellator.Sweep.__gl_computeInterior(Sweep.java:1314) at jogamp.opengl.glu.tessellator.GLUtessellatorImpl.gluTessEndPolygon(GLUtessellatorImpl.java:526) at com.jogamp.opengl.glu.GLU.gluTessEndPolygon(GLU.java:896) at processing.opengl.PJOGL$Tessellator.endPolygon(PJOGL.java:601) at processing.opengl.PGraphicsOpenGL$Tessellator.tessellatePolygon(PGraphicsOpenGL.java:12521) at processing.opengl.PGraphicsOpenGL.tessellate(PGraphicsOpenGL.java:2273) at processing.opengl.PGraphicsOpenGL.endShape(PGraphicsOpenGL.java:1986) at processing.core.PGraphics.endShape(PGraphics.java:1701) at processing.opengl.PGraphicsOpenGL.quad(PGraphicsOpenGL.java:3126) at processing.core.PGraphics.rectImpl(PGraphics.java:2616) at processing.core.PGraphics.rect(PGraphics.java:2611) at processing.core.PApplet.rect(PApplet.java:11486) at Game.draw(Game.java:1033) at processing.core.PApplet.handleDraw(PApplet.java:2399) at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:731) 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) Tessellation Error: out of memory

    java.lang.RuntimeException: Too many calls to popMatrix(), and not enough to pushMatrix().

    Tessellation Error: gluTessBeginPolygon() must precede a gluTessEndPolygon Tessellation Error: gluTessBeginContour() must precede a gluTessEndContour() Tessellation Error: gluTessEndPolygon() must follow a gluTessBeginPolygon()

  • I think I fixed this by making sure that the thread couldn't call drawing commands, though I am still getting weird errors, specifically ArrayIndexOuOfBoundExceptions on things like rect(width/2, height/2, barLength, barHeight);

  • What OS are you using? OpenGL version? Processing version? Are you on a laptop? A bit more information if you would please.

  • Mac OSX 10.10.2, macbook pro late 2013, 13 in retina display. Processing 3.0.1? Not sure about OpenGL. I think the problem was the thread shuffling the draw commands. That doesn't explain why it only started after turning the hints on, and I am still get weir ArrayIndexOutOfBounds exceptions, but that seems to have fixed it, mostly.

  • And the problem still occasionally happens

  • Ah, I couldn't be of much help anyway, no Mac. :(

  • java.lang.RuntimeException: Too many calls to popMatrix(), and not enough to pushMatrix().

    I think this is the important bit of that stack trace and the only bit you can do anything about. Check your code.

  • I think somehow the thread is calling popMatrix and pushMatrix, messing stuff up because it doesn't occur in order. What is strange is that I can't find a place the thread would call this, and it does not occur at the same time.

  • edited February 2016

    either search pushMatrix and popMatrix in your code and check whether they match (they must come in pairs, so they must be the same in number etc.)

    OR post your code

  • edited February 2016

    All of my pushMatrix and popMatrix calls match. The problem seems to be that my thread is calling pushMatrix and popMatrix, so something like this is happening:

    draw(): pushMatrix

    draw(): pushMatrix

    thread: pushMatrix

    draw(): popMatrix

    thread: popMatrix

    draw(): popMatrix

    Each one is matched, but the thread is de-synced. I just cant find where in the thread this is happening. Also, my code is 3.5k lines long, and this problem involves about 500 lines of that at least. I think I can fix this now, but if anyone has any idea on something hidden that could be causing this, your help is much appreciated.

  • It also seems to cause a lot of AssertionErrors, I think this is caused by something similar.

  • Swap 4 and 5 above

    I mean that would be the Order as it should be

  • Must be symmetrical

  • The point is that I can't control whether the thread or draw comes first, they are de-synchronized. That order is just an example of how the thread and draw are meshing together. I know why that is happening. This is pretty much answered now.

  • don't draw anything in the thread, if possible. use the thread to set a flag and act on that flag in the draw loop.

  • Thats what I am doing. I just can't find if there is anything being drawn in the thread. Is there a way to reset the drawing after the thread finishes.

  • We can't draw directly to canvas outside sketch's "Animation Thread".
    However, we can draw via some PGraphics object.
    Then just use image() on them inside draw().

  • I do not need to draw in the thread, however, since the thread calls hundreds of lines of code, it is not easy to find where the drawing calls actually are, and things other than drawing calls can behave in the same way as pushMatrix and popMatrix, i.e. using pushes/pops (in general).

  • edited February 2016

    ... it is not easy to find where the drawing calls actually are, ...

    In a method being run by a Thread, every call from it is also run by that same Thread.
    If it's not the "Animation Thread", we can't call another method which draws to canvas from there.

  • I can also confirm that when the remaining glitch is NOT caused by an exception that is in a try/catch. Whatever it is, I know that is not actually causing a caught exception.

  • Actually, you can call drawing calls. It just messes everything up. I finally found the problem, it was a drawing call caused by the creation of an object.

Sign In or Register to comment.