[SOLVED]Drawing a polygon to a canvas
Posted: Thu Jan 08, 2015 2:11 pm
Hello boys and girls!
I'm currently on a small side project to understand canvas better and right now I have rectangles and circles drawn to the screen, I also want to add triangles to the screen too but since 0.9.0 you can't use graphics.triangle so I'm using graphics.polygon instead.
But as of now they don't show up on my screen, I'm pretty sure that I have the coordinates nailed down and I also have a size of my "triangle" that I'm satisfied with so I would appreciate if you could give me some hints on what I'm doing wrong.
Thank you for your time!
I'm currently on a small side project to understand canvas better and right now I have rectangles and circles drawn to the screen, I also want to add triangles to the screen too but since 0.9.0 you can't use graphics.triangle so I'm using graphics.polygon instead.
But as of now they don't show up on my screen, I'm pretty sure that I have the coordinates nailed down and I also have a size of my "triangle" that I'm satisfied with so I would appreciate if you could give me some hints on what I'm doing wrong.
Thank you for your time!
Code: Select all
local rectangleCanvas = love.graphics.newCanvas(100, 100) -- Rectangle Canvas
local circleCanvas = love.graphics.newCanvas(100, 100) -- Circle Canvas
local polygonCanvas = love.graphics.newCanvas(100, 100) -- Polygon Canvas
function love.load()
-- Rectangle
love.graphics.setCanvas(rectangleCanvas)
rectangleCanvas:clear()
love.graphics.setColor(0, 255, 0, 128)
love.graphics.rectangle('fill', 0, 0, 100, 100)
love.graphics.setCanvas()
-- Circle
love.graphics.setCanvas(circleCanvas)
circleCanvas:clear()
love.graphics.setColor(255, 0, 0, 128)
love.graphics.circle('fill', 50, 50, 50, 50)
love.graphics.setCanvas()
-- Polygon
love.graphics.setCanvas(polygonCanvas)
polygonCanvas:clear()
love.graphics.setColor(0, 0, 255, 128)
love.graphics. polygon('fill', 0, 200, 0, 300, 100, 300)
love.graphics.setCanvas()
--[[
love.graphics.draw(rectangleCanvas) -- Rectangle
love.graphics.draw(circleCanvas, 100, 100) -- Circle
love.graphics.draw(rectangleCanvas, 100, 0)
love.graphics.draw(circleCanvas,0, 100) -- Bright Red
]]--
end
function love.draw()
love.graphics.setColor(255, 255, 255, 255)
--[[
-- Rectangle
love.graphics.setCanvas(rectangleCanvas)
rectangleCanvas:clear()
love.graphics.setColor(0, 255, 0, 128)
love.graphics.rectangle('fill', 0, 0, 100, 100)
love.graphics.setCanvas()
-- Circle
love.graphics.setCanvas(circleCanvas)
circleCanvas:clear()
love.graphics.setColor(255, 0, 0, 128)
love.graphics.circle('fill', 50, 50, 50, 50)
love.graphics.setCanvas()
-- Polygon
love.graphics.setCanvas(polygonCanvas)
polygonCanvas:clear()
love.graphics.setColor(0, 0, 255, 128)
love.graphics. polygon('fill', 0, 200, 0, 300, 100, 300)
love.graphics.setCanvas()
]]--
-- Canvas (Drawn To The Left)
love.graphics.draw(rectangleCanvas) -- Rectangle
love.graphics.draw(circleCanvas, 0, 100) -- Circle
love.graphics.draw(polygonCanvas, 0, 200) -- Polygon
-- Canvas (Drawn In The Middle)
love.graphics.draw(rectangleCanvas, 100, 0) -- Rectangle
love.graphics.draw(circleCanvas, 100, 100) -- Circle
love.graphics.draw(polygonCanvas, 100, 200) -- Polygon
-- Normal (Drawn To The Right)
-- Rectangle
love.graphics.setColor(0, 255, 0, 128)
love.graphics.rectangle('fill', 200, 0, 100, 100)
-- Circle
love.graphics.setColor(255, 0, 0, 128)
love.graphics.circle('fill', 250, 150, 50, 50)
--[[
-- Polygon
love.graphics.setColor(0, 0, 255, 128)
love.graphics. polygon('fill', 0, 200, 0, 300, 100, 300)
]]--
end