Let's say I want my game to have a specific native resolution (320x200) which is scaled up on the player's desktop monitor using the love.graphics.scale() function.
In this screenshot, the blue and orange background is a bitmap (PNG) picture scaled up, while the white line is a dynamic shape generated using love.graphics.line():
Is there a way to render the line as if it were a bitmap picture so that it has the same pixel resolution as like the blue and orange picture?
An easy way to do this is with a canvas. It may not be the most elegant solution, but may work well if you're using multiple line/shapes that don't move independently.
function love.load()
gWidth, gHeight = 320, 200 --my game resolution
love.graphics.setDefaultFilter("nearest", "nearest")
i = 1 --scaling factor
while gWidth*(i+1) < love.window.getDesktopDimensions() do i = i+1 end
love.window.setMode(gWidth*i, gHeight*i, {fullscreentype = "desktop"})
line = love.graphics.newCanvas()
line:renderTo(function() love.graphics.line(10, 0, 210, 200) end)
end
function love.draw()
love.graphics.push()
love.graphics.scale(i)
testImage = love.graphics.newImage("test.png")
love.graphics.draw(testImage)
love.graphics.draw(line)
love.graphics.pop()
end
love.keypressed = function(key, unicode)
if key == "escape" then love.event.push("quit") end
end
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Yeah, you should use a canvas. By having a sort of "base resolution" for your game, create a canvas of that size and draw everything to it. Then draw that canvas to the screen at the scale you need.
Otherwise you're just gonna get the smooth shape edges.
Plu wrote:
It's basically the same kind of approach as using a canvas except you'll have to do it directly to the screen. Should still work though.
The whole problem is that this doesn't work for primitives drawn by the framework.
Is there a particular reason you're not using pre-rendered images? If not, just use a few images instead.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Plu wrote:Seriously? Sorry I didn't know that. Seems... weird that it wouldn't do that
I'm guessing it's just how openGL handles it?
edit: Oops, I should have reread the OP before posting again, it does indeed mention there it doesn't work. (But I still think it's weird.)
Yeah it's pretty weird, but I guess it's preferrable for games who need "vectorized" graphics.
Lafolie wrote:Is there a particular reason you're not using pre-rendered images? If not, just use a few images instead.
I'd like the geometric shapes to be dynamically generated to accomodate different coordinates/angles/lengths.
Example at 0:48
In this video from a SNES game, when these two characters do a special attack, red lines are drawn in their paths. So these lines can start anywhere on the screen and have any angle and length possible.
Last edited by Daniel Eakins on Thu Jan 09, 2014 3:27 am, edited 1 time in total.
If I get it correctly, then you want to draw lines (or polygons) such that they are pixelated in a consistent way with your other images.
Since Canvas is not option for you, you can try ImageData. You create an empty one, draw the lines onto it and then make a new image from it and draw it scaled. This might take some time, but if you only do it ocasionally, it should be okay.
The drawing on the imageData is the difficult part. You can only use the setPixel-function, so you have to create a function that draws a line onto an imageData using only single pixels.