SFML community forums

Help => Graphics => Topic started by: Alex-Mart on May 18, 2018, 02:42:01 am

Title: How to draw a texture to a quad without weird deformation
Post by: Alex-Mart on May 18, 2018, 02:42:01 am
I want to draw a sf::Texture to a simple sf::VertexArray/ sf::Quad, like the attached image shows, but if i simply map the quads vertexes to the texture it doesn't draw my quad like the image because the quad is divided into two triangles and that deforms the texture, causing a split in the middle, how can I avoid this?
Thank you in advance.

P.S: I've also tried to draw 4 difrent triangles and a triangle fan with 6 points with the 0 in the middle and the vertex 1 being equal to the 5th
Title: Re: How to draw a texture to a quad without weird deformation
Post by: AlejandroCoria on May 18, 2018, 03:44:43 am
I think that in order to have the correct deformation 3d is needed. You should look Sprite 3D (https://github.com/Hapaxia/SelbaWard/wiki/Sprite-3D) from SelbaWard.
Title: Re: How to draw a texture to a quad without weird deformation
Post by: Alex-Mart on May 18, 2018, 03:49:08 am
I think that in order to have the correct deformation 3d is needed. You should look Sprite 3D (https://github.com/Hapaxia/SelbaWard/wiki/Sprite-3D) from SelbaWard.

I don't actually want to do a 3D transform on the texture, just to have it interpolate between all 4 vertexes instead of 3, maybe a shader could do that?
I'm not sure...
Title: Re: How to draw a texture to a quad without weird deformation
Post by: AlejandroCoria on May 18, 2018, 03:59:17 am
I think ElasticSprite of SelbaWard does it in 2d. You should check their code.
Title: Re: How to draw a texture to a quad without weird deformation
Post by: Stauricus on May 22, 2018, 12:10:10 am
can't you just use TriangleStrip? add vertices to the VertexArray in this order:
A: -1, -1
B: 1, -1
C: -1, 1
D: 1, 1
Title: Re: How to draw a texture to a quad without weird deformation
Post by: Hapax on May 24, 2018, 05:24:22 pm
Yes, Selba Ward's Elastic Sprite (https://github.com/Hapaxia/SelbaWard/wiki/Elastic-Sprite) does just this - interpolates the texture using four points instead of three.

For examples,

Bi-linear interpolation (default):
(http://i.imgur.com/zodshBH.png)

Perspective interpolation (if required instead):
(http://i.imgur.com/gcg39PI.png)