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.
[solved] How to get Texture from Quad
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[solved] How to get Texture from Quad
Last edited by Xii on Sun Dec 13, 2020 6:58 pm, edited 1 time in total.
Re: How to get Texture from Quad
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.
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.
Re: How to get Texture from Quad
So what you're saying is, I need to edit the shader to draw only part of the texture?
Re: How to get Texture from Quad
Yes, basically.
Re: How to get Texture from Quad
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."
"If each mistake being made is a new one, then progress is being made."
Re: How to get Texture from Quad
Thank you for your assistance pgimeno, the shader now draws the specified part.
The shader I have is a requirement. Not optional. Anyhow, the original issue is resolved.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.
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to get Texture from Quad
Without explaining why, i can't really suggest otherwise, but this technically could work:Xii wrote: ↑Sun Dec 13, 2020 6:57 pm Thank you for your assistance pgimeno, the shader now draws the specified part.
The shader I have is a requirement. Not optional. Anyhow, the original issue is resolved.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.
Code: Select all
function love.draw()
love.graphics.setShader(yourShader)
love.graphics.draw(yourImage, yourQuad, 0, 0)
end
Me and my stuff True 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.
Re: How to get Texture from Quad
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.
- 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
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_mappingXii 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.
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.
Who is online
Users browsing this forum: No registered users and 83 guests