3D in Love 11.0

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
barnyard
Prole
Posts: 3
Joined: Sun Feb 24, 2019 9:08 pm

3D in Love 11.0

Post by barnyard » Mon Feb 25, 2019 4:44 am

I heard Love 11.0 new 3D functions such as rendering were added in. I looked around for all the 3D related functions in the wiki, but couldn't find them. Is there a reference and perhaps tutorials on how to do 3D graphics within love?

User avatar
pgimeno
Party member
Posts: 2168
Joined: Sun Oct 18, 2015 2:58 pm

Re: 3D in Love 11.0

Post by pgimeno » Thu Feb 28, 2019 6:34 pm

Hi barnyard, welcome to the forums.

LÖVE is a 2D engine. It can be made to work with 3D because support was added for the stuff that was missing, but it isn't much easier to use for 3D than raw OpenGL is, because 3D is not really its focus.

Rendering was not added in 11.0; it was supported from the beginning. Images are internally drawn as 3D faces with the Z coordinate set to 0, and with an orthographic projection. Meshes are supported since 0.9.0 and 3D mesh support since 0.10.0. Vertex shaders are also supported from 0.9.0, and fragment shaders since earlier.

What 11.0 added is support for some stuff that is almost essential for 3D like backface culling and depth buffers. Previously that could only be done by calling OpenGL through FFI.

All that said, there is at least one 3D engine for LÖVE, check out viewtopic.php?f=5&t=86350

User avatar
barnyard
Prole
Posts: 3
Joined: Sun Feb 24, 2019 9:08 pm

Re: 3D in Love 11.0

Post by barnyard » Tue Mar 12, 2019 7:41 am

Is there a way that I can manipulate the images so that I can change the projection to perspective and set the Z coordinate to anything I want?

User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: 3D in Love 11.0

Post by arampl » Tue Mar 12, 2019 10:00 am

Sure. You have to use custom shader(s) and mesh vertex format like this:

Code: Select all

local vs = [[extern mat4 model; extern mat4 projection; extern mat4 view;
		vec4 position(mat4 transform_projection, vec4 vertex_position)
		{
			return projection * view * model * vertex_position;
		}]]

local format = {{"VertexPosition", "float", 3}, {"VertexTexCoord", "float", 2}, {"VertexColor", "byte", 4}}
mesh = lg.newMesh(format, vertices, "triangles")
Small demo (mouselook, controls: w,s,a,d - movement):
Attachments
mouselook.love
(17.84 KiB) Downloaded 159 times

Post Reply

Who is online

Users browsing this forum: slime and 20 guests