Hi everyone!
I've updated push with multiple shaders support.
You can now provide a table of shaders, which will apply in the order they're provided. This allows you to combine shader effects, or even draw the same shader with multiple passes.
https://github.com/Ulydev/push
push - a resolution-handling library
Re: push - a resolution-handling library
Great library Ulydev!
I am using it to scale my android game, it didnt work right away but after some digging I managed to make it work. I wanted to share some tips that are perhaps common-knowledge but took me some time to figure out. Firstly if you are developing for phones you have to take into consideration the Pixel density of the different phones that exist. I didnt know much about this so I never got Push to work properly before realizing that for example the the pixel density on my phone is 3(number I got from love.window.getDPIScale() ) and I have to take that also into account when scaling. My solution was this:
So i divide the screen resolution with the pixel density value before passing them on to the Push library. Perhaps there is a better way to do this, but since my game is pretty lowres this works for me.
Another thing is the canvas boolean. With it set to true it completely tanked my FPS on my phone from steady 60 to about 18-21 fps. Took some time to find this out but when i put canvas to false I was back into the usual 60fps.
Maybe those 2 tips will help others who are using this with android development. Once again thanks for this great library Ulydev
I am using it to scale my android game, it didnt work right away but after some digging I managed to make it work. I wanted to share some tips that are perhaps common-knowledge but took me some time to figure out. Firstly if you are developing for phones you have to take into consideration the Pixel density of the different phones that exist. I didnt know much about this so I never got Push to work properly before realizing that for example the the pixel density on my phone is 3(number I got from love.window.getDPIScale() ) and I have to take that also into account when scaling. My solution was this:
Code: Select all
gameWidth, gameHeight = 480, 320
screenWidth, screenHeight = love.window.getDesktopDimensions()
local dpi_scale = love.window.getDPIScale()
screenWidth = screenWidth/dpi_scale
screenHeight = screenHeight/dpi_scale
push:setupScreen(gameWidth, gameHeight, screenWidth, screenHeight, {fullscreen = true, resizable = false, canvas = false, pixelperfect =
false, highdpi = true, stretched = true})
Another thing is the canvas boolean. With it set to true it completely tanked my FPS on my phone from steady 60 to about 18-21 fps. Took some time to find this out but when i put canvas to false I was back into the usual 60fps.
Maybe those 2 tips will help others who are using this with android development. Once again thanks for this great library Ulydev
Email: ic4ruz39@gmail.com
-
- Prole
- Posts: 1
- Joined: Mon Dec 03, 2018 12:31 pm
Re: push - a resolution-handling library
Thank you for sharing this Mermersk, I definitely helped me sorting out this Android scaling issue. I did
I am not sure if I need to do this second part, as I am not experiencing that same issue but will keep it in my cheat sheet just in caseMermersk wrote: ↑Thu Jul 12, 2018 6:35 pmSo i divide the screen resolution with the pixel density value before passing them on to the Push library. Perhaps there is a better way to do this, but since my game is pretty lowres this works for me.Code: Select all
gameWidth, gameHeight = 480, 320 screenWidth, screenHeight = love.window.getDesktopDimensions() local dpi_scale = love.window.getDPIScale() screenWidth = screenWidth/dpi_scale screenHeight = screenHeight/dpi_scale push:setupScreen(gameWidth, gameHeight, screenWidth, screenHeight, {fullscreen = true, resizable = false, canvas = false, pixelperfect = false, highdpi = true, stretched = true})
@ Ulydev thanks for such an amazing library.Another thing is the canvas boolean. With it set to true it completely tanked my FPS on my phone from steady 60 to about 18-21 fps. Took some time to find this out but when i put canvas to false I was back into the usual 60fps.
Re: push - a resolution-handling library
I am unable to get this library to work with stencils. I am getting this error, which I don't know how to fix:
I am using canvases, shaders, and stecils.
Code: Select all
Drawing to the stencil buffer with a Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas.
Re: push - a resolution-handling library
Hi ac3ravenac3raven wrote: ↑Sat Apr 06, 2019 6:19 am I am unable to get this library to work with stencils. I am getting this error, which I don't know how to fix:I am using canvases, shaders, and stecils.Code: Select all
Drawing to the stencil buffer with a Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas.
Hmm, I need to update the library to support stencils. In the meantime, you can do a quick fix by going to line 92 in push.lua and modify the love.graphics.setCanvas call to use stencils (see https://love2d.org/wiki/love.graphics.stencil)
Re: push - a resolution-handling library
I have already tried that, but maybe I'm doing something wrong. Here is the modification I made:
I still get the same error. Perhaps I am using Push incorrectly? Or is there more to the modification?
Here is my code:
Code: Select all
function push:setCanvas(name)
if not self._canvas then return true end
return love.graphics.setCanvas({self:getCanvasTable(name).canvas,stencil=true})
end
Here is my code:
Code: Select all
local canvas = lg.newCanvas(350,60)
local scoretext = tostring(currentscore)
local scoretext_object = lg.newText(font,scoretext)
local rainbow_shader = require 'rainbow_shader'
local rainbowmask_shader = require 'rainbowmask_shader'
function stencilFunction()
rainbow_shader:send("scaler",scaler)
rainbow_shader:send("rot",r)
push:setShader(rainbowmask_shader)
lg.print(scoretext,lg.getWidth()/2-28,30)
push:setShader()
end
function gameplay:update(dt)
push:setCanvas(canvas)
push:setShader(rainbow_shader)
lg.rectangle("fill",0,0,lg.getWidth(),lg.getHeight())
push:setShader()
push:setCanvas()
end
function gameplay:draw()
push:start()
lg.stencil(stencilFunction,"replace",1)
lg.setStencilTest("greater",0)
scoretext = tostring(math.floor(currentscore))
lg.setColor(1,1,1,1)
if newHighScore then
lg.draw(canvas,lg.getWidth()/2-24-string.len(scoretext),30)
end
lg.setStencilTest()
push:finish()
Last edited by ac3raven on Sat Apr 06, 2019 2:30 pm, edited 1 time in total.
Re: push - a resolution-handling library
Oops, looks like you also need to apply the fix to line 138. Along with any other call to love.graphics.setCanvas(167, 171, 175, 192, and 213).
Re: push - a resolution-handling library
Okay, well that's some progress. Now I get this error, the first time I call push:setCanvas():
Do I need to call setCanvas() differently now that its return is different? Note that I am not currently using push:setupCanvas(). Should I? If so, I'm not sure how to use it. I tried it and the error persisted. I am just passing a canvas to push:setCanvas().
EDIT: btw, I really appreciate your speedy replies!
Code: Select all
Error: libs/push.lua:92: attempt to index a nil value
stack traceback:
[string "boot.lua"]:637: in function '__index'
libs/push.lua:92: in function 'setCanvas'
gameplay.lua:399: in function 'update'
[string "boot.lua"]:509: in function <[string "boot.lua"]:493>
[C]: in function 'xpcall'
EDIT: btw, I really appreciate your speedy replies!
Re: push - a resolution-handling library
I just changed the first parameter to "canvas" instead of (what would be) canvas.canvas on line 92 and it seems to work now!! A bunch of my stuff is off-screen during full-screen mode though, which I will need to fix. But I know how to fix that. I am certain my brute-forcing of line 92 is not an ideal solution.
Re: push - a resolution-handling library
Glad you got it haha yeah it probably isn't a definitive fix but as long as it does the jobac3raven wrote: ↑Sat Apr 06, 2019 3:38 pm I just changed the first parameter to "canvas" instead of (what would be) canvas.canvas on line 92 and it seems to work now!! A bunch of my stuff is off-screen during full-screen mode though, which I will need to fix. But I know how to fix that. I am certain my brute-forcing of line 92 is not an ideal solution.
Also please feel free to open a PR if you'd like!
Who is online
Users browsing this forum: No registered users and 5 guests