[lib] maid64 - easy low resolution scaling system

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

[lib] maid64 - easy low resolution scaling system

Post 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 394 times
maid64 version 1.1
maid64.love
(8.29 KiB) Downloaded 411 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
Last edited by adekto on Sun Oct 08, 2017 1:05 am, edited 5 times in total.
User avatar
modog
Prole
Posts: 17
Joined: Sun Mar 27, 2016 1:20 am

Re: [lib] maid64 - square low resolution system

Post by modog »

Oh dude, that's amazing! Good job!
:emo: lua-chan falling in love with löve-senpai :neko:
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: [lib] maid64 - square low resolution system

Post by josefnpat »

I saw this jam on twitter a few hours ago - this might be a nifty library to use! Thanks!
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

Re: [lib] maid64 - square low resolution system

Post by adekto »

pixelated font, hopfully its readeble (have to test it still)
lowfontA.png
lowfontA.png (15.42 KiB) Viewed 11196 times

Code: Select all

pixelfont = love.graphics.newImageFont("lowfontA.png",
    " abcdefghijklmnopqrstuvwxyz" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
    "123456789.,!?-+/():;%&`'*#=[]\"")
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: [lib] maid64 - square low resolution system

Post 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 11162 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
Last edited by qubodup on Sat Apr 02, 2016 5:47 am, edited 1 time in total.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
TheRedRaccoon
Prole
Posts: 12
Joined: Sun Feb 21, 2016 6:55 pm

Re: [lib] maid64 - square low resolution system

Post 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
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

Re: [lib] maid64 - square low resolution system

Post 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)
    
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

Re: [lib] maid64 - square low resolution system

Post 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)
    
surfacetoairmissiles
Prole
Posts: 1
Joined: Tue Apr 05, 2016 5:18 am

Re: [lib] maid64 - square low resolution system

Post 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


WetDesertRock
Citizen
Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

Re: [lib] maid64 - square low resolution system

Post by WetDesertRock »

Another jam this system would be great for! https://itch.io/jam/bit-jam

;)
Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests