Page 1 of 2

[lib] maid64 - easy low resolution scaling system

Posted: Thu Mar 31, 2016 4:34 am
by adekto
i made this for this upcoming jam: https://itch.io/jam/lowrezjam2016

made this so its easy to get to work on a low resolution project, dynamically scales for window mode.
hope anyone else can use this, and maybe wants to join in on that game jam.

maid64 version 1.0
maid64.love
(8.08 KiB) Downloaded 453 times
maid64 version 1.1
maid64.love
(8.29 KiB) Downloaded 451 times
github

maid64 version 1.5
https://github.com/adekto/maid64/tree/master/legacy

maid64 version 1.6
https://github.com/adekto/maid64

main.lua (v1.0)

Code: Select all

require "maid64"

function love.load()
    --optional settings for window
    love.window.setMode(640, 640, {resizable=true, vsync=false, minwidth=200, minheight=200})
 
    --initilizing maid64 for use and set to 64x64 mode
    maid64(64)

    --loading test sprite
    maid = love.graphics.newImage("maid64.png")
    --setting the test sprite's filter so it wont do any anti-aliasing
    maid:setFilter("nearest","nearest")

    rotate = 0
    
end
function love.update(dt)
    --rotation for test sprite
    rotate = rotate + dt
end
function maid64_draw()
    --this is where you do image drawing

    --test sprite
    love.graphics.draw(maid,32,32,rotate,1,1,32,32)
end
maid64.lua (v1.0)

Code: Select all

function maid64(pixels)
	maid64 = {}
    maid64.size = pixels or 64 
    maid64.scaler = love.graphics.getHeight() / maid64.size
    maid64.x = love.graphics.getWidth()/2-(maid64.scaler*(maid64.size/2))
    maid64.y = love.graphics.getHeight()/2-(maid64.scaler*(maid64.size/2))
    maid64.canvas = love.graphics.newCanvas(maid64.size, maid64.size)
    maid64.canvas:setFilter("nearest","nearest")
    
end
function love.draw()
	love.graphics.setCanvas(maid64.canvas)
	love.graphics.clear()
	maid64_draw()
	love.graphics.setCanvas()
    love.graphics.draw(maid64.canvas, maid64.x,maid64.y,0,maid64.scaler,maid64.scaler)
end
function love.resize(w, h)
    if h < w then
        maid64.scaler = h / maid64.size
    else
        maid64.scaler = w / maid64.size
    end
    maid64.x = w/2-(maid64.scaler*(maid64.size/2))
    maid64.y = h/2-(maid64.scaler*(maid64.size/2))
end

Re: [lib] maid64 - square low resolution system

Posted: Thu Mar 31, 2016 7:11 am
by modog
Oh dude, that's amazing! Good job!

Re: [lib] maid64 - square low resolution system

Posted: Thu Mar 31, 2016 8:21 am
by josefnpat
I saw this jam on twitter a few hours ago - this might be a nifty library to use! Thanks!

Re: [lib] maid64 - square low resolution system

Posted: Fri Apr 01, 2016 3:28 am
by adekto
pixelated font, hopfully its readeble (have to test it still)
lowfontA.png
lowfontA.png (15.42 KiB) Viewed 11889 times

Code: Select all

pixelfont = love.graphics.newImageFont("lowfontA.png",
    " abcdefghijklmnopqrstuvwxyz" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
    "123456789.,!?-+/():;%&`'*#=[]\"")

Re: [lib] maid64 - square low resolution system

Posted: Fri Apr 01, 2016 6:19 am
by qubodup
Set minwidth=64, minheight=64 in main.lua:5 for the real deal. :)
http://giphy.com/gifs/gamedev-lve-love2d-3o7WTxeUgHVuFVcUcE
http://giphy.com/gifs/gamedev-lve-love2d-3o7WTxeUgHVuFVcUcE
maid64.gif (171.96 KiB) Viewed 11855 times

https://www.youtube.com/watch?v=XUteFZH2tIg

Looking forward to #lowrezjam!

EDIT:

I combined maid64 and love3d. It kind of works...


https://youtu.be/Hn5fz1oHTTA

Re: [lib] maid64 - square low resolution system

Posted: Fri Apr 01, 2016 4:40 pm
by TheRedRaccoon
adekto wrote:pixelated font, hopfully its readeble (have to test it still)
lowfontA.png

Code: Select all

pixelfont = love.graphics.newImageFont("lowfontA.png",
    " abcdefghijklmnopqrstuvwxyz" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
    "123456789.,!?-+/():;%&`'*#=[]\"")
Skipped the letter 'N', other than that, it works

