Page 6 of 7

Re: push - a resolution-handling library

Posted: Tue Apr 03, 2018 12:01 am
by Ulydev
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

Re: push - a resolution-handling library

Posted: Thu Jul 12, 2018 6:35 pm
by Mermersk
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})
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 :awesome:

Re: push - a resolution-handling library

Posted: Mon Dec 03, 2018 12:37 pm
by lmontoya12
Thank you for sharing this Mermersk, I definitely helped me sorting out this Android scaling issue. I did
Mermersk wrote:
Thu Jul 12, 2018 6:35 pm

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})
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.
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 case
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.
@ Ulydev thanks for such an amazing library.

Re: push - a resolution-handling library

Posted: Sat Apr 06, 2019 6:19 am
by ac3raven
I am unable to get this library to work with stencils. I am getting this error, which I don't know how to fix:

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.
I am using canvases, shaders, and stecils.

Re: push - a resolution-handling library

Posted: Sat Apr 06, 2019 7:30 am
by Ulydev
ac3raven 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:

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.
I am using canvases, shaders, and stecils.
Hi ac3raven
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

Posted: Sat Apr 06, 2019 1:17 pm
by ac3raven
I have already tried that, but maybe I'm doing something wrong. Here is the modification I made:

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
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

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()


Re: push - a resolution-handling library

Posted: Sat Apr 06, 2019 2:28 pm
by Ulydev
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

Posted: Sat Apr 06, 2019 2:52 pm
by ac3raven
Okay, well that's some progress. Now I get this error, the first time I call push:setCanvas():

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'
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!

Re: push - a resolution-handling library

Posted: Sat Apr 06, 2019 3:38 pm
by ac3raven
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. :D

Re: push - a resolution-handling library

Posted: Sat Apr 06, 2019 8:53 pm
by Ulydev
ac3raven 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. :D
Glad you got it haha :awesome: yeah it probably isn't a definitive fix but as long as it does the job :crazy:
Also please feel free to open a PR if you'd like!