Playmat - A Mode 7 Library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Playmat - A Mode 7 Library

Post by hatninja »

Borrowing retrotail's fast shader code, i've decided to create a library that helps the mode 7 effect become much more accessible. The mode 7 plane is well documented, but sprites were a big difficulty. After hitting that wall myself, i've finally figured it out, so i hope playmat helps you out too!

Playmat
A strong utility for making mode 7 games from within love2d!

Features:
  • Fast to set up!
  • Cool helper functions.
  • Versatile sprite system.
  • Ability to run on slow computers.
Example Code:

Code: Select all

PM = require("playmat")

mapimg = love.graphics.newImage("map.png")
spriteimg = love.graphics.newImage("sprite.png")

cam = PM.newCamera() --Sets up a new camera, resolution is 800 x 600 by default.

cam:setPosition(100,50)
cam:setZoom(48)

function love.draw()
	PM.drawPlane(cam, mapimg) --The image drawn as a plane.
	
	PM.placeSprite(cam, spriteimg, 125,100, 0, 8,8)
	PM.renderSprites(cam) --And now the sprite is there too!
end
Changelog:

Code: Select all

v1.5 - Experimentally better
Sprites can now be colored!
Planes are stretchy now.
Planes now render directly using the shader.
Some major code improvements.

v1.2 - Minor
Fixed Sprite scaling problems

v1.1 - Perfection
Fixed non-square images not working right.
Added plane wrapping feature!

v1.0.3 - Hotfixes
The demo has also been updated to fix crashing for some.

v1.0 - Made public!
Find it here:
Github

Feedback would be greatly appreciated!

Demo controls:
wasd - Movement
q & e - Rotate
- & + - Zoom in and out
i & o - Change FOV
k & l - Change Offset
Attachments
Playmat Demo.love
(27.7 KiB) Downloaded 915 times
Last edited by hatninja on Sat Jun 24, 2017 7:09 pm, edited 7 times in total.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Playmat - A Mode 7 Library

Post by zorg »

hatninja wrote:(...)
Didn't try it out (yet), but i did look at the code a bit;

Code: Select all

local size = ((1/distance)/cam.z*cam.o)*800 -- line 162
I'm assuming that magic number there wanted to be the width of the screen? Or is it more magic than that? :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Re: Playmat - A Mode 7 Library

Post by hatninja »

It was an approximation, but i'm still surprised i didn't catch that! Sounds like it would be the case!
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Playmat - A Mode 7 Library

Post by zorg »

I remember myself wanting to calculate aperture, fov and z distance relations for my own camera implementation too, was quite suprised that the equation turned out simpler than i imagined... which i did want to share, if only for the fact that with some "basic" values, like 90° field-of-view and similarly default numbers, what it gave me back was exactly half of the value i was expecting... but yeah, sadly i can' find my code, (nor the equations i actually wrote out into one of my notebooks) so i can't be more clear than this. :monocle:
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Playmat - A Mode 7 Library

Post by pgimeno »

I'm getting this:

Code: Select all

Error: playmat.lua:125: Shader uniform 'r' does not exist.
A common error is to define but not use the variable.
stack traceback:
	[C]: in function 'send'
	playmat.lua:125: in function 'drawPlane'
	main.lua:26: in function 'draw'
	[string "boot.lua"]:468: in function <[string "boot.lua"]:436>
	[C]: in function 'xpcall'
I've got that sometimes myself. An extern variable is optimized out and that causes an error. I removed the 'extern r = 0' and the shader:send('r'...) lines and then it worked.

Awesome work!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Playmat - A Mode 7 Library

Post by Jasoco »

What version of Löve do you have? What GPU and drivers? It worked for me on 0.10.2.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Playmat - A Mode 7 Library

Post by Davidobot »

Jasoco wrote:This is amazing.
Does this mean that our Raycasters can get a proper floor now? :awesome:
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Playmat - A Mode 7 Library

Post by Jasoco »

Davidobot wrote:
Jasoco wrote:This is amazing.
Does this mean that our Raycasters can get a proper floor now? :awesome:
I was wondering that myself. Maybe you should do some experimenting. It'd be figuring out the correct angles to use to make it line up properly.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Playmat - A Mode 7 Library

Post by yetneverdone »

wow, very awesome. Possible to make doom-esque fps?
Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests