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?
Scaling love.graphics geometric shapes like bitmap pics?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Daniel Eakins
- Citizen
- Posts: 99
- Joined: Thu Jul 18, 2013 9:14 pm
- Location: France
Scaling love.graphics geometric shapes like bitmap pics?
- Attachments
-
- example.love
- (1.29 KiB) Downloaded 193 times
Re: Scaling love.graphics geometric shapes like bitmap pics?
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.
If you don't want the aliasing then you can use
to get a more harsh, pixellated result.
Code: Select all
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
Code: Select all
love.graphics.setLineStyle("rough")
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.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Scaling love.graphics geometric shapes like bitmap pics?
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.
Otherwise you're just gonna get the smooth shape edges.
- Daniel Eakins
- Citizen
- Posts: 99
- Joined: Thu Jul 18, 2013 9:14 pm
- Location: France
Re: Scaling love.graphics geometric shapes like bitmap pics?
Ohh no, it turns out my computer doesn't support canvases! I didn't know it doesn't
- Daniel Eakins
- Citizen
- Posts: 99
- Joined: Thu Jul 18, 2013 9:14 pm
- Location: France
Re: Scaling love.graphics geometric shapes like bitmap pics?
Any other idea?
Re: Scaling love.graphics geometric shapes like bitmap pics?
You could try the more direct approach and using graphics.scale to draw everything bigger.
https://love2d.org/wiki/love.graphics.scale
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.
https://love2d.org/wiki/love.graphics.scale
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.
Re: Scaling love.graphics geometric shapes like bitmap pics?
The whole problem is that this doesn't work for primitives drawn by the framework.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.
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.
Re: Scaling love.graphics geometric shapes like bitmap pics?
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.)
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.)
- Daniel Eakins
- Citizen
- Posts: 99
- Joined: Thu Jul 18, 2013 9:14 pm
- Location: France
Re: Scaling love.graphics geometric shapes like bitmap pics?
Yeah it's pretty weird, but I guess it's preferrable for games who need "vectorized" graphics.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.)
I'd like the geometric shapes to be dynamically generated to accomodate different coordinates/angles/lengths.Lafolie wrote:Is there a particular reason you're not using pre-rendered images? If not, just use a few images instead.
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.
Re: Scaling love.graphics geometric shapes like bitmap pics?
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.
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.
Check out my blog on gamedev
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 229 guests