Basically, I’d like to do gouraud shading with triangles in java. I am aware of the 2 point gradient in Graphics2D, but I am not sure what to do for 3 points . Please reply if you know a way to do this or an effective alternative. (I am not using and do not intend to use java3D)
Do you want to shade with GradientPaint using 3 color gradients or are you talking about orienting the shading with regards to 3 vertices of your triangle?
I’d like a gradient based on 3 points each a different color. So, the second one.
A gourad-shaded triangle, then.
Cas
[quote]A gourad-shaded triangle, then.
Cas
[/quote]
I’m not aware of any utility class in the java2d library that does gouraud-shading based on 3 non-collinear points. So if you’re planning on sticking with java2D to do your shading, then the most straightforward way would be to either:
-
Extend the Paint and PaintContext interfaces with your own GouraudShading class that draws a pixel with a certain color based on the distance between 3 (or more) points. This should be somewhat similar to the method used by java2D’s GradientPaint.
-
Forget about extending interfaces in the java2D library and build your own scan-converter/rasterizer that colors a pixel with a certain color based on the distance between 3 or more points. There should be lots of tutorials on the web that shows you how to perform scan-conversion of triangles if you’re unsure how.
Are you doing real-time 3D? I recommend you take a look at other user-made OpenGL-based libraries like JOGL or LWJGL or Xith3D. Java2D’s no good for that kind of thing (hence “java2D”).