Re: [lib] maid64 - square low resolution system

Posted: Sat Apr 02, 2016 6:51 am
by adekto
whoops, il try and fix that, im not to happy about it and will probebly change.

maybe something not to well explained is the init parameter you can change, for example if you like the pico8 resolution:

Code: Select all

--initilizing maid64 for 128x128
    maid64(128)
    

Re: [lib] maid64 - square low resolution system

Posted: Sat Apr 02, 2016 9:59 am
by adekto
not sure if i should add a shader selection to maid64, any ideas or sugestions?

made a cga mode and some others just to try it out, never done anything like this

Code: Select all

mode  = {
    [[  // mode 1 - CGA mode
        vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
        {
            vec4 texcolor = Texel(texture, texture_coords);
            vec4 col = step(0.5,texcolor);
            if(col == vec4(1.,1.,1.,1.)) return col * color;
            if(col == vec4(0.,0.,0.,1.)) return col * color;
            if(col.r == 1.0) col = vec4(1.,0.,1.,col.a);
            if(col.r == 0.) col = vec4(0.,1.,1.,col.a);
            return col * color;
        }
    ]]
    ,
    [[ // mode 2 - prime color mode
        vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
        {
            vec4 texcolor = Texel(texture, texture_coords);
            return step(0.5,texcolor) * color;
        }
    ]]
    ,
    [[ // mode 3 - 8bit color mode?
        vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
        {
            vec4 texcolor = Texel(texture, texture_coords);
            return  ((step(0.25,texcolor)+step(0.75,texcolor))/2)* color;
        }
    ]]
    }

    shader = love.graphics.newShader(mode[1])
    love.graphics.setShader(shader)
    

Re: [lib] maid64 - square low resolution system

Posted: Tue Apr 05, 2016 5:49 am
by surfacetoairmissiles
this is really great and showed up exactly when i started having problems with my resolutions.

I fiddled around with your implementation and got rid of maid64_draw since i wanted to use states. now everything occurs in love.draw() again. Also i changed it so now all the functions fall under the maid64 variable. this means that all of the function calls are maid64.something which makes it feel more like a library. I wont bother uploading a .love since this is functionally the same .

main.lua

Code: Select all

require "maid64"

function love.load()
    love.window.setMode(640, 640, {resizable=true, vsync=false, minwidth=200, minheight=200})
    
   maid64.setup(64)--This has been changed from maid64 it just looks nicer idk
    
    maid = love.graphics.newImage("maid64.png")
    maid:setFilter("nearest","nearest")

    rotate = 0
   
end
function love.update(dt)
    rotate = rotate + dt
end
function love.draw()
    --now all of your drawing occurs in love.draw
    maid64.start()--starts the maid64 process

    --all of your drawing goop goes in the middle
    love.graphics.draw(maid,32,32,rotate,1,1,32,32)
    
    maid64.finish()--finishes
end

function love.resize(w, h)-- i moved this to main.lua since i like having all the base love. functions in here
	maid64.resize(w, h)
end
maid64.lua

Code: Select all

maid64 = {}--I declare maid64 up here. Its a global anyway so this is better practice than in in a function
function maid64.setup(pixels)-- maid64 is now maid64.setup
    maid64.size = pixels or 64
    maid64.scaler = love.graphics.getHeight() / maid64.size
    maid64.x = love.graphics.getWidth()/2-(maid64.scaler*(maid64.size/2))
    maid64.y = love.graphics.getHeight()/2-(maid64.scaler*(maid64.size/2))
    maid64.canvas = love.graphics.newCanvas(maid64.size, maid64.size)
    maid64.canvas:setFilter("nearest","nearest")
end

maid64.start = function ()--part of maid64_draw is now maid64.start
   	love.graphics.setCanvas(maid64.canvas)
   	love.graphics.clear()
    end
maid64.finish = function () --The other half of maid64_draw is now maid64.finish
    	love.graphics.setCanvas()
    	love.graphics.draw(maid64.canvas, maid64.x,maid64.y,0,maid64.scaler,maid64.scaler)
end

function maid64.resize(w, h)-- this is a function for neatnesses sake
    if h < w then
        maid64.scaler = h / maid64.size
    else
        maid64.scaler = w / maid64.size
    end
    maid64.x = w/2-(maid64.scaler*(maid64.size/2))
    maid64.y = h/2-(maid64.scaler*(maid64.size/2))
end



Re: [lib] maid64 - square low resolution system

Posted: Tue Apr 05, 2016 8:03 am
by WetDesertRock
Another jam this system would be great for! https://itch.io/jam/bit-jam

;)