Hello @Simeon. Does the following code reveal a bug in beta 1.5(14), or is it my code that is buggy?
The mesh renders for a few seconds, then disappears for a short while, then reappears briefly, to disappear for good.
Lua:
--
-- Arc
--
supportedOrientations(LANDSCAPE_ANY)
function setup()
parameter.number("width", 1, 100, 40)
parameter.number("radius", 50, WIDTH / 2, 200)
parameter.number("startAngle", -180, 180, -130)
parameter.number("endAngle", -180, 180, 130)
stroke(118, 223, 25)
end
function draw()
background(64)
strokeWidth(width)
arc(WIDTH / 2, HEIGHT / 2, radius, startAngle, endAngle)
end
function arc(x, y, radius, a1, a2)
local m = mesh()
m:addRect(x, y, radius * 2, radius * 2)
m.shader = shader("Documents:Arc")
m.shader.size = (1 - strokeWidth()/radius) * 0.5
m.shader.color = color(stroke())
m.shader.a1 = math.rad(a1)
m.shader.a2 = math.rad(a2)
m:draw()
end
Vertex shader:
//
// Vertex shader: Arc
//
uniform mat4 modelViewProjection;
attribute vec4 position;
attribute vec2 texCoord;
varying highp vec2 vTexCoord;
void main() {
vTexCoord = texCoord;
gl_Position = modelViewProjection * position;
}
Fragment shader:
//
// Fragment shader: Arc
//
precision highp float;
uniform float size;
uniform float a1;
uniform float a2;
uniform vec4 color;
varying vec2 vTexCoord;
void main() {
vec4 col = vec4(0.0);
vec2 r = vTexCoord - vec2(0.5);
float d = length(r);
if (d > size && d < 0.5) {
float a = atan(r.y, r.x);
if (a2 > a1) {
if (a > a1 && a < a2) {
col = color;
}
} else {
if (a > a1 || a < a2) {
col = color;
}
}
}
gl_FragColor = col;
}