Shaders, Help!
Posted: Thu Feb 22, 2024 7:52 am
Hello I'm new to this forum and I want to know if anyone has an idea on what is wrong with the shader code i provided,(comment lines will point to location of code 'not part of the code) for I can't seem to draw a triangle on the screen, It worked well for other tests i've done like an rgb altering effect, but it doesn't seem to be working for me , the error given when trying to run|bad argument #1 to 'newShader' (missing 'position' or 'effect' function?))|
function love.load()
-- Define vertices of the triangle
vertices = {
{-0.5, -0.5},
{0.5, -0.5},
{0.0, 0.5}
}
------------------------------------------------------------
-- Load the shader
shaderCode = [[
// Vertex shader
attribute vec4 position;
void main() {
gl_Position = position;
}
// Fragment shader
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // Red color
}
]]
shader = love.graphics.newShader(shaderCode)
-----------------------------------------------------------
-- Create a Mesh with position attribute
mesh = love.graphics.newMesh(vertices, "triangles")
mesh:setVertexAttribute("position", vertices, "float", 2) -- Set vertex attribute
end
function love.draw()
-- Set the shader
love.graphics.setShader(shader)
-- Draw the mesh
love.graphics.draw(mesh)
-- Reset shader
love.graphics.setShader()
end
function love.load()
-- Define vertices of the triangle
vertices = {
{-0.5, -0.5},
{0.5, -0.5},
{0.0, 0.5}
}
------------------------------------------------------------
-- Load the shader
shaderCode = [[
// Vertex shader
attribute vec4 position;
void main() {
gl_Position = position;
}
// Fragment shader
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // Red color
}
]]
shader = love.graphics.newShader(shaderCode)
-----------------------------------------------------------
-- Create a Mesh with position attribute
mesh = love.graphics.newMesh(vertices, "triangles")
mesh:setVertexAttribute("position", vertices, "float", 2) -- Set vertex attribute
end
function love.draw()
-- Set the shader
love.graphics.setShader(shader)
-- Draw the mesh
love.graphics.draw(mesh)
-- Reset shader
love.graphics.setShader()
end