/*
 * Copyright information removed for SIGGRAPH anonymous review process.
 * This file is licensed under the GNU General Public License.
 */

/*
 * An example of Ardeco's generic rasterizer. We declare a ''Process" class
 * that simply draws pixels in an image. Ardeco uses similar "Process" 
 * classes to compute integrals, barycenters and pre-accumulated 
 * covariance matrices (it reads pixels values instead of changing them).
 * Classes to compute integrals are declared in "integral.h"
 */

#include "rasterizer.h"
#include "integral.h"

namespace OGF {
    class SetPixelProcess : public RasterizerProcess {
    public:
        SetPixelProcess() { } ;
        typedef int ResultType ;

        // This function is called for each pixel of the triangle.
        // x,y                        : pixel coordinates
        // p                           : pointer to pixel data in image
        // coverage in [0..1] : area of triangle/pixel intersection, 
        void pixel(int x, int y, Memory::pointer p, double coverage) {
            int col = int(coverage*255.0) ;
            p[0] = Memory::byte(col) ; // R
            p[1] = Memory::byte(col) ; // G
            p[2] = Memory::byte(col) ; // B
        }
    private:
    } ;
    
    typedef GenericRasterizer<SetPixelProcess> MyRasterizer ;
}

int main() {
    OGF::MyRasterizer rasterizer ;
    OGF::Image image(64,64,3) ;
    rasterizer.set_image(&image) ;

    rasterizer.begin_facet() ;
    rasterizer.vertex(OGF::Vec2(0.5, 0)) ;
    rasterizer.vertex(OGF::Vec2(1, 1)) ;
    rasterizer.vertex(OGF::Vec2(0, 1)) ;
    rasterizer.end_facet() ;

    image.save_as_rgb("out.rgb") ;

    return 0 ;
}

