(gl:shade-model 'SMOOTH) ; Enable Smooth Shading
;;(gl:shade-model 'FLAT)
(gl:clear-color (color .527 .805 .977 1.)) ; light sky blue: #x87cefa
- (gl:clear-depth 1.) ; Depth Buffer Setup
- (gl:enable 'DEPTH-TEST) ; Enables Depth Testing
- (gl:depth-func 'LEQUAL) ; The Type Of Depth Testing To Do
- ;;(gl:enable 'CULL-FACE)
- ;;(gl:cull-face 'BACK)
+ (gl:enable 'DEPTH-TEST)
+ (gl:enable 'CULL-FACE)
;; Really Nice Perspective Calculations
(gl:hint 'PERSPECTIVE-CORRECTION 'NICEST)
- (gl:light 'LIGHT0 'AMBIENT (color .4 .4 .4 1.))
- (gl:light 'LIGHT0 'DIFFUSE (color 1. 1. 1. 1.))
- (gl:light 'LIGHT0 'SPECULAR (color 1. 1. 1. 1.))
(gl:light 'LIGHT0 'POSITION (terrain-viewport-light-position widget))
(gl:light-model 'LOCAL-VIEWER 1.)
(gl:enable 'LIGHTING)
#t)
(define-method glx-viewport-draw ((widget <terrain-viewport>))
- (with-glx-widget widget
- (lambda ()
- (gl:call-list (terrain-viewport-mesh widget))))
+ (%trace2 "; (glx-viewport-draw <terrain-viewport>)\n")
+ (gl:call-list (terrain-viewport-mesh widget))
(update-label widget))
(define (update-label widget)
+ (%trace2 "; update-label\n")
(let ((origin (terrain-viewport-origin widget))
(pos (glx-viewport-position widget))
(d/m (flo:/ (terrain-viewport-step-degrees widget)
(define (draw-colored widget)
(%trace "; draw-colored "widget"\n")
- (let ((step (terrain-viewport-step-meters widget))
- (matrix (terrain-viewport-matrix widget))
+ (let ((matrix (terrain-viewport-matrix widget))
(rows (terrain-viewport-rows widget))
- (columns (terrain-viewport-columns widget)))
- (let ((-step (flo:- 0. step)))
+ (columns (terrain-viewport-columns widget))
+ (step (terrain-viewport-step-meters widget))
+ (-step (flo:- 0. (terrain-viewport-step-meters widget))))
- (define (vertex x y)
- (let ((h (matrix-ref matrix columns x y)))
- (gl:color (height-color widget h))
- (gl:vertex (flo:3d (flo:* (->flonum x) step)
- h
- (flo:* (->flonum y) -step)))))
-
- (gl:color-material 'FRONT 'DIFFUSE)
- (gl:enable 'COLOR-MATERIAL)
- (gl:begin 'QUADS)
- (let ((last-row (fix:- rows 2))
- (last-column (fix:- columns 2)))
- (do ((y 0 (fix:1+ y)))
- ((fix:= y last-row))
- (do ((x 0 (fix:1+ x)))
- ((fix:= x last-column))
-;;; (gl:begin 'LINE-LOOP)
- (vertex x y)
- (vertex (fix:1+ x) y)
- (vertex (fix:1+ x) (fix:1+ y))
- (vertex x (fix:1+ y))
-;;; (gl:end)
- )))
- (gl:end)
- (gl:disable 'COLOR-MATERIAL)
- (draw-sea-level widget))))
+ (define (vertex x y)
+ (let ((h (matrix-ref matrix columns x y)))
+ (gl:color (height-color widget h))
+ (gl:vertex (flo:3d (flo:* (->flonum x) step)
+ h
+ (flo:* (->flonum y) -step)))))
+
+ (%trace "; begin quads\n")
+ (gl:begin 'QUADS)
+ (let ((last-row (fix:- rows 2))
+ (last-column (fix:- columns 2)))
+ (do ((y 0 (fix:1+ y)))
+ ((fix:= y last-row))
+ (do ((x 0 (fix:1+ x)))
+ ((fix:= x last-column))
+ (vertex x y)
+ (vertex (fix:1+ x) y)
+ (vertex (fix:1+ x) (fix:1+ y))
+ (vertex x (fix:1+ y))
+ )))
+ (gl:end)
+ (%trace "; end quads\n")
+ ;;(draw-sea-level widget)
+ ))
(define (draw-sea-level widget)
;; A translucent blue plane at sea level.
- (declare (ignore widget))
- unspecific
- #;(let ((rows (terrain-viewport-rows widget))
+ (%trace "; draw-sea-level\n")
+ (let ((rows (terrain-viewport-rows widget))
(columns (terrain-viewport-columns widget))
(step (terrain-viewport-step-meters widget)))
(%trace "; disabling LIGHTING\n")
(ref (fix:1+ x) y) ; west
(ref x (fix:1+ y)) ; north
(ref x (fix:-1+ y)))) ; south
- (gl:color (height-color widget h))
(gl:vertex (flo:3d (flo:* (->flonum x) step)
h
(flo:* (->flonum y) -step)))))
- (gl:material 'FRONT-AND-BACK 'SPECULAR (flo:4d 1. 1. 1. 1.))
- (gl:material 'FRONT 'SHININESS 128.0)
- (gl:material 'FRONT-AND-BACK 'AMBIENT (flo:4d .1 .1 .1 1.))
- (gl:material 'FRONT-AND-BACK 'DIFFUSE (flo:4d 1. 1. 1. 1.))
- (gl:color-material 'FRONT-AND-BACK 'AMBIENT-AND-DIFFUSE)
- (gl:enable 'COLOR-MATERIAL)
+ (gl:enable 'NORMALIZE)
+ (%trace "; begin quads\n")
(gl:begin 'QUADS) ; or LINES for wireframe
(let ((last-row (fix:- rows 2))
(last-column (fix:- columns 2)))
(vertex (fix:1+ x) (fix:1+ y))
(vertex x (fix:1+ y)))))
(gl:end)
- (gl:disable 'COLOR-MATERIAL)
- (draw-sea-level widget)))
+ (%trace "; end quads\n")
+ ;;(draw-sea-level widget)
+ ))
(define (normal step height east west north south)
(let ((-step (flo:- 0. step)))
(define %trace? #t)
-(define (%trace . msg)
- (if %trace? (for-each display msg)))
\ No newline at end of file
+(define-syntax %trace
+ (syntax-rules ()
+ ((_ . MSG)
+ (if %trace? ((lambda () (outf-error . MSG)))))))
+
+(define %trace2? #f)
+
+(define-syntax %trace2
+ (syntax-rules ()
+ ((_ . MSG)
+ (if %trace2? ((lambda () (outf-error . MSG)))))))
\ No newline at end of file