Contour fills as rectangle when drawing to render target

Hi! I think there’s something I’m missing about render targets.
I have simplified my problem to the following example where I try to draw a triangle:

In this first program without using render target a triangle is drawn as expected:

fun main() = application {
    configure {
        width = 800
        height = 800
        windowResizable = true
    }
    program {
        extend {
            val c = contour {
                moveTo(Vector2(width / 2.0 - 120.0, height / 2.0 - 120.00))
                lineTo(cursor + Vector2(240.0, 0.0))
                lineTo(cursor + Vector2(0.0, 240.0))
                lineTo(anchor)
                close()
            }
            drawer.clear(ColorRGBa.BLACK)
            drawer.fill = ColorRGBa.PINK
            drawer.strokeWeight = 4.0
            drawer.stroke = ColorRGBa.WHITE
            drawer.contour(c)
        }
    }
}

Now I modify the program to draw to a render target and then draw that to the screen as an image and in this case the result is a pink filled rectangle (the stroke is correctly drawn as a triangle):

fun main() = application {
    configure {
        width = 800
        height = 800
        windowResizable = true
    }
    program {
        val rt = renderTarget(width, height) {
            colorBuffer()
            depthBuffer()
        }

        extend {
            val c = contour {
                moveTo(Vector2(width / 2.0 - 120.0, height / 2.0 - 120.00))
                lineTo(cursor + Vector2(240.0, 0.0))
                lineTo(cursor + Vector2(0.0, 240.0))
                lineTo(anchor)
                close()
            }
            drawer.isolatedWithTarget(rt) {
                clear(ColorRGBa.BLACK)
                fill = ColorRGBa.PINK
                strokeWeight = 4.0
                stroke = ColorRGBa.WHITE
                contour(c)
            }

            drawer.image(rt.colorBuffer(0))
        }
    }
}

I believe I am using the latest openrndr-template.

This happens with any contour I draw, not just triangles. Could someone help me understand what is happening and how I could fix it? Thanks!!

I tried your render target version on openrndr/orx 0.4.4 and a development build from a couple of weeks back, and your example works fine for me on Linux

Oh thanks! Forgot to say I’m on macOS on an M2 MacBook. Will try on linux!

Same for me: works fine. I wonder if it’s something related to the depth buffer.

Ah good point about the M2. I’ll mention this in Slack, maybe it’s related to the platform used.

Could you pls try the next-version branch of openrndr-template ? Maybe that fixes it.

That branch will be updated in the coming days to use 0.4.5-alpha6 instead of 0.4.5-alpha5, which may bring further improvements. AFAIK @edwin has been working a lot recently on making things very smooth on Mac computers, including compute shader support :slight_smile:

Works fine on the next-version branch! Thank you so much :slight_smile:

1 Like