Skip to content

Commit 12fee44

Browse files
committed
sdf-text added more texts
1 parent ebed8f6 commit 12fee44

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

sdf-text/assets/texts.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//src: http://www.rikeripsum.com/#!/
2+
We finished our first sensor sweep of the neutral zone.
3+
I suggest you drop it, Mr. Data.
4+
Mr. Crusher, ready a collision course with the Borg ship.
5+
Why don't we just give everybody a promotion and call it a night - 'Commander'? I think you've let your personal feelings cloud your judgement.
6+
Yesterday I did not know how to eat gagh.
7+
I'm afraid I still don't understand, sir.
8+
A lot of things can change in twelve years, Admiral.
9+
How long can two people talk about nothing? Talk about going nowhere fast.
10+
I'll be sure to note that in my log.
11+
Commander William Riker of the Starship Enterprise and attack the Romulans.
12+
My oath is between Captain Kargan and myself.
13+
Your only concern is with how you obey my orders.
14+
Or do you prefer the rank of prisoner to that of lieutenant? When has justice ever been as simple as a rule book? The unexpected is our normal routine.
15+
Computer, belay that order.
16+
The Enterprise computer system is controlled by three primary main processor cores, cross-linked with a redundant melacortz ramistat, fourteen kiloquad interface modules.
17+
What's a knock-out like you doing in a computer-generated gin joint like this? Computer, lights up! Some days you get the bear, and some days the bear gets you.
18+
Maybe if we felt any human loss as keenly as we feel one of those close to us, human history would be far less bloody.
19+
Some days you get the bear, and some days the bear gets you.
20+
I'll alert the crew.
21+
We know you're dealing in stolen ore.
22+
But I wanna talk about the assassination attempt on Lieutenant Worf.
23+
You bet I'm agitated! I may be surrounded by insanity, but I am not insane.

sdf-text/main.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Window.create({
3535
sdfFontVert: { glsl: glslify(__dirname + '/assets/SDFFont.vert') },
3636
sdfFontFrag: { glsl: glslify(__dirname + '/assets/SDFFont.frag') },
3737
fontImage: { image: ASSETS_DIR + '/fonts/' + Font.pages[0] },
38+
texts: { text: ASSETS_DIR + '/texts.txt' }
3839
},
3940
init: function() {
4041
var ctx = this.getContext();
@@ -77,13 +78,18 @@ Window.create({
7778
this.gui.addParam('fontSize', this, 'fontSize', { min: 4 , max: 64 });
7879
this.gui.addParam('debug', this, 'debug');
7980

80-
this.text = new SpriteTextBox(ctx, text, {
81-
fontSize: this.fontSize * DPI / 500,
82-
lineHeight: 1.2,
83-
font: Font,
84-
textures: [ this.fontTex ],
85-
wrap: 320 * DPI / 500
86-
});
81+
this.texts = res.texts.trim().split('\n').map(function(line) {
82+
var text = new SpriteTextBox(ctx, line, {
83+
fontSize: this.fontSize * DPI / 500,
84+
lineHeight: 1.2,
85+
font: Font,
86+
wrap: 320 * DPI / 500
87+
});
88+
text.position = [Math.random()*6-3-0.5, Math.random()*6-3-0.5, Math.random()*4-2-2]
89+
return text;
90+
}.bind(this))
91+
92+
8793
},
8894
draw: function() {
8995
var ctx = this.getContext();
@@ -99,25 +105,38 @@ Window.create({
99105

100106
ctx.setLineWidth(2);
101107

102-
this.text.setFontSize(this.fontSize * DPI / 500);
103108

104109
this.gui.draw();
105110

106111
ctx.pushModelMatrix();
107-
var s = this.text.opts.scale;
108-
ctx.scale([s, -s, s])
109-
ctx.translate([-0.5, -0.5, -1])
112+
var s = this.texts[0].opts.scale;
113+
110114

111115
ctx.bindTexture(this.fontTex, 0)
112116

117+
113118
ctx.bindProgram(this.sdfFontProgram);
114-
ctx.bindMesh(this.text.mesh);
115-
ctx.drawMesh();
119+
this.texts.forEach(function(text) {
120+
ctx.pushModelMatrix()
121+
ctx.translate(text.position)
122+
ctx.scale([s, -s, s])
123+
text.setFontSize(this.fontSize * DPI / 500);
124+
ctx.bindMesh(text.mesh);
125+
ctx.drawMesh();
126+
ctx.popModelMatrix();
127+
}.bind(this))
128+
116129

117130
if (this.debug) {
118131
ctx.bindProgram(this.solidColorProgram);
119-
ctx.bindMesh(this.text.debugMesh);
120-
ctx.drawMesh();
132+
this.texts.forEach(function(text) {
133+
ctx.pushModelMatrix()
134+
ctx.translate(text.position)
135+
ctx.scale([s, -s, s])
136+
ctx.bindMesh(text.debugMesh);
137+
ctx.drawMesh();
138+
ctx.popModelMatrix();
139+
}.bind(this))
121140
}
122141

123142
ctx.popModelMatrix();

0 commit comments

Comments
 (0)