Page 1 of 1

bitMap screen rendering

Posted: Tue Sep 13, 2022 1:01 am
by skagonTheIdiot
i am working on a 3d rendering engine and ive come up on a problem that i cant figure out. i want to use a bitmap rendering system from a table, i would have a table or a variable that i can give a x and y of a pixle on the screen and i can tell it which colour i would like it to be, i cant find an efficient way of doing this and rendering it without dropping fps from 60 down to 3. is there anyway i can make it more efficient? there is no code since it is just a table and a for loop but i know its not the drawing of the pixles that is the issue since i ran it without rendering anything, just running the for loop and assigning the colours not rendering any pixles, and its still near 6 fps. i plan on having an entire screen filled so using a second table filled with the only pixles to render wouldnt work very well but im open to anything. ive looked everywhere on google but the only possible solutions are downloadable addons and scripts that i dont want (its a single script engine that im doing as a challange), but if you can point me in any speudo bitmap script addons that i can try and understand and copy that would be fine aswell.

Re: bitMap screen rendering

Posted: Tue Sep 13, 2022 9:00 am
by ReFreezed
Do you mean you want to generate an image programmatically, as opposed to creating it in a drawing program? Generate the image once at load time using love.image.newImageData and ImageData:mapPixel or ImageData:setPixel, followed by love.graphics.newImage.

Code: Select all

function love.load()
	local imageData = love.image.newImageData(100, 100)

	imageData:mapPixel(function(x,y, r,g,b,a)
		r = math.random() -- You could get the color from some table. Here we just generate random noise.
		g = math.random()
		b = math.random()
		a = 1
		return r, g, b, a
	end)

	image = love.graphics.newImage(imageData)
end

function love.draw()
	love.graphics.draw(image)
end

Re: bitMap screen rendering

Posted: Tue Sep 13, 2022 9:38 am
by pgimeno
It appears that you're doing this every frame. If that's the case, it's unlikely you will get the performance you want, but anyway, rather than using love.graphics.newImage, use Image:replacePixels.

Also, depending on what you're trying to do, it might be better to use a shader rather than drawing the pixels on the Lua side.

Edit: Oops, I missed the part of the 3D rendering engine. You're better off using OpenGL 3D no doubt; it's designed to be fast.