Page 1 of 1

Why does my project stop when I run it?

Posted: Wed Mar 16, 2022 2:41 pm
by diamondglass
Why does my project stop when I run it? What do I mean? Well, because my project (it's a "screen") stops me
at the moment of executing it, I will leave the code so that they can help me to know what happens.

PD: I translate it because my English is basic

Code: Select all

function love.load()
    love.window.setMode(300,200,{resizable=false})
end

function love.draw()
	DrawDisplay(300,200)
end

function love.update()

end

function DrawDisplay(w,h)
	for y = 1, h do
		for x = 1, w do
			DrawPoint(x - 1,y,color)
		end
		y = y + 1
	end	
end

function DrawPoint(x,y,color)
	love.graphics.points(x,y)
	love.graphics.setColor(love.math.colorFromBytes(128, 234, 255))
end

Re: Why does my project stop when I run it?

Posted: Thu Mar 17, 2022 2:19 am
by pgimeno
You should not draw pixel by pixel to fill the screen. OpenGL is very slow when doing that. Draw a rectangle that covers the whole area instead, like this:

Code: Select all

function DrawDisplay(w, h)
	love.graphics.setColor(love.math.colorFromBytes(128, 234, 255)
	love.graphics.rectangle("fill", 0, 0, w, h)
end
But if you want to fill the screen with a colour, you can use "love.graphics.clear()" like this:

Code: Select all

function DrawDisplay(w, h)
	love.graphics.clear(love.graphics.colorFromBytes(128, 234, 255))
end

Re: Why does my project stop when I run it?

Posted: Sat Mar 19, 2022 6:24 am
by zorg
I don't recall whether points are actually batched or not, but if they aren't, you might get *somewhat* better performance by drawing a tinted 1x1 white Image instead.

Code: Select all

local dot = love.graphics.newImage(love.graphics.newImageData(1,1,'rgba8',string.char(255,255,255,255)))
function DrawPoint(x,y,color)
    love.graphics.setColor(love.math.colorFromBytes(color))
    love.graphics.draw(dot, x, y)
end
You might want to also specify color somewhere... since you do want to treat it as a variable you pass around.