8.10
13 RRLL: Rasterizer
Racket Rogue-Like Library: Rasterizer for 3D renderer.
13.1 Rasterizer
(require rrll/rasterizer) | package: rrll-rasterizer |
This module implements rasterization of triangles in screen coordinates.
procedure
(make-rasterizer can [ num-futures #:defer-alpha defer-alpha?]) → rasterizer? can : canvas? num-futures : positive-integer? = (processor-count) defer-alpha? : boolean? = #t
Creates a rasterizer for single rendering.
If defer-alpha? is #t, rasterization of triangles needing alpha blending is postponed until the finish-rasterizer call.
Returns #t if given value is a rasterizer struct.
Waits until all pending operations on given rasterizer finished.
Sends triangle to given rasterizer for processing.
If setw is #f, the w-buffer is only tested but not updated.
procedure
(raster-quad rst x1 y1 w1 x2 y2 w2 x3 y3 w3 x4 y4 w4 [ #:color color #:c1 c1 #:c2 c2 #:c3 c3 #:c4 c4 #:u1 u1 #:u2 u2 #:u3 u3 #:u4 u4 #:v1 v1 #:v2 v2 #:v3 v3 #:v4 v4 #:tex tex #:blending blending #:alpha alpha #:id id #:setw setw]) → void? rst : rasterizer? x1 : fixnum? y1 : fixnum? w1 : flonum? x2 : fixnum? y2 : fixnum? w2 : flonum? x3 : fixnum? y3 : fixnum? w3 : flonum? x4 : fixnum? y4 : fixnum? w4 : flonum? color : fixnum? = 16711935 c1 : (or/c fixnum? #f) = #f c2 : (or/c fixnum? #f) = #f c3 : (or/c fixnum? #f) = #f c4 : (or/c fixnum? #f) = #f u1 : (or/c flonum? #f) = #f u2 : (or/c flonum? #f) = #f u3 : (or/c flonum? #f) = #f u4 : (or/c flonum? #f) = #f v1 : (or/c flonum? #f) = #f v2 : (or/c flonum? #f) = #f v3 : (or/c flonum? #f) = #f v4 : (or/c flonum? #f) = #f tex : (or/c mipmap? #f) = #f blending : boolean? = #f alpha : (or/c (integer-in 0 255) #f) = #f id : fixnum? = 0 setw : boolean = #t
Sends two triangles comprising the quad to the rasterizer. The
triangles are composed of (1 2 3) and (1 3 4)
vertices.
procedure
(raster-line rst x0 y0 w0 x1 y1 w1 [ #:color color #:w-bias w-bias #:blending blending #:alpha alpha #:id id]) → void? rst : rasterizer? x0 : fixnum? y0 : fixnum? w0 : flonum? x1 : fixnum? y1 : fixnum? w1 : flonum? color : fixnum? = 4278190080 w-bias : flonum? = 1.024 blending : boolean? = #f alpha : (or/c (integer-in 0 255) #f) = #f id : (or/c fixnum? #f) = #f
Renders a 2D line with given W-coordinates gradient. The
w-bias is used to ensure the line is always drawn even when
the triangle of the same depth is already drawn onto the
canvas?.
13.2 Usage
The rasterizer? must be used with canvas? in order to rasterizer triangles. The common setup is:
(define can (make-canvas 320 240)) (define rst (make-rasterizer can)) ... (finish-rasterizer rst)
13.2.1 Triangle Filled with Single Color
(raster-triangle rst 20 20 1.0 40 220 1.0 300 50 1.0 #:color 52479)

13.2.2 Alpha Blending Triangles Filled with Single Color
(raster-triangle rst 20 20 2.0 40 220 2.0 300 50 2.0 #:color 16711680) (raster-triangle rst 280 30 1.0 10 90 1.0 310 230 1.0 #:color 65280 #:alpha 127)

13.2.3 Smoothly-Colored Triangles
(raster-triangle rst 20 220 1.0 300 180 1.0 140 20 1.0 #:c1 16711680 #:c2 65280 #:c3 255)

13.2.4 Alpha Blending Smoothly-Colored Triangles
(raster-triangle rst 20 220 2.0 300 180 2.0 140 20 2.0 #:c1 16711680 #:c2 65280 #:c3 255) (raster-triangle rst 20 20 1.0 140 220 1.0 300 50 1.0 #:c1 16776960 #:c2 65535 #:c3 16711935 #:alpha 127)
