use new get-argb-pixels to convert bitmap to GL

svn: r4743
This commit is contained in:
Matthew Flatt 2006-11-01 23:04:12 +00:00
parent 166f2ea539
commit 33e75ab6ec
2 changed files with 21 additions and 14 deletions

View File

@ -4,7 +4,8 @@
(lib "class.ss") (lib "class.ss")
(lib "gl-vectors.ss" "sgl") (lib "gl-vectors.ss" "sgl")
(prefix gl- (lib "sgl.ss" "sgl")) (prefix gl- (lib "sgl.ss" "sgl"))
(lib "gl.ss" "sgl")) (lib "gl.ss" "sgl")
(lib "kw.ss"))
(provide bitmap->gl-list) (provide bitmap->gl-list)
@ -20,22 +21,22 @@
(loop (+ i 4)))) (loop (+ i 4))))
rgba)) rgba))
(define (bitmap->argb bmp) (define (bitmap->argb bmp bmp-mask)
(let* ((width (send bmp get-width)) (let* ((width (send bmp get-width))
(height (send bmp get-height)) (height (send bmp get-height))
(argb (make-bytes (* 4 width height) 255)) (argb (make-bytes (* 4 width height) 255)))
(dc (make-object bitmap-dc% bmp))) (send bmp get-argb-pixels 0 0 width height argb #f)
(send dc get-argb-pixels 0 0 width height argb #f) (when bmp-mask
(when (send bmp get-loaded-mask) (send bmp-mask get-argb-pixels 0 0 width height argb #t))
(send dc set-bitmap (send bmp get-loaded-mask))
(send dc get-argb-pixels 0 0 width height argb #t))
(send dc set-bitmap #f)
argb)) argb))
(define (bitmap->gl-list bm with-gl) (define/kw (bitmap->gl-list bm
#:key
[with-gl (lambda (f) (f))]
[mask (send bm get-loaded-mask)])
(let ([w (send bm get-width)] (let ([w (send bm get-width)]
[h (send bm get-height)] [h (send bm get-height)]
[rgba (argb->rgba (bitmap->argb bm))]) [rgba (argb->rgba (bitmap->argb bm mask))])
(with-gl (with-gl
(lambda () (lambda ()
(let ((tex (gl-vector-ref (glGenTextures 1) 0)) (let ((tex (gl-vector-ref (glGenTextures 1) 0))

View File

@ -277,14 +277,20 @@ _bitmap.ss_
The "bitmap.ss" library in the "sgl" collection provides a helper The "bitmap.ss" library in the "sgl" collection provides a helper
function for converting a MrEd bitmap to a GL list: function for converting a MrEd bitmap to a GL list:
> (bitmap->gl-list bitmap with-gl-proc) > (bitmap->gl-list bitmap #:with-gl with-gl-proc
#:mask bitmap)
Converts the given bitmap (an instance of bitmap%) into a GL list that Converts the given bitmap (an instance of bitmap%) into a GL list that
can be rendered with `call-list' or `glCallList'. The rendered object can be rendered with `call-list' or `glCallList'. The rendered object
is a square on the z=0 plane with corners at (0,0) and (1,1). is a square on the z=0 plane with corners at (0,0) and (1,1).
The given `with-gl-proc' function must accept a thunk and call it If `with-gl-proc' is provided, it must accept a thunk and call it
while the relevant GL context is selected. while the relevant GL context is selected. Otherwise, the relevant GL
context must be selected already.
If `mask' is given, it is used as the mask bitmap (for extracting
alpha values). The default is the result of the `get-loaded-mask'
method of `bm'.
================================================================= =================================================================
Function indexes Function indexes