We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The texture image is just a simple ellipse (link). As you can see as soon as I wrap it on the deformed plane it looks broken
Here's my code. pg is just an image with the ellipse.
textureMode(NORMAL);
beginShape(TRIANGLE_FAN);
texture(pg);
vertex(30,20, 0, 0);
vertex(680,62, 1, 0);
vertex(629,478, 1, 1);
vertex(158,499, 0, 1);
endShape();
IMHO I was expecting a result like my mockup (link). What am I doing wrong here?
Answers
Try rendering it as a QUAD instead of a TRIANGLE_FAN.
Try Using OPENGL render instead of P3D.
YMMV.
I changed it to beginShape(QUAD); and the renderer to OPENGL instead of P2D
Still bent
known problem, and not just a processing problem: https://en.wikipedia.org/wiki/Texture_mapping#Perspective_correctness
(i thought this was better in later versions and with opengl. which version are you using?)
it also helps having more, smaller quads, if that's an option. and try using the 3d version of vertex() with z = 0
It's just as bad with z=0.
I'm using processing 2.2.1
My system has OpenGL 4.4 installed.
This affine texture mapping problem seems like something from the 90s. I can't believe I ran into this bug like this. Is there really no fix in processing? Maybe there's a texture mode I can switch.
I tried all of the above and various hint () and smooth() settings with no luck.
I'm sure I've fixed it before, maybe using raw opengl.
Oddly, the textured cube example used to suffer from the same problem but now doesn't. I think that may be using javascript mode now though.
Going through your history I did find this thread: http://forum.processing.org/two/discussion/comment/32599/#Comment_32599
The last post talks about fixing it by not using the processing libraries and instead using a java library for rendering. The fix is kind of headscratchingly odd. I'd much rather have a "native" solution that doesn't use external libraries.
The link you provide is not the solution to your problem because it distorts the image that you want to use as a texture.
In 3D the quad is not 'distorted' rather a perspective transformation is applied to the quad so the texture is unaffected. In 2D the quad is deformed so you get distortion along the diagonal.
The only way I have found to solve this problem is to slice the quad into smaller quads. I also use TRIANGLE_STRIP because it makes the code more succinct.
This is the output from the program below
The first image is using the OpenGL QUAD, the second uses OpenGL TRIANGLE_STRIP (2 triangles) and the last one uses a computed grid to give 200 triangles.
If to want to animate the shape then you can call the setCorners method as many times as you like.
The sketch has 2 tabs
Main tab code
QuadGrid.java tab
quark that is a thing of beauty.
Thank you very much for this. It fixed everything and gave me some fine ideas of where to take this program. :-bd
Well done! This one should be included in some library in the default code :)