I've been implementing a headless server for my game and I'm implementing a feature that effectively draws a simple approximation of the world and draws it to a canvas, sending it to the server admin over HTTP. However, I'm running into an issue: when running it in a completely headless operation by using love.window.close(), it disables the love.graphics() library with it. As a result, the server crashes when attempt to operate the canvas if love.window.close() is invoked. Is there a way to use graphics library functionality whilst the window is disabled?
local canvas = love.graphics.newCanvas(800, 600)
canvas:renderTo(function()
for i, v in pairs(objects) do
love.graphics.rectangle("fill",v.x,v.y,v.w,v.h)
end
end)
local rawimg = canvas:newImageData()
local data = rawimg:encode("png")
rawimg:encode("png", "test.png")
This is essentially an OpenGL thing, where it requires a context where to draw the stuff at hand (check the footnotes on this wiki page). Now, there are ways to handle OpenGL without opening a window, but you probably would have to write changes to löve's source code for it to do this exact thing. Additionally, the approach you'd have to take is also going to depend on your operating system.
Apologies for such a belated response. I've decided to go with the software rendering approach -- something I wasn't aware of beforehand. Granted it's not going to be as fast but speed is not a large concern in practice considering this image is only called upon once every 10 seconds. I am tempted to change it all over to some sort of client-side HTML5 canvas type thing down the road, but for now this will do. Thank you to everyone that responded! :-)