@Ignatz What I mean is that the result is the same–error. If I do not comment the line, the error will occur at “myAttrBuffer:resize(30)” , if I comment the line, the error will also occur at “myAttrBuffer:resize(30)”.
this is the whole code without comment:
-- MagicMirror
-- ????????????????
-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)
-- print("Hello World!")
cameraSource(CAMERA_FRONT)
--cameraSource(CAMERA_BACK)
spriteMode(CORNER)
img = image(100, 100)
m = mesh()
local w, h =WIDTH, HEIGHT
-- ????????????
-- mesh ????
m.vertices = {
vec2(0,0), vec2(0,h), vec2(w,h),
vec2(0,0), vec2(w,0), vec2(w,h),
}
-- ????????: ???? mesh ??????????
m.texCoords = {
vec2(0,0), vec2(0,1), vec2(1,1),
vec2(0,0), vec2(1,0), vec2(1,1),
}
myColor = color(255, 255, 255, 255)
myColorV = color(255, 0, 6, 255)
m:setColors(myColor)
m.texture = CAMERA
m.shader = shader(mShader.vS,mShader.fS)
--m.shader = shader("Documents:Matrix")
m.shader.uniformVar = 120
setContext(img)
m:draw()
setContext()
print(m.shader.uniformVar)
-- Fetch the attribute array
myAttrBuffer = m:buffer("myAttribute")
-- Resize our buffer
myAttrBuffer:resize(30)
-- Add some random numbers
for i = 1,30 do
myAttrBuffer[i] = math.random(-50,50)
end
print(m.size+100)
--m:resize(10)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(0, 0, 0, 255)
-- This sets the line thickness
strokeWidth(5)
resetMatrix()
translate(0,HEIGHT)
rotate(-90)
scale(1,1.5,1)
m:draw()
end
mShader = { vS = [[
//
// A basic vertex shader
//
// ?? Codea ?????, ???????????
uniform mat4 modelViewProjection;
uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
// ?? Codea ???: ??? attribute ? uniform ??????
// position ??? mesh.vertices ??????????????, ?? [x, y, z, 1]
// color ??? mesh.colors ?????????, ?? [r, g, b, a]
// texCoord ??? mesh.texCoords ??????????????, ?? [x, y]
attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;
attribute float myAttribute;
// ?? fragment ???
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
void main()
{
vColor = color;
vTexCoord = texCoord;
//myAttr = myAttr+vec2(1,1);
gl_Position = modelViewProjection * position;
//gl_Position = modelMatrix*viewMatrix*projectionMatrix * position;
//gl_Position = modelMatrix*projectionMatrix * position;
//gl_Position = viewMatrix*projectionMatrix * position;
//gl_Position = projectionMatrix * viewMatrix* modelMatrix* position;
}
]],
fS = [[
//
// A basic fragment shader
//
precision highp float;
// ?? Codea ?????, ??? Codea ?? mesh.texture ????
uniform lowp sampler2D texture;
// ???????
uniform int uniformVar;
// ? vertex ????????
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
void main()
{
lowp vec4 col = texture2D( texture, vTexCoord ) * vColor;
mediump float t = col.r + col.g + col.b;
lowp float a = t / 3.0;
lowp float a1 = a;
//myAttr = myAttr+1;
// ???????
if(a1 < 0.33) a = 0.0;
else if(a1>=0.33 && a1<0.66) a = 0.5;
else a = 1.0;
col.r = a;
col.g = a;
col.b = a;
//gl_FragColor = vec4(0.15, 0.15, 0.15, a * a);
//gl_FragColor = vec4(0.15, 0.15, 0.15, a);
gl_FragColor = col;
}
]]
}