[SOLVED] Is stroke applied after fill?

edited June 2015 in Questions about Code


I'm creating a simple breakout game where in when a block is hit it moves out of the screen at a certain pace, and then disappears. I would like said block to be drawn on top of any block that is still stationary. It works only partially. For some reason the fill of the moving block is drawn on top of the fill of the stationary block, but the stroke of the stationary block shows through the moving block. Image here:

The moving blocks are drawn after the stationary blocks. The code for drawing a block looks like this:

    @ Override
    public void draw() {
        if (doomed) {
            x += velocity * cos(angle);
            y += velocity * sin(angle);
        if (x < 0 || x > width || y < 0 || y > height) {
            dead = true;
        } else {
            fill(red, green, blue);
            rect(x, y, w, h);
            fill(red + lowerColor, green + lowerColor, blue + lowerColor);
            triangle(x, y + blockHeight, x + blockWidth, y + blockHeight, x + blockWidth, y);
            fill(red + upperColor, green + upperColor, blue + upperColor);
            rect(x + bevel * cos(bevelAngle), y + bevel * sin(bevelAngle), blockWidth - 2 * bevel * cos(bevelAngle), blockHeight - 2 * bevel * sin(bevelAngle));

The main draw loop called by processing looks like this, where blockArray contain all the stationary blocks, and doomedBlockArray contains all the moving blocks:

@ Override
public void draw() {
    if (firstRun && frame != null) {                    // Lock frame size
        firstRun = false;

    background(230);                                    // Clear frame

    if (blockArray.size() == 0) {

    blockIterator = blockArray.iterator();              // Draw stationary blocks
    while (blockIterator.hasNext()) {

    doomedBlockIterator = blockArrayOfDoom.iterator();  // Draw moving blocks
    while (doomedBlockIterator.hasNext()) {
        block = doomedBlockIterator.next();
        if (block.isDead()) {
            doomedBlockIterator.remove();               // Remove if block is outside screen
        } else {

    drawableIterator = drawablesArray.iterator();       // Draw anything else
    while (drawableIterator.hasNext()) {

As you can see, the "doomed" blocks are drawn after the regular blocks, and yet the stroke from the regular blocks overlap the doomed blocks. Is this normal, can it be avoided?

Any help much appreciated!


Solved after changing from P3D to P2D renderer!


  • can you write a simple sketch that shows the problem, something that we can run and modify without having to guess at the code you don't supply?

    just something that draws two blocks should do.

  • edited June 2015 Answer ✓

    Are you using P3D or OPENGL renderer? If you are then change it to P2D. Note that P2D uses OpenGL.

    More info about this can be found in this discussion.

  • Are you using P3D or OPENGL renderer?

    Just to clarify things better, since Processing 2, P3D & OPENGL constants refer to the same renderer.

  • Yes, indeed, changing to P2D fixed it. Thank you!

Sign In or Register to comment.