summaryrefslogtreecommitdiff
path: root/demo/honey.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-22 13:29:20 -0500
committersanine <sanine.not@pm.me>2022-08-22 13:29:20 -0500
commit6f06255d2ae0337d9aea5e5330502581e32dab09 (patch)
tree688e922a01db5a146199e763ba8531de37c1d9f3 /demo/honey.lua
parentb2c0dd12d2a39e74f8e6d63bffec073ef0871ea7 (diff)
add multiple vertex attributes
Diffstat (limited to 'demo/honey.lua')
-rw-r--r--demo/honey.lua22
1 files changed, 14 insertions, 8 deletions
diff --git a/demo/honey.lua b/demo/honey.lua
index 470880d..7f02006 100644
--- a/demo/honey.lua
+++ b/demo/honey.lua
@@ -26,21 +26,26 @@ end)
local vertexShaderSource = [[
#version 330 core
layout (location = 0) in vec3 aPos;
+layout (location = 1) in vec3 aColor;
+
+out vec3 pColor;
void main()
{
+ pColor = aColor;
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
]]
local fragmentShaderSource = [[
#version 330 core
+in vec3 pColor;
uniform vec4 color;
out vec4 FragColor;
void main()
{
- FragColor = color;
+ FragColor = vec4(pColor.rgb, 1);
}
]]
@@ -60,10 +65,11 @@ gl.shader.delete(fragmentShader)
local vertices = {
- 0.5, 0.5, 0.0,
- 0.5, -0.5, 0.0,
- -0.5, -0.5, 0.0,
- -0.5, 0.5, 0.0
+ -- position color
+ 0.5, 0.5, 0.0, 0, 0, 0,
+ 0.5, -0.5, 0.0, 1, 0, 0,
+ -0.5, -0.5, 0.0, 0, 1, 0,
+ -0.5, 0.5, 0.0, 0, 0, 1
}
local indices = {
0, 1, 3,
@@ -85,10 +91,10 @@ if gl.getError() ~= gl.errorType.noError then error(gl.getError()) end
gl.data.bindBuffer(gl.data.bufferTarget.elementArrayBuffer, elementBuffer)
gl.data.bufferData(gl.data.bufferTarget.elementArrayBuffer, gl.dataType.uint, indices, gl.data.bufferUsage.staticDraw)
-gl.data.vertexAttribPointer(0, 3, false, 3, 0)
-if gl.getError() ~= gl.errorType.noError then error(gl.getError()) end
+gl.data.vertexAttribPointer(0, 3, false, 6, 0)
gl.data.vertexArrayEnableAttrib(0)
-if gl.getError() ~= gl.errorType.noError then error(gl.getError()) end
+gl.data.vertexAttribPointer(1, 3, false, 6, 3)
+gl.data.vertexArrayEnableAttrib(1)
gl.data.bindBuffer(gl.data.bufferTarget.arrayBuffer, 0)
if gl.getError() ~= gl.errorType.noError then error(gl.getError()) end