1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-26 19:38:22 +01:00

Text rendering is greatly improved

This commit is contained in:
DanyLE 2022-03-06 18:33:10 +01:00
parent a751a6a6d3
commit bd9d406c85
20 changed files with 295 additions and 243 deletions

6
Diya/Color.extension.st Normal file
View File

@ -0,0 +1,6 @@
Extension { #name : #Color }
{ #category : #'*Diya' }
Color >> asGL4FArray [
^{self red. self green. self blue. self alpha }
]

View File

@ -1,15 +1,20 @@
Class {
#name : #Diya2DNode,
#superclass : #DiyaNode,
#instVars : [
'color'
],
#category : #'Diya-Graphics'
}
{ #category : #'as yet unclassified' }
Diya2DNode >> gltf: points do: block [
^ points collect: [ :point | |coord|
coord := self tf +* { point x. point y. 1.0 }.
block value: coord first value: (coord at:2)
]
{ #category : #accessing }
Diya2DNode >> color [
^ color
]
{ #category : #accessing }
Diya2DNode >> color: anObject [
color := anObject
]
{ #category : #initialization }
@ -19,6 +24,14 @@ Diya2DNode >> initialize [
scale := 1.0@1.0.
rotation := 0.0.
tf := Array2D identity: 3.
shader := Diya2DShader uniqueInstance.
color := Color white
]
{ #category : #initialization }
Diya2DNode >> setUpShader [
super setUpShader.
shader setUniform: #u_color value: self color asGL4FArray.
]
{ #category : #accessing }
@ -42,6 +55,8 @@ Diya2DNode >> updateTF [
0.0. scale y. 0.0.
0.0. 0.0. 1.0
}).
self parent isRoot ifTrue: [ ^tf ].
tf := self parent tf +* tf
self parent isRoot ifFalse: [ tf := self parent tf +* tf ].
children ifNotNil: [
children do:[:c| c updateTF ]].
]

View File

@ -0,0 +1,33 @@
Class {
#name : #Diya2DPrimShape,
#superclass : #Diya2DNode,
#instVars : [
'texture'
],
#category : #'Diya-Graphics'
}
{ #category : #initialization }
Diya2DPrimShape >> initialize [
super initialize.
texture := nil.
]
{ #category : #initialization }
Diya2DPrimShape >> setUpShader [
super setUpShader.
texture ifNotNil: [
self shader
setUniform: #u_use_texture value:1.
].
]
{ #category : #accessing }
Diya2DPrimShape >> texture [
^ texture
]
{ #category : #accessing }
Diya2DPrimShape >> texture: anObject [
texture := anObject
]

View File

@ -0,0 +1,57 @@
Class {
#name : #Diya2DShader,
#superclass : #OpenGLSL,
#category : #'Diya-Shaders'
}
{ #category : #accessing }
Diya2DShader class >> fragmentShader [
^'
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
// 2D uniforms
uniform int u_use_texture;
uniform vec4 u_color;
uniform vec4 u_border_color;
uniform sampler2D u_texture;
varying vec2 texcoord;
void main(void) {
vec4 texcolor = vec4(1,1,1,1);
if(u_use_texture == 1)
{
texcolor = vec4(1, 1, 1, texture2D(u_texture, texcoord).a);
}
gl_FragColor = texcolor * u_color;
}'
]
{ #category : #accessing }
Diya2DShader class >> vertexShader [
^'
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 u_projection;
uniform mat3 u_transform;
varying vec2 texcoord;
void main()
{
vec3 coord_global = u_transform * vec3(gl_Vertex.xy, 1.0);
gl_Position = u_projection * vec4(coord_global.xy, 0, 1.0);
texcoord = gl_Vertex.zw;
}'
]
{ #category : #initialization }
Diya2DShader >> setUpUniforms [
self addUniform: #u_texture of: Uniform1i.
self addUniform: #u_use_texture of: Uniform1i.
self addUniform: #u_color of: Uniform4F.
self addUniform: #u_border_color of: Uniform4F.
self addUniform: #u_border of: Uniform1i.
]

View File

@ -17,6 +17,11 @@ Class {
#category : #'Diya-Runtime'
}
{ #category : #'instance creation' }
DiyaBoot class >> maxFPS [
^60
]
{ #category : #'instance creation' }
DiyaBoot class >> startUp: status [
self startx.
@ -61,6 +66,23 @@ DiyaBoot >> createWindow [
^window
]
{ #category : #events }
DiyaBoot >> exampleNodes [
|root text rec style|
root := DiyaRootNode new.
rec := root addNode: (DiyaRectangle size: 208@288) at: 250 @ 200.
style := DiyaFontManager uniqueInstance style: 'Bold' from: 'Ubuntu'.
rec texture: (style textureOf: 16).
rec color: (Color r: 1.0 g:0.0 b:1.0 alpha:1.0 ).
rec := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 20 @ 400.
rec rotation: (Float pi / -8.0).
rec scale: 1.5@1.5.
text := root addNode: (DiyaText data: String loremIpsum) at: 20@320.
text extent: 200@320.
^ root
"text rotation:(Float pi / 4.0); scale: 2.0@2.0."
]
{ #category : #events }
DiyaBoot >> init [
| status |
@ -107,26 +129,27 @@ DiyaBoot >> randomColorChannel [
{ #category : #events }
DiyaBoot >> render [
|event root rec text|
|event root text delta|
event := SDL_Event new.
root := DiyaRootNode new.
root := self exampleNodes.
DiyaRenderer uniqueInstance root: root.
rec := root addNode: (DiyaRectangle size: 120@160 shader: GLSimpleShader uniqueInstance) at: 250 @ 200.
rec := root addNode: (DiyaRectangle size: 50@50 shader: GLSimpleShader uniqueInstance) at: 250 @ 500.
rec rotation: (Float pi / -8.0).
rec scale: 1.5@1.5.
text := root addNode: (DiyaText data: String loremIpsum shader: TotoShader uniqueInstance) at: 20@320.
text extent: 200@320.
"text rotation:(Float pi / 4.0)."
text := root addNode:(DiyaText data: 'tick') at: (display w - 80)@40.
text extent: 80@40.
text fontSize: 20.
text color: Color red.
self GLinit.
OpenGL viewportX: 0 Y:0 W: display w H: display h.
"TODO: maybe give node to customize this"
[ running ] whileTrue: [
(SDL2 pollEvent: event) > 0 ifTrue: [
delta := DiyaClock uniqueInstance delta asMilliSeconds.
text data: ('FPS:', (1000/delta) asInteger asString).
DiyaClock uniqueInstance tick.
[(SDL2 pollEvent: event) > 0] whileTrue: [
self processEvent: event
].
DiyaRenderer uniqueInstance render.
SDL2 glSwapWindow: window.
delta := DiyaClock uniqueInstance delta asMilliSeconds.
SDL2 delay: (0 max: (1000/ self class maxFPS) asInteger - delta). "60 fps"
].
]

View File

@ -2,11 +2,17 @@ Class {
#name : #DiyaClock,
#superclass : #DiyaSingleton,
#instVars : [
'monotonic'
'monotonic',
'lastTick'
],
#category : #'Diya-Runtime'
}
{ #category : #initialization }
DiyaClock >> delta [
^(DateAndTime now) - lastTick
]
{ #category : #initialization }
DiyaClock >> elapsedTime [
^(DateAndTime now) - monotonic
@ -15,4 +21,10 @@ DiyaClock >> elapsedTime [
{ #category : #initialization }
DiyaClock >> initialize [
monotonic := DateAndTime now.
lastTick := monotonic.
]
{ #category : #initialization }
DiyaClock >> tick [
lastTick := DateAndTime now.
]

View File

@ -1,18 +0,0 @@
Class {
#name : #DiyaDefaultShader,
#superclass : #OpenGLSL,
#category : #'Diya-Shaders'
}
{ #category : #accessing }
DiyaDefaultShader class >> fragmentShader [
^ '
#ifdef GL_ES
precision mediump float;
#endif
void main()
{
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
'
]

View File

@ -1,11 +1,11 @@
Class {
#name : #GLSimpleShader,
#superclass : #OpenGLSL,
#name : #DiyaExampleShader,
#superclass : #Diya2DShader,
#category : #'Diya-Shaders'
}
{ #category : #accessing }
GLSimpleShader class >> fragmentShader [
DiyaExampleShader class >> fragmentShader [
^ '
#ifdef GL_ES
precision mediump float;
@ -17,7 +17,6 @@ void main()
{
vec2 mouse = u_mouse / u_resolution;
vec2 px = (gl_FragCoord.xy/u_resolution);
gl_FragColor = vec4(px/mouse, abs(sin(u_time)), 1.0);
}
'

View File

@ -120,6 +120,7 @@ DiyaNode >> position: anObject [
{ #category : #accessing }
DiyaNode >> render [
shader ifNotNil: [ self setUpShader ].
self draw.
children ifNil: [ ^self ].
children do: [:c | c render ].
@ -147,6 +148,22 @@ DiyaNode >> scale: anObject [
self updateTF.
]
{ #category : #accessing }
DiyaNode >> setUpShader [
shader use;
setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat;
setUniform: #u_projection value: {GL_FALSE. context projection buffer};
setUniform: #u_resolution value: { context resolution x. context resolution y };
setUniform: #u_texture value: 0;
setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer}.
context mouse ifNotNil: [
"in shader, window origin is bottom left conor of the window
the mouse position should be transformed to this coodinate"
shader setUniform: #u_mouse value:
{ context mouse x. context resolution y - context mouse y }.
].
]
{ #category : #accessing }
DiyaNode >> shader [
shader ifNil: [

View File

@ -1,32 +1,30 @@
Class {
#name : #DiyaRectangle,
#superclass : #Diya2DNode,
#superclass : #Diya2DPrimShape,
#category : #'Diya-Graphics'
}
{ #category : #accessing }
DiyaRectangle >> draw [
{
0.0. 0.0. 1.0.
0.0. extent y. 1.0.
extent x. extent y. 1.0.
extent x. 0.0. 1.0.
0.0. extent y. 0.0. 0.0.
0. 0. 0.0. 1.0.
extent x. 0.0. 1.0. 1.0.
0.0. extent y. 0.0. 0.0.
extent x. 0.0. 1.0. 1.0.
extent x. extent y. 1.0. 0.0.
} doWithIndex: [:e :i| context buffer at: i put: e].
shader use.
shader setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat.
shader setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer}.
shader setUniform: #u_projection value: {GL_FALSE. context projection buffer}.
shader setUniform: #u_resolution value: { context resolution x. context resolution y }.
context mouse ifNotNil: [
"in shader, window origin is bottom left conor of the window
the mouse position should be transformed to this coodinate"
shader setUniform: #u_mouse value: { context mouse x. context resolution y - context mouse y }.
texture ifNotNil: [
self texture setup.
context texture0 setImage2D: self texture.
context texture0 active.
].
context vao enableAttribute: 0.
OpenGLVertexArray vertexAttributePointerIndex: 0 size:3 type: GL_FLOAT normalized: GL_FALSE stride: 0 pointer: nil.
context vbo subData: GL_ARRAY_BUFFER offset:0 data: context buffer.
OpenGL drawArrays: GL_QUADS first:0 count: 4.
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil.
context vbo subData: GL_ARRAY_BUFFER offset:0 data: context buffer size: 96.
OpenGL drawArrays: GL_TRIANGLES first:0 count: 6.
context vao disableAttribute: 0.
texture ifNotNil: [self texture drop]
]
{ #category : #accessing }

View File

@ -24,7 +24,7 @@ DiyaRendererContext class >> cleanUpInstance: singleton [
{ #category : #'instance creation' }
DiyaRendererContext class >> maxFloatBufferSize [
^512
^4096
]
{ #category : #accessing }

View File

@ -6,7 +6,7 @@ Class {
{ #category : #accessing }
DiyaRootNode >> draw [
OpenGL clearColorR: 1.0 G: 0.0 B: 1.0 A:0.
OpenGL clearColorR: 0.0 G: 0.0 B: 0.0 A:0.
OpenGL clear: GL_COLOR_BUFFER_BIT.
context vbo bind: GL_ARRAY_BUFFER.
]
@ -15,7 +15,7 @@ DiyaRootNode >> draw [
DiyaRootNode >> initialize [
super initialize.
parent := self.
shader := DiyaDefaultShader uniqueInstance.
shader := nil.
]
{ #category : #testing }

View File

@ -37,74 +37,36 @@ DiyaText >> data: anObject [
{ #category : #accessing }
DiyaText >> draw [
data ifNil: [ ^self ].
style := DiyaFontManager uniqueInstance style: self fontStyle from: self fontName.
OpenGL
enable: GL_CULL_FACE;
enable: GL_BLEND;
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA;
pixelstorei: GL_UNPACK_ALIGNMENT param: 1.
self shader
use;
setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat;
setUniform: #u_projection value: {GL_FALSE. context projection buffer};
setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer};
setUniform: #u_texture value: 0;
setUniform: #u_resolution value: { context resolution x. context resolution y }.
setUniform: #u_use_texture value:1.
"configure vao vbo for texture QUAD"
context texture0 active.
style := DiyaFontManager uniqueInstance style: self fontStyle from: self fontName.
self texture setup.
context texture0 setImage2D: self texture.
OpenGLTexture
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_S param: GL_CLAMP_TO_EDGE;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_T param: GL_CLAMP_TO_EDGE;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MIN_FILTER param: GL_LINEAR;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MAG_FILTER param: GL_LINEAR.
context texture0 active.
context vao enableAttribute: 0.
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil .
self drawText.
context vao disableAttribute: 0.
"reset value"
OpenGL
pixelstorei: GL_UNPACK_ALIGNMENT param: 4;
disable: GL_CULL_FACE;
disable: GL_BLEND.
self texture drop.
]
{ #category : #accessing }
DiyaText >> drawCharacter: c at: offset [
|x y w h glyph tex2D|
tex2D := self texture.
c = (Character space asciiValue) ifTrue:[
^offset setX: (offset x + ((tex2D spacing )* (self scale x)) ) setY: offset y.
].
glyph := tex2D getGlyph: c.
((offset x > self extent x) and: (glyph extent x > 0)) ifTrue:[
offset setX: 0.0 setY: (offset y )- (tex2D linespace * (self scale y)).].
x := offset x + ((glyph bearing x )*(self scale x)).
y := offset y - ((tex2D cellh) * (self scale y)).
w := (glyph extent x)*(self scale x).
h := (glyph extent y)*(self scale y).
{x. y + h. glyph texcoord origin x. glyph texcoord origin y.
x. y. glyph texcoord origin x. glyph texcoord corner y.
x + w. y. glyph texcoord corner x. glyph texcoord corner y.
x. y + h. glyph texcoord origin x. glyph texcoord origin y.
x + w. y. glyph texcoord corner x. glyph texcoord corner y.
x + w. y + h. glyph texcoord corner x. glyph texcoord origin y. } withIndexDo: [ :e :i| context buffer at:i put: e ].
context vbo subData: GL_ARRAY_BUFFER offset: 0 data: context buffer.
OpenGL drawArrays: GL_TRIANGLES first:0 count:6.
offset setX: (offset x + ((glyph advance x )* (self scale x)) ) setY: offset y.
]
{ #category : #accessing }
DiyaText >> drawSubStringFrom: lower at: offset [
|upper vertices count|
upper := lower + ((data size - lower) min:(context buffer size / 6) asInteger) - 1.
|upper vertices count index tex2D|
upper := lower + ((data size - lower) min:(context buffer size / 24) asInteger).
count := 0.
index := 1.
tex2D := self texture.
lower to: upper do: [ :i|
vertices := self getCharsVertices:(data at:i) asciiValue offset: offset.
vertices withIndexDo: [
:e :p| context buffer at: count*4 + p put:e ].
count := count + (vertices size /4) asInteger.
vertices := self getCharsVertices:(data at:i) asciiValue offset: offset on: tex2D.
vertices do: [
:e| context buffer at: index put:e.
index := index + 1.
].
vertices ifNotEmpty: [ count := count + 6 ].
].
context vbo subData: GL_ARRAY_BUFFER offset: 0 data: context buffer.
OpenGL drawArrays: GL_TRIANGLES first:0 count:count.
@ -122,33 +84,6 @@ DiyaText >> drawText [
] whileTrue.
]
{ #category : #accessing }
DiyaText >> fillVerticesBuffer: buffer at: offset tex: tex [
|x y w h|
"x := offset x + ((tex bearing x )*(self scale x)).
y := offset y - (((tex height) - (tex bearing y))*(self scale y)).
w := (tex width)*(self scale x).
h := (tex height)*(self scale y)."
x := 0.
y := 0.
w := tex width.
h := tex height.
{x. y + h. 0.0. 0.0.
x. y. 0.0. 1.0.
x + w. y. 1.0. 1.0.
x. y + h. 0.0. 0.0.
x + w. y. 1.0. 1.0.
x + w. y + h. 1.0. 0.0. } withIndexDo: [ :e :i| buffer at:i put: e ]
"{x. y + h. 0.0. 0.0.
x. y. 0.0. 1.0.
x + w. y. 1.0. 1.0.
x. y + h. 0.0. 0.0.
x + w. y. 1.0. 1.0.
x + w. y + h. 1.0. 0.0. }"
]
{ #category : #accessing }
DiyaText >> fontName [
^ fontName
@ -180,21 +115,21 @@ DiyaText >> fontStyle: anObject [
]
{ #category : #accessing }
DiyaText >> getCharsVertices:c offset: offset [
|x y w h glyph tex2D|
tex2D := self texture.
DiyaText >> getCharsVertices:c offset: offset on: tex2D [
|x y w h glyph gsize|
c = (Character space asciiValue) ifTrue:[
offset setX: (offset x + ((tex2D spacing )* (self scale x)) ) setY: offset y.
^ { }.
offset setX: (offset x + (tex2D spacing ) ) setY: offset y.
^ {}.
].
glyph := tex2D getGlyph: c.
((offset x > self extent x) and: (glyph extent x > 0)) ifTrue:[
offset setX: 0.0 setY: (offset y )- (tex2D linespace * (self scale y)).].
x := offset x + ((glyph bearing x )*(self scale x)).
y := offset y - ((tex2D cellh) * (self scale y)).
w := (glyph extent x)*(self scale x).
h := (glyph extent y)*(self scale y).
offset setX: (offset x + ((glyph advance x )* (self scale x)) ) setY: offset y.
gsize := glyph extent.
((offset x > self extent x) and: (gsize x > 0)) ifTrue:[
offset setX: 0.0 setY: (offset y )- (tex2D linespace).].
x := offset x + (glyph bearing x).
y := offset y - (tex2D cellh).
w := (gsize x).
h := (gsize y).
offset setX: (offset x + (glyph advance x)) setY: offset y.
^{x. y + h. glyph texcoord origin x. glyph texcoord origin y.
x. y. glyph texcoord origin x. glyph texcoord corner y.
x + w. y. glyph texcoord corner x. glyph texcoord corner y.
@ -208,7 +143,7 @@ DiyaText >> initialize [
super initialize.
self fontName: 'Ubuntu'.
self fontStyle: 'Regular'.
self fontSize: 14.
self fontSize: 16.
data := nil.
]

View File

@ -1,23 +0,0 @@
Class {
#name : #GLTexShader,
#superclass : #OpenGLSL,
#category : #'Diya-Shaders'
}
{ #category : #accessing }
GLTexShader class >> fragmentShader [
^ '
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
uniform vec2 u_resolution;
void main(){
//vec2 uv = gl_FragCoord.xy / u_resolution;
vec4 sampled = vec4(1.0, 1.0, 1.0, texture2D(u_texture,gl_FragCoord.zw).r);
gl_FragColor = vec4(1.0,1.0,1.0,1.0)* sampled; //texture2D(u_texture,uv.xy);
}
'
]

View File

@ -14,6 +14,7 @@ Class {
'GL_BLEND',
'GL_BLUE',
'GL_BYTE',
'GL_CLAMP_TO_BORDER',
'GL_CLAMP_TO_EDGE',
'GL_COLOR_BUFFER_BIT',
'GL_COMPILE_STATUS',
@ -39,6 +40,7 @@ Class {
'GL_LINE_STRIP',
'GL_LINK_STATUS',
'GL_MAX_TEXTURE_SIZE',
'GL_NEAREST',
'GL_ONE_MINUS_SRC_ALPHA',
'GL_PACK_ALIGNMENT',
'GL_POINTS',
@ -168,9 +170,10 @@ OpenGLConstants class >> initTextureConstants [
GL_TEXTURE_MIN_FILTER := 16r2801.
GL_TEXTURE_MAG_FILTER := 16r2800.
GL_LINEAR := 16r2601.
GL_NEAREST := 16r2600.
GL_TEXTURE_UNIT_BASE := 16r84C0.
GL_MAX_TEXTURE_SIZE := 16r0D33
GL_MAX_TEXTURE_SIZE := 16r0D33.
GL_CLAMP_TO_BORDER := 16r812D
]
{ #category : #'class initialization' }

View File

@ -4,7 +4,8 @@ Class {
#instVars : [
'charmap',
'cellw',
'cellh'
'cellh',
'spacing'
],
#pools : [
'OpenGLConstants',
@ -56,10 +57,10 @@ OpenGLFontTex >> createBitmapFontFrom: bitmaps metrics: metrics maxBearing: maxb
0 to: 15 do: [ :row|
0 to: 15 do: [ :col| |glyph|
offset := (col * cellw) @ (row*cellh).
glyph := (DiyaFontGlyph origin: offset extent: (((metrics at: currChar) first x) @ cellh)).
glyph := (DiyaFontGlyph origin: offset extent: (((metrics at: currChar) first x asInteger) @ cellh)).
glyph
bearing: ((metrics at: currChar) at: 2);
advance: ((metrics at: currChar) at: 3);
bearing: ((metrics at: currChar) at: 2) asFloatPoint;
advance: ((metrics at: currChar) at: 3) asFloatPoint;
texcoord: (Rectangle origin: (glyph origin/ (self extent) ) asFloatPoint corner: ((glyph corner) / (self extent)) asFloatPoint ).
charmap add:glyph.
self blitPixel8: (bitmaps at: currChar) at: (offset x) @ ((offset y) + maxbearing - ((metrics at: currChar) last) ) size: (metrics at: currChar) first.
@ -68,6 +69,14 @@ OpenGLFontTex >> createBitmapFontFrom: bitmaps metrics: metrics maxBearing: maxb
].
]
{ #category : #accessing }
OpenGLFontTex >> drop [
OpenGL
pixelstorei: GL_UNPACK_ALIGNMENT param: 4;
disable: GL_CULL_FACE;
disable: GL_BLEND.
]
{ #category : #'instance creation' }
OpenGLFontTex >> fromFace: face ofSize: size [
|minhang maxbearing rec metrics bitmaps |
@ -83,7 +92,12 @@ OpenGLFontTex >> fromFace: face ofSize: size [
0 to: 255 do: [ :c |
|bmp bmpsize|
face loadCharacter: c flags: (1 << 2).
metrics add: { ((rec glyph metrics width) /64)@ ((rec glyph metrics height) /64). (face glyph hBearing). (face glyph advance). (rec glyph metrics horiBearingY) / 64}.
metrics add: {
(((rec glyph metrics width) /64)@ ((rec glyph metrics height) /64)).
(face glyph hBearing).
(face glyph advance).
((rec glyph metrics horiBearingY) / 64)
}.
maxbearing := maxbearing max: ((rec glyph metrics horiBearingY) / 64).
cellw := cellw max: ((rec glyph metrics width) / 64).
minhang := minhang min: ((( rec glyph metrics horiBearingY) - (rec glyph metrics height )) / 64).
@ -94,6 +108,7 @@ OpenGLFontTex >> fromFace: face ofSize: size [
bitmaps add: bmp.
].
cellh := maxbearing - minhang.
spacing := (cellw / 2) asInteger.
self createBitmapFontFrom: bitmaps metrics: metrics maxBearing: maxbearing.
bitmaps do:[:p| p free].
]
@ -122,6 +137,20 @@ OpenGLFontTex >> linespace [
]
{ #category : #accessing }
OpenGLFontTex >> spacing [
^ cellw / 2
OpenGLFontTex >> setup [
OpenGL
enable: GL_CULL_FACE;
enable: GL_BLEND;
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA;
pixelstorei: GL_UNPACK_ALIGNMENT param: 1.
OpenGLTexture
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_S param: GL_CLAMP_TO_EDGE;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_T param: GL_CLAMP_TO_EDGE;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MIN_FILTER param: GL_LINEAR;
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MAG_FILTER param: GL_LINEAR.
]
{ #category : #accessing }
OpenGLFontTex >> spacing [
^ spacing
]

View File

@ -109,18 +109,7 @@ OpenGLSL class >> useProgram:program [
{ #category : #accessing }
OpenGLSL class >> vertexShader [
^ '
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 u_projection;
uniform mat3 u_transform;
void main()
{
vec3 coord_global = u_transform * vec3(gl_Vertex.xy, 1.0);
gl_Position = u_projection * vec4(coord_global.xy, 0, 1.0);
}
'
^self subclassResponsibility
]
{ #category : #initialization }

View File

@ -52,6 +52,11 @@ OpenGLTexImage2D >> debug [
stdlog: 'internalformat :',internalFormat hex
]
{ #category : #accessing }
OpenGLTexImage2D >> drop [
^self subclassResponsibility
]
{ #category : #accessing }
OpenGLTexImage2D >> extent [
^ width @ height
@ -97,6 +102,11 @@ OpenGLTexImage2D >> level: anObject [
level := anObject
]
{ #category : #accessing }
OpenGLTexImage2D >> setup [
^self subclassResponsibility
]
{ #category : #accessing }
OpenGLTexImage2D >> target [
^ target
@ -107,6 +117,11 @@ OpenGLTexImage2D >> target: anObject [
target := anObject
]
{ #category : #accessing }
OpenGLTexImage2D >> teardown [
^self subclassResponsibility
]
{ #category : #accessing }
OpenGLTexImage2D >> type [
^ type

View File

@ -87,6 +87,12 @@ OpenGLVertexBuffer >> subData:target offset: offset data:data [
^OpenGLVertexBuffer subData: target offset: offset size: data size * 4 data: data getHandle
]
{ #category : #'as yet unclassified' }
OpenGLVertexBuffer >> subData:target offset: offset data:data size: size [
self bind: target.
^OpenGLVertexBuffer subData: target offset: offset size: size data: data getHandle
]
{ #category : #initialization }
OpenGLVertexBuffer >> vertexBufferID [
^ vertexBufferID at: 1

View File

@ -1,44 +0,0 @@
Class {
#name : #TotoShader,
#superclass : #OpenGLSL,
#category : #'Diya-Shaders'
}
{ #category : #'as yet unclassified' }
TotoShader class >> fragmentShader [
^'
#ifdef GL_ES
precision highp float;
#endif
varying vec2 texcoord;
uniform sampler2D u_texture;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
void main(void) {
gl_FragColor = vec4(1, 1, 1, texture2D(u_texture, texcoord).a) * vec4(1,1,1,1);
}'
]
{ #category : #'as yet unclassified' }
TotoShader class >> vertexShader [
^'
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 u_projection;
uniform mat3 u_transform;
varying vec2 texcoord;
void main()
{
vec3 coord_global = u_transform * vec3(gl_Vertex.xy, 1.0);
gl_Position = u_projection * vec4(coord_global.xy, 0, 1.0);
texcoord = gl_Vertex.zw;
}'
]
{ #category : #initialization }
TotoShader >> setUpUniforms [
self addUniform: #u_texture of: Uniform1i.
]