Check-in [fd1cd6736c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some changes to freetype-gl stuff
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fd1cd6736c3892dec895075a730403d4b09a1e7f
User & Date: bernd 2013-11-26 23:02:15
Context
2013-11-27
00:21
Uniform program for text and normal textures check-in: 2e267bcf9f user: bernd tags: trunk
2013-11-26
23:02
Some changes to freetype-gl stuff check-in: fd1cd6736c user: bernd tags: trunk
18:23
Freetype for 32 and 64 bits check-in: c2b9a73492 user: bernd tags: trunk
Changes

Changes to ftgl-helper.fs.

16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47

48
49
50
51
52
53

54
55





56
57
58
59
60
61
62
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

also freetype-gl
also opengl

512 Value atlas#

atlas# dup 1 texture_atlas_new Value atlas
tex: atlas-tex
atlas-tex current-tex atlas texture_atlas_t-id !


\ render font into vertex buffers

2Variable penxy
Variable color $FFC0A000 color !

: xy, { glyph -- }
    penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    glyph texture_glyph_t-offset_x @ s>f
    glyph texture_glyph_t-offset_y @ s>f { f: xo f: yo }
    glyph texture_glyph_t-width  @ s>f
    glyph texture_glyph_t-height @ s>f { f: w f: h }    
    xp xo f+  yp yo f- { f: x0 f: y0 }
    x0 w f+ y0 h f+ { f: x1 f: y1 }
    glyph texture_glyph_t-s0 sf@ { f: s0 }
    glyph texture_glyph_t-t0 sf@ { f: t0 }
    glyph texture_glyph_t-s1 sf@ { f: s1 }
    glyph texture_glyph_t-t1 sf@ { f: t1 }
    >v
    x0 y0 >xy n> color @ rgba>c s0 t0 >st v+

    x0 y1 >xy n> color @ rgba>c s0 t1 >st v+
    x1 y1 >xy n> color @ rgba>c s1 t1 >st v+
    x1 y0 >xy n> color @ rgba>c s1 t0 >st v+  v>

    xp glyph texture_glyph_t-advance_x sf@ f+ penxy sf!
    yp glyph texture_glyph_t-advance_y sf@ f+ penxy sfloat+ sf! ;

: glyph+xy ( glyph -- )
    buf^ array-buf - vertex-c @ / >r
    xy,

    r@ i, r@ 1 + i, r@ 2 + i,
    r@ i, r@ 2 + i, r> 3 + i, ;






0 Value font

: xchar+xy ( prev-xchar xchar -- xchar )
    tuck font swap texture_font_get_glyph >r
    dup 0> IF  r@ swap texture_glyph_get_kerning
	penxy sf@ f+ penxy sf!
................................................................................
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
// The entry point for our fragment shader.
void main()
{
    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
    gl_FragColor.rgb = v_Color.rgb;
}

' VertexShader ' textFragmentShader create-program Value textprogram
textprogram init

: <render ( -- )
    textprogram glUseProgram
    .01e 100e 100e >ap
    atlas-tex v0 i0 ;

: render> ( -- )  GL_TRIANGLES draw-elements ;

previous previous







|
|
>



|




|
|
|
|








>


<
>




|
<
>
|
|
>
>
>
>
>







 







|













16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

also freetype-gl
also opengl

512 Value atlas#

atlas# dup 1 texture_atlas_new Value atlas
." Textur in Atlas: " atlas texture_atlas_t-id l@ . cr
: atlas-tex  atlas texture_atlas_t-id l@ dup to current-tex
    GL_TEXTURE_2D swap glBindTexture ;

\ render font into vertex buffers

2 sfloats buffer: penxy
Variable color $FFC0A000 color !

: xy, { glyph -- }
    penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    glyph texture_glyph_t-offset_x l@ s>f
    glyph texture_glyph_t-offset_y l@ s>f { f: xo f: yo }
    glyph texture_glyph_t-width  l@ s>f
    glyph texture_glyph_t-height l@ s>f { f: w f: h }    
    xp xo f+  yp yo f- { f: x0 f: y0 }
    x0 w f+ y0 h f+ { f: x1 f: y1 }
    glyph texture_glyph_t-s0 sf@ { f: s0 }
    glyph texture_glyph_t-t0 sf@ { f: t0 }
    glyph texture_glyph_t-s1 sf@ { f: s1 }
    glyph texture_glyph_t-t1 sf@ { f: t1 }
    >v
    x0 y0 >xy n> color @ rgba>c s0 t0 >st v+
    x1 y0 >xy n> color @ rgba>c s1 t0 >st v+
    x0 y1 >xy n> color @ rgba>c s0 t1 >st v+
    x1 y1 >xy n> color @ rgba>c s1 t1 >st v+

    v>
    xp glyph texture_glyph_t-advance_x sf@ f+ penxy sf!
    yp glyph texture_glyph_t-advance_y sf@ f+ penxy sfloat+ sf! ;

: glyph+xy ( glyph -- )
    i>off  xy,  2 quad ;


: all-glyphs ( -- )
    i>off >v
    0e 0e >xy n> color @ rgba>c 0e 0e >st v+
    512e 0e >xy n> color @ rgba>c 1e 0e >st v+
    0e 512e >xy n> color @ rgba>c 0e 1e >st v+
    512e 512e >xy n> color @ rgba>c 1e 1e >st v+
    v> 2 quad ;

0 Value font

: xchar+xy ( prev-xchar xchar -- xchar )
    tuck font swap texture_font_get_glyph >r
    dup 0> IF  r@ swap texture_glyph_get_kerning
	penxy sf@ f+ penxy sf!
................................................................................
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
// The entry point for our fragment shader.
void main()
{
    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
//    gl_FragColor.rgb = v_Color.rgb;
}

' VertexShader ' textFragmentShader create-program Value textprogram
textprogram init

: <render ( -- )
    textprogram glUseProgram
    .01e 100e 100e >ap
    atlas-tex v0 i0 ;

: render> ( -- )  GL_TRIANGLES draw-elements ;

previous previous

Changes to ftgl-sample.fs.

1
2
3
4
5
6
7
8
9
10
11
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
\ freetype GL example

require gl-helper.fs
window-init

require ftgl-helper.fs

\ Demo Toplevel

also freetype-gl
also opengl
................................................................................
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/bkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2

Variable text1$ "Dös isch a Tägscht." text1$ $!
Variable text2$ "这是一个文本:在德语说" text2$ $!

: glyph-draw ( -- )
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    <render
    0. penxy 2!
    font1 to font  text1$ $@ render-string
    -100e penxy sf! -60e penxy sfloat+ sf!
    font2 to font  text2$ $@ render-string
    render> sync ;

: glyph-demo ( -- ) [IFDEF] hidekb  hidekb [THEN]
    1 level# +!  BEGIN  glyph-draw  >looper  level# @ 0= UNTIL ;

previous previous previous



|







 







|











|









1
2
3
4
5
6
7
8
9
10
11
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
\ freetype GL example

require gl-helper.fs
[IFUNDEF] android window-init [THEN]

require ftgl-helper.fs

\ Demo Toplevel

also freetype-gl
also opengl
................................................................................
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2

Variable text1$ "Dös isch a Tägscht." text1$ $!
Variable text2$ "这是一个文本:在德语说" text2$ $!

: glyph-draw ( -- )
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    <render
    0e penxy sf!  0e penxy sfloat+ sf!
    font1 to font  text1$ $@ render-string
    -100e penxy sf! -60e penxy sfloat+ sf!
    font2 to font  text2$ $@ render-string
    render> sync ;

: glyph-demo ( -- ) [IFDEF] hidekb  hidekb [THEN]
    1 level# +!  BEGIN  glyph-draw  >looper  level# @ 0= UNTIL ;

previous previous previous

Changes to gles2/ftgl-helper.fs.

16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47

48
49
50
51
52
53

54
55





56
57
58
59
60
61
62
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

also freetype-gl
also opengl

512 Value atlas#

atlas# dup 1 texture_atlas_new Value atlas
tex: atlas-tex
atlas-tex current-tex atlas texture_atlas_t-id !


\ render font into vertex buffers

2Variable penxy
Variable color $FFC0A000 color !

: xy, { glyph -- }
    penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    glyph texture_glyph_t-offset_x @ s>f
    glyph texture_glyph_t-offset_y @ s>f { f: xo f: yo }
    glyph texture_glyph_t-width  @ s>f
    glyph texture_glyph_t-height @ s>f { f: w f: h }    
    xp xo f+  yp yo f- { f: x0 f: y0 }
    x0 w f+ y0 h f+ { f: x1 f: y1 }
    glyph texture_glyph_t-s0 sf@ { f: s0 }
    glyph texture_glyph_t-t0 sf@ { f: t0 }
    glyph texture_glyph_t-s1 sf@ { f: s1 }
    glyph texture_glyph_t-t1 sf@ { f: t1 }
    >v
    x0 y0 >xy n> color @ rgba>c s0 t0 >st v+

    x0 y1 >xy n> color @ rgba>c s0 t1 >st v+
    x1 y1 >xy n> color @ rgba>c s1 t1 >st v+
    x1 y0 >xy n> color @ rgba>c s1 t0 >st v+  v>

    xp glyph texture_glyph_t-advance_x sf@ f+ penxy sf!
    yp glyph texture_glyph_t-advance_y sf@ f+ penxy sfloat+ sf! ;

: glyph+xy ( glyph -- )
    buf^ array-buf - vertex-c @ / >r
    xy,

    r@ i, r@ 1 + i, r@ 2 + i,
    r@ i, r@ 2 + i, r> 3 + i, ;






0 Value font

: xchar+xy ( prev-xchar xchar -- xchar )
    tuck font swap texture_font_get_glyph >r
    dup 0> IF  r@ swap texture_glyph_get_kerning
	penxy sf@ f+ penxy sf!
................................................................................
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
// The entry point for our fragment shader.
void main()
{
    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
    gl_FragColor.rgb = v_Color.rgb;
}

' VertexShader ' textFragmentShader create-program Value textprogram
textprogram init

: <render ( -- )
    textprogram glUseProgram
    .01e 100e 100e >ap
    atlas-tex v0 i0 ;

: render> ( -- )  GL_TRIANGLES draw-elements ;

previous previous







|
|
>



|




|
|
|
|








>


<
>




|
<
>
|
|
>
>
>
>
>







 







|













16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

also freetype-gl
also opengl

512 Value atlas#

atlas# dup 1 texture_atlas_new Value atlas
." Textur in Atlas: " atlas texture_atlas_t-id l@ . cr
: atlas-tex  atlas texture_atlas_t-id l@ dup to current-tex
    GL_TEXTURE_2D swap glBindTexture ;

\ render font into vertex buffers

2 sfloats buffer: penxy
Variable color $FFC0A000 color !

: xy, { glyph -- }
    penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    glyph texture_glyph_t-offset_x l@ s>f
    glyph texture_glyph_t-offset_y l@ s>f { f: xo f: yo }
    glyph texture_glyph_t-width  l@ s>f
    glyph texture_glyph_t-height l@ s>f { f: w f: h }    
    xp xo f+  yp yo f- { f: x0 f: y0 }
    x0 w f+ y0 h f+ { f: x1 f: y1 }
    glyph texture_glyph_t-s0 sf@ { f: s0 }
    glyph texture_glyph_t-t0 sf@ { f: t0 }
    glyph texture_glyph_t-s1 sf@ { f: s1 }
    glyph texture_glyph_t-t1 sf@ { f: t1 }
    >v
    x0 y0 >xy n> color @ rgba>c s0 t0 >st v+
    x1 y0 >xy n> color @ rgba>c s1 t0 >st v+
    x0 y1 >xy n> color @ rgba>c s0 t1 >st v+
    x1 y1 >xy n> color @ rgba>c s1 t1 >st v+

    v>
    xp glyph texture_glyph_t-advance_x sf@ f+ penxy sf!
    yp glyph texture_glyph_t-advance_y sf@ f+ penxy sfloat+ sf! ;

: glyph+xy ( glyph -- )
    i>off  xy,  2 quad ;


: all-glyphs ( -- )
    i>off >v
    0e 0e >xy n> color @ rgba>c 0e 0e >st v+
    512e 0e >xy n> color @ rgba>c 1e 0e >st v+
    0e 512e >xy n> color @ rgba>c 0e 1e >st v+
    512e 512e >xy n> color @ rgba>c 1e 1e >st v+
    v> 2 quad ;

0 Value font

: xchar+xy ( prev-xchar xchar -- xchar )
    tuck font swap texture_font_get_glyph >r
    dup 0> IF  r@ swap texture_glyph_get_kerning
	penxy sf@ f+ penxy sf!
................................................................................
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
// The entry point for our fragment shader.
void main()
{
    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
//    gl_FragColor.rgb = v_Color.rgb;
}

' VertexShader ' textFragmentShader create-program Value textprogram
textprogram init

: <render ( -- )
    textprogram glUseProgram
    .01e 100e 100e >ap
    atlas-tex v0 i0 ;

: render> ( -- )  GL_TRIANGLES draw-elements ;

previous previous

Changes to gles2/ftgl-sample.fs.

1
2
3
4
5
6
7
8
9
10
11
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
\ freetype GL example

require gl-helper.fs
window-init

require ftgl-helper.fs

\ Demo Toplevel

also freetype-gl
also opengl
................................................................................
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/bkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2

Variable text1$ "Dös isch a Tägscht." text1$ $!
Variable text2$ "这是一个文本:在德语说" text2$ $!

: glyph-draw ( -- )
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    <render
    0. penxy 2!
    font1 to font  text1$ $@ render-string
    -100e penxy sf! -60e penxy sfloat+ sf!
    font2 to font  text2$ $@ render-string
    render> sync ;

: glyph-demo ( -- ) [IFDEF] hidekb  hidekb [THEN]
    1 level# +!  BEGIN  glyph-draw  >looper  level# @ 0= UNTIL ;

previous previous previous



|







 







|











|









1
2
3
4
5
6
7
8
9
10
11
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
\ freetype GL example

require gl-helper.fs
[IFUNDEF] android window-init [THEN]

require ftgl-helper.fs

\ Demo Toplevel

also freetype-gl
also opengl
................................................................................
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2

Variable text1$ "Dös isch a Tägscht." text1$ $!
Variable text2$ "这是一个文本:在德语说" text2$ $!

: glyph-draw ( -- )
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    <render
    0e penxy sf!  0e penxy sfloat+ sf!
    font1 to font  text1$ $@ render-string
    -100e penxy sf! -60e penxy sfloat+ sf!
    font2 to font  text2$ $@ render-string
    render> sync ;

: glyph-demo ( -- ) [IFDEF] hidekb  hidekb [THEN]
    1 level# +!  BEGIN  glyph-draw  >looper  level# @ 0= UNTIL ;

previous previous previous