source: project/nondescript/gl-font/gl-font.scm @ 35339

Last change on this file since 35339 was 3730, checked in by thu, 14 years ago

beginning of unicode support -- code need to be cleaned

File size: 2.5 KB
Line 
1;;; gl-font.scm
2;;; 2007-02-25 - 2007-02-27
3;;;
4;;; The intent of this file is to provide a FreeType
5;;; based font.
6
7(require 'lolevel)
8(require 'srfi-4)
9(require 'gl)
10
11(declare
12  (uses srfi-1)
13  (export
14    gl-font:create
15    gl-font:create-from-path
16    gl-font:create-from-path/ascii
17    gl-font:print
18    gl-font:print/ansi
19    gl-font:print/ascii
20
21    textured-square-xy
22    )
23  )
24
25#>
26#include "gl_font.h"
27<#
28
29(define gl-font:create
30  (foreign-lambda void "create_font"))
31(define gl-font:create-from-path
32  (foreign-lambda c-pointer "create_font_from_path" c-string))
33(define gl-font:create-from-path/ascii
34  (foreign-lambda void "create_font_from_path_ascii" c-string))
35(define gl-font:print/ascii                                    ; ascii
36  (foreign-lambda void "gl_print_ascii" c-string))
37(define gl-font:print/ansi                                     ; ascii with ansi escape codes
38  (foreign-lambda void "gl_print_ansi" c-string))
39(define gl-font:print                                          ; unicode with ansi escape codes
40  (foreign-lambda void "gl_print" c-pointer c-string))
41
42;
43
44(define font-texture (make-u32vector 1))
45(define width 256)
46(define height 256)
47(define data (make-byte-vector (* width height) 0))
48(define (byte-vector-map! f vec)
49  (let loop ((i 0))
50    (when (< i (byte-vector-length vec))
51      (byte-vector-set! vec i (f (byte-vector-ref vec i)))
52      (loop (+ i 1)))))
53(byte-vector-map! (lambda _ (random 256)) data)
54(gl:GenTextures 1 font-texture)
55(gl:BindTexture gl:TEXTURE_2D (u32vector-ref font-texture 0))
56(gl:PixelStorei gl:UNPACK_ALIGNMENT   1)
57(gl:PixelStorei gl:UNPACK_ROW_LENGTH  0)
58(gl:PixelStorei gl:UNPACK_SKIP_PIXELS 0)
59(gl:PixelStorei gl:UNPACK_SKIP_ROWS   0)
60(gl:TexImage2D gl:TEXTURE_2D 0 gl:INTENSITY8 width height 0 gl:LUMINANCE  gl:UNSIGNED_BYTE (make-locative data))
61(gl:TexParameteri gl:TEXTURE_2D gl:TEXTURE_MAG_FILTER gl:LINEAR)
62(gl:TexParameteri gl:TEXTURE_2D gl:TEXTURE_MIN_FILTER gl:LINEAR)
63(gl:TexParameteri gl:TEXTURE_2D gl:TEXTURE_WRAP_S gl:CLAMP)
64(gl:TexParameteri gl:TEXTURE_2D gl:TEXTURE_WRAP_T gl:CLAMP)
65
66; Draw a square on the x/y plane. Size is given in argument.
67(define (textured-square-xy size)
68  (gl:BindTexture gl:TEXTURE_2D (u32vector-ref font-texture 0))
69  (gl:Enable gl:TEXTURE_2D)
70  (let ((-s (/ (- size) 2))
71        (s (/ size 2)))
72    (gl:Begin gl:QUADS)
73      (gl:TexCoord2f 0 0)
74      (vertex -s -s)
75      (gl:TexCoord2f 1 0)
76      (vertex  s -s)
77      (gl:TexCoord2f 1 1)
78      (vertex  s  s)
79      (gl:TexCoord2f 0 1)
80      (vertex -s  s)
81    (gl:End))
82  (gl:Disable gl:TEXTURE_2D))
83
Note: See TracBrowser for help on using the repository browser.