attractplus
attractplus copied to clipboard
Missing image breaks vertex shaders
When an image fails to load (ie: no file) all subsequent object vertices change order. This makes it impossible to use vertex shaders that rely on vertex order.
Normal: [tl, bl, tr, br] Broken: [br, tl, bl, tr]
- Run example to see the expected behavior (a red square rotated left)
- Un-comment
bad_img
to see the vertices change order - Leaving
bad_img
visible, un-comment afix
to see its results
Successfully adding another object appears to fix the broken ordering. It seems something isn't getting cleaned up after a failed load.
layout.nut
// local bad_img = fe.add_image("bad_name.png");
// local fix1 = fe.add_artwork("snap", 0, 0, 50, 50);
// local fix2 = fe.add_text("Maybe", 0, 0, 400, 50); // AM, not AM+
// local fix3 = fe.add_text("LongerText", 0, 0, 400, 50);
local img = fe.add_artwork("snap", 50, 50, 400, 400);
img.shader = fe.add_shader(Shader.VertexAndFragment, "shader.vert", "shader.frag");
shader.frag
#version 120
uniform sampler2D texture;
void main() {
gl_FragColor = gl_Color * vec4(1,0,0,1);
}
shader.vert
#version 120
#extension GL_EXT_gpu_shader4 : require
void main() {
vec2[4] offset = vec2[](vec2(0,50), vec2(50,0), vec2(-50,0), vec2(0,-50));
gl_Position = gl_ModelViewProjectionMatrix * (gl_Vertex + vec4(offset[gl_VertexID % 4], 0.0, 0.0));
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}
Attract-Mode Plus v3.0.8, Attract-Mode v2.7.0