[solved] How to get Texture from Quad

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.
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

[solved] How to get Texture from Quad

Post by Xii »

I have a shader, and when I create a new Image and a new Quad from that Image, then try to pass the Quad to the shader it errors with: "bad argument #3 to 'gl_send' (Texture expected, got Quad)".

How do I get the Texture from the Quad?

The wiki says nothing on Textures.

I'm trying to render a part from a sprite atlas with a shader.
Last edited by Xii on Sun Dec 13, 2020 6:58 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to get Texture from Quad

Post by pgimeno »

A quad is mostly an object holding four coordinates and the width/height of a texture, but not the texture itself; you can use the same quad for different textures.

You can't send a quad to a shader. You can send the texture, and use Quad:getTextureDimensions and Quad:getViewport to send them to the shader and draw the correct texture fragment with some math.
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: How to get Texture from Quad

Post by Xii »

So what you're saying is, I need to edit the shader to draw only part of the texture?
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to get Texture from Quad

Post by pgimeno »

Yes, basically.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: How to get Texture from Quad

Post by ReFreezed »

To render a part of a texture you give love.graphics.draw both the texture and the quad. No shaders are required to do that. If you only give love.graphics.draw a texture then LÖVE automatically uses a quad that spans the whole texture.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: How to get Texture from Quad

Post by Xii »

Thank you for your assistance pgimeno, the shader now draws the specified part.
ReFreezed wrote: Sun Dec 13, 2020 6:39 pm To render a part of a texture you give love.graphics.draw both the texture and the quad. No shaders are required to do that. If you only give love.graphics.draw a texture then LÖVE automatically uses a quad that spans the whole texture.
The shader I have is a requirement. Not optional. Anyhow, the original issue is resolved.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to get Texture from Quad

Post by zorg »

Xii wrote: Sun Dec 13, 2020 6:57 pm Thank you for your assistance pgimeno, the shader now draws the specified part.
ReFreezed wrote: Sun Dec 13, 2020 6:39 pm To render a part of a texture you give love.graphics.draw both the texture and the quad. No shaders are required to do that. If you only give love.graphics.draw a texture then LÖVE automatically uses a quad that spans the whole texture.
The shader I have is a requirement. Not optional. Anyhow, the original issue is resolved.
Without explaining why, i can't really suggest otherwise, but this technically could work:

Code: Select all

function love.draw()
  love.graphics.setShader(yourShader)
  love.graphics.draw(yourImage, yourQuad, 0, 0)
end
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
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: How to get Texture from Quad

Post by Xii »

zorg wrote: Sun Dec 13, 2020 7:01 pm Without explaining why,
LÖVE's API to draw quads is awful. Shearing factors? What even is that? I have a custom solution of the form:

draw_textured_quad(texture, tx,ty,tw,th, x1,y1, x2,y2, x3,y3, x4,y4)

Which is much more convenient, as it allows arbitrary quad shapes by specifying the vertices' positions.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to get Texture from Quad

Post by slime »

Xii wrote: Sun Dec 13, 2020 7:42 pm LÖVE's API to draw quads is awful. Shearing factors? What even is that? I have a custom solution of the form:

draw_textured_quad(texture, tx,ty,tw,th, x1,y1, x2,y2, x3,y3, x4,y4)

Which is much more convenient, as it allows arbitrary quad shapes by specifying the vertices' positions.
This is shear. It's a niche feature, which is why the parameters for it are at the very end of the list in draw(): https://en.wikipedia.org/wiki/Shear_mapping

You can use a mesh if you want arbitrary shapes - you don't need a shader at all. However, with a shader or a mesh people will probably be confused when they expect perspective-correct texture mapping but get an affine mapping instead, since they didn't actually use real 3D coordinates. Meshes can do perspective-correct texture mapping as well, if you give it the right information and have a perspective projection matrix.
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: How to get Texture from Quad

Post by Xii »

slime wrote: Sun Dec 13, 2020 9:03 pm You can use a mesh if you want arbitrary shapes [...] Meshes can do perspective-correct texture mapping as well, if you give it the right information and have a perspective projection matrix.
What is the right information?
Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests