Polygon vertices as UV coordinates
3d, graphics, java, swing
Solution
You may be able to leverage `java.awt.TexturePaint`, illustrated here and here. In this context, you should know that `TexturePaint` aligns with the rendering surface's raster, rather than the shape's bounds.
Addendum: While shading is a broad topic, also consider a pixel-based approach using gradient shading with alpha, illustrated in the `KineticModel` cited here. Note that such a gradient can be applied to the `WritableRaster` of a `TexturePaint`.
For non-affine transformations, see `javax.media.jai.Warp.Warp`, cited here.
Problem
I am working on a 3D renderer in Java using the Graphics class, It is now capable of drawing any shape with coloured faces, however I was wondering if it was possible to texture the faces? I have seen a lot of people creating software renderers in Javascript so surely there is an equivalent function/method of however they are doing it in Java... I have looked around so far but all I can find is Graphics.setClip(Shape), I don't think it would be suitable because it merely sets the background texture and wouldn't stretch the texture if a vertex moved - and that's just in 2D, it need to also stretch/skew the texture when it's at an angle to the camera (Think of the sides of a rotating cube). I really have no idea where to start, I can't use XOR modes because of no skewing and I really wouldn't know how to do the math if I had to do it manually. How do these Javascript software renderers do it so well?