mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 03:48:21 +01:00
Text rendering iss working now
This commit is contained in:
parent
ce08ac49e2
commit
8cb2cb543a
@ -5,11 +5,10 @@ Class {
|
||||
}
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
Diya2DNode >> gltf: points [
|
||||
Diya2DNode >> gltf: points do: block [
|
||||
^ points collect: [ :point | |coord|
|
||||
coord := self tf +* { point x. point y. 1.0 }.
|
||||
coord at:3 put: 0.0.
|
||||
coord
|
||||
block value: coord first value: (coord at:2)
|
||||
]
|
||||
]
|
||||
|
||||
|
@ -4,9 +4,34 @@ Class {
|
||||
#category : #'Diya-Core'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaBaseObject >> checkGLError: mark [
|
||||
|err|
|
||||
err := OpenGL getError.
|
||||
err = 0 ifFalse:[
|
||||
self stderror:mark, ': return error code ', err hex.
|
||||
].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaBaseObject >> logError: string [
|
||||
self stderr nextPutAll: string; cr
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaBaseObject >> stderr [
|
||||
VTermOutputDriver stderr
|
||||
^VTermOutputDriver stderr
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaBaseObject >> stderror: string [
|
||||
self stderr nextPutAll: string; nextPutAll: Character cr asString.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaBaseObject >> stdlog: string [
|
||||
self stdout nextPutAll: string;
|
||||
nextPutAll: Character cr asString.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
@ -4,7 +4,6 @@ Class {
|
||||
#instVars : [
|
||||
'running',
|
||||
'window',
|
||||
'renderer',
|
||||
'context',
|
||||
'display',
|
||||
'clock'
|
||||
@ -36,14 +35,6 @@ DiyaBoot >> createGLContext [
|
||||
|
||||
]
|
||||
|
||||
{ #category : #events }
|
||||
DiyaBoot >> createRenderer [
|
||||
renderer := window primCreateRenderer: -1 flags: SDL_RENDERER_ACCELERATED.
|
||||
renderer ifNil: [ ^self error: SDL2 getErrorMessage ].
|
||||
^renderer
|
||||
|
||||
]
|
||||
|
||||
{ #category : #events }
|
||||
DiyaBoot >> createWindow [
|
||||
window := SDL2 createWindow: 'Diya'
|
||||
@ -54,12 +45,20 @@ DiyaBoot >> createWindow [
|
||||
flags: SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL.
|
||||
window ifNil: [ ^self error: SDL2 getErrorMessage ].
|
||||
"handle fullscreen: SDL_WINDOW_FULLSCREEN."
|
||||
"SDL2 glSetAttribute: SDL_GL_CONTEXT_PROFILE_MASK value: SDL_GL_CONTEXT_PROFILE_ES.
|
||||
SDL2 glSetAttribute: SDL_GL_CONTEXT_MAJOR_VERSION value: 2.
|
||||
SDL2 glSetAttribute: SDL_GL_CONTEXT_MINOR_VERSION value: 0.
|
||||
SDL2 glSetAttribute: SDL_GL_ACCELERATED_VISUAL value: 1."
|
||||
"SDL2 glSetAttribute: SDL_GL_DOUBLEBUFFER value: 1.
|
||||
SDL2 glSetAttribute: SDL_GL_DEPTH_SIZE value: 24."
|
||||
|
||||
^window
|
||||
]
|
||||
|
||||
{ #category : #events }
|
||||
DiyaBoot >> init [
|
||||
| status |
|
||||
SDL2 setHint: 'SDL_RENDER_DRIVER' value: 'opengles2'.
|
||||
status := SDL2 init: SDL_INIT_EVERYTHING.
|
||||
status = 0
|
||||
ifFalse: [ ^ self error: SDL2 getErrorMessage ].
|
||||
@ -106,9 +105,11 @@ DiyaBoot >> render [
|
||||
DiyaRenderer uniqueInstance root: root.
|
||||
rec := root addNode: (DiyaRectangle size: 120@160 shader: GLSimpleShader uniqueInstance) at: 200 @ 200.
|
||||
rec := root addNode: (DiyaRectangle size: 50@50 shader: GLSimpleShader uniqueInstance) at: 200 @ 500.
|
||||
"rec rotation: (Float pi / -8.0).
|
||||
rec scale: 1.5@1.5."
|
||||
text := root addNode: (DiyaText data: 'Hello,world' shader: TotoShader uniqueInstance) at: 0@0.
|
||||
rec rotation: (Float pi / -8.0).
|
||||
rec scale: 1.5@1.5.
|
||||
text := root addNode: (DiyaText data: 'the quick brown fox jumped over the lazy dog' shader: TotoShader uniqueInstance) at: 50@100.
|
||||
text extent: 100@100.
|
||||
"text rotation:(Float pi / 4.0)."
|
||||
OpenGL viewportX: 0 Y:0 W: display w H: display h.
|
||||
"TODO: maybe give node to customize this"
|
||||
[ running ] whileTrue: [
|
||||
@ -182,10 +183,6 @@ DiyaBoot >> showSystemInfo [
|
||||
stream nextPutAll: rinfo name readString; nextPutAll:' '.
|
||||
].
|
||||
stream cr.
|
||||
renderer ifNotNil:[
|
||||
renderer primGetRendererInfo: rinfo.
|
||||
stream nextPutAll: 'SDL_RENDER_DRIVER selected: '; nextPutAll: rinfo name readString; cr.
|
||||
].
|
||||
stream nextPutAll:'Display resolution: ';
|
||||
nextPutAll:display w asString;
|
||||
nextPutAll: 'x';
|
||||
@ -199,12 +196,11 @@ DiyaBoot >> startx [
|
||||
display ifNil: [ ^self error: 'Please run #init before this method' ].
|
||||
self createWindow.
|
||||
self createGLContext.
|
||||
self createRenderer.
|
||||
SDL2 glMakeCurrent: window context: context.
|
||||
self showSystemInfo.
|
||||
DiyaRendererContext uniqueInstance display: display; useProjection: OrthoProjectionMatrix.
|
||||
self render.
|
||||
context delete.
|
||||
renderer destroy.
|
||||
window destroy.
|
||||
DiyaFontManager reset.
|
||||
DiyaRendererContext reset.
|
||||
|
@ -2,7 +2,7 @@ Class {
|
||||
#name : #DiyaFontFamily,
|
||||
#superclass : #DiyaBaseObject,
|
||||
#instVars : [
|
||||
'faces',
|
||||
'styles',
|
||||
'name'
|
||||
],
|
||||
#category : #'Diya-Fonts'
|
||||
@ -16,23 +16,13 @@ DiyaFontFamily class >> fromFace: face [
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> addFace: face [
|
||||
name ifNil: [ name := face familyName ].
|
||||
faces at: face styleName ifAbsentPut: face.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> face: styleName [
|
||||
^faces at: styleName ifAbsent: [^faces at: 'Regular']
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> faces [
|
||||
^ faces
|
||||
styles at: face styleName ifAbsentPut: (DiyaFontStyle fromFace: face).
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontFamily >> initialize [
|
||||
super initialize.
|
||||
faces := Dictionary new.
|
||||
styles := Dictionary new.
|
||||
name := nil
|
||||
]
|
||||
|
||||
@ -47,6 +37,16 @@ DiyaFontFamily >> name: anObject [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> styleNames [
|
||||
^faces keys
|
||||
DiyaFontFamily >> style: styleName [
|
||||
^styles at: styleName ifAbsent: [^styles at: 'Regular']
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> styleNames [
|
||||
^styles keys
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> styles [
|
||||
^ styles
|
||||
]
|
||||
|
@ -27,14 +27,6 @@ DiyaFontManager >> defaultFamily [
|
||||
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontManager >> face: styleName from: familyName [
|
||||
|family|
|
||||
family := families at: familyName ifAbsent: [ self defaultFamily ].
|
||||
^family face: styleName
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontManager >> families [
|
||||
^ families
|
||||
@ -99,3 +91,11 @@ DiyaFontManager >> reset [
|
||||
"reset all stored faces"
|
||||
families := Dictionary new.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontManager >> style: styleName from: familyName [
|
||||
|family|
|
||||
family := families at: familyName ifAbsent: [ self defaultFamily ].
|
||||
^family style: styleName
|
||||
|
||||
]
|
||||
|
55
Diya/DiyaFontStyle.class.st
Normal file
55
Diya/DiyaFontStyle.class.st
Normal file
@ -0,0 +1,55 @@
|
||||
Class {
|
||||
#name : #DiyaFontStyle,
|
||||
#superclass : #DiyaBaseObject,
|
||||
#instVars : [
|
||||
'face',
|
||||
'name',
|
||||
'charmap'
|
||||
],
|
||||
#category : #'Diya-Fonts'
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaFontStyle class >> fromFace: aFace [
|
||||
^self new face: aFace; yourself
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontStyle >> face [
|
||||
^ face
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontStyle >> face: anObject [
|
||||
face := anObject.
|
||||
name := anObject styleName
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontStyle >> initialize [
|
||||
super initialize.
|
||||
charmap := Dictionary new.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontStyle >> loadChar: charCode size: size [
|
||||
|tex dic|
|
||||
"lookup in the char map"
|
||||
dic := charmap at: charCode ifAbsentPut: Dictionary new.
|
||||
tex := dic at: size ifAbsentPut: [
|
||||
face setPixelWidth:0 height: size.
|
||||
face loadCharacter: charCode flags: (1 << 2).
|
||||
OpenGLFontTex fromFace: face
|
||||
].
|
||||
^tex
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontStyle >> name [
|
||||
^ name
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontStyle >> name: anObject [
|
||||
name := anObject
|
||||
]
|
@ -9,7 +9,8 @@ Class {
|
||||
'rotation',
|
||||
'tf',
|
||||
'shader',
|
||||
'context'
|
||||
'context',
|
||||
'extent'
|
||||
],
|
||||
#pools : [
|
||||
'OpenGLConstants',
|
||||
@ -18,6 +19,16 @@ Class {
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaNode class >> size: size [
|
||||
^(self new) extent: size; yourself
|
||||
]
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaNode class >> size: size shader:s [
|
||||
^(self with:s) extent: size; yourself
|
||||
]
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaNode class >> with: shader [
|
||||
^self new shader: shader; yourself
|
||||
@ -52,11 +63,26 @@ DiyaNode >> draw [
|
||||
self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> extent [
|
||||
^ extent
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> extent: anObject [
|
||||
extent := anObject
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
DiyaNode >> gltf: points [
|
||||
^self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> height [
|
||||
^ extent y
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaNode >> initialize [
|
||||
super initialize.
|
||||
@ -144,3 +170,8 @@ DiyaNode >> tf [
|
||||
DiyaNode >> updateTF [
|
||||
self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> wdith [
|
||||
^ extent x
|
||||
]
|
||||
|
@ -1,22 +1,9 @@
|
||||
Class {
|
||||
#name : #DiyaRectangle,
|
||||
#superclass : #Diya2DNode,
|
||||
#instVars : [
|
||||
'size'
|
||||
],
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
DiyaRectangle class >> size: s [
|
||||
^(self new) size:s; yourself
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
DiyaRectangle class >> size: size shader:s [
|
||||
^(self with:s) size: size; yourself
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> draw [
|
||||
self transformDo:[:i :e|
|
||||
@ -42,26 +29,18 @@ DiyaRectangle >> draw [
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> initialize [
|
||||
super initialize.
|
||||
self size:10@10.
|
||||
self extent:10@10.
|
||||
translation := nil.
|
||||
children := nil
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> size [
|
||||
^ size
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> size: anObject [
|
||||
size := anObject.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> transformDo: block [
|
||||
|i|
|
||||
i := 1.
|
||||
(self gltf: { 0.0@0.0. 0.0@ (size y). size. (size x) @0. }) do:[:p|
|
||||
p do: [ :e|
|
||||
block value:i value:e. i := i+1]].
|
||||
self gltf: { 0.0@0.0. 0.0@ (extent y). extent. (extent x) @0. } do:[:x :y|
|
||||
block value: i value:x.
|
||||
block value: i + 1 value: y.
|
||||
block value: i + 2 value: 0.0.
|
||||
i := i+3].
|
||||
]
|
||||
|
@ -53,9 +53,9 @@ DiyaRendererContext >> initialize [
|
||||
vao bind.
|
||||
vbo bind: GL_ARRAY_BUFFER.
|
||||
projection := Array2D identity: 4.
|
||||
buffer := FFIExternalArray externalNewType: GLfloat size: 128.
|
||||
buffer := FFIExternalArray externalNewType: GLfloat size: 32.
|
||||
buffer autoRelease.
|
||||
vbo data: GL_ARRAY_BUFFER data: nil size:512 usage: GL_DYNAMIC_DRAW.
|
||||
vbo data: GL_ARRAY_BUFFER data: nil size:128 usage: GL_DYNAMIC_DRAW.
|
||||
|
||||
]
|
||||
|
||||
|
@ -5,7 +5,8 @@ Class {
|
||||
'fontStyle',
|
||||
'fontSize',
|
||||
'fontName',
|
||||
'data'
|
||||
'data',
|
||||
'style'
|
||||
],
|
||||
#pools : [
|
||||
'FT2Types'
|
||||
@ -35,30 +36,25 @@ DiyaText >> data: anObject [
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> draw [
|
||||
|face offset|
|
||||
| offset|
|
||||
data ifNil: [ ^self ].
|
||||
offset := 100.0@100.0.
|
||||
offset := 0.0@0.0.
|
||||
OpenGL enable: GL_CULL_FACE.
|
||||
OpenGL enable: GL_BLEND.
|
||||
OpenGL enable: GL_TEXTURE_2D.
|
||||
OpenGL blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA.
|
||||
self shader use.
|
||||
self shader setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat.
|
||||
self shader setUniform: #u_projection value: context projection buffer.
|
||||
self shader setUniform: #u_texture value: 0.
|
||||
self 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 }.
|
||||
].
|
||||
face := DiyaFontManager uniqueInstance face: self fontStyle from: self fontName.
|
||||
"set fontsize"
|
||||
face setPixelWidth:0 height: self fontSize.
|
||||
style := DiyaFontManager uniqueInstance style: self fontStyle from: self fontName.
|
||||
OpenGL pixelstorei: GL_UNPACK_ALIGNMENT param: 1.
|
||||
"configure vao vbo for texture QUAD"
|
||||
context texture0 active.
|
||||
context vao enableAttribute: 0.
|
||||
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil .
|
||||
data do:[:c | self drawCharacter: c at: offset with: face.].
|
||||
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil .
|
||||
data do:[:c | self drawCharacter: c at: offset].
|
||||
context vao disableAttribute: 0.
|
||||
"reset value"
|
||||
OpenGL pixelstorei: GL_UNPACK_ALIGNMENT param: 4.
|
||||
@ -68,46 +64,46 @@ DiyaText >> draw [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> drawCharacter: c at: offset with: face [
|
||||
DiyaText >> drawCharacter: c at: offset [
|
||||
|tex2D|
|
||||
face loadCharacter: c asciiValue flags: (1 << 2) "FT_LOAD_RENDER".
|
||||
tex2D := OpenGLTexImage2D new target: GL_TEXTURE_2D;
|
||||
level: 0;
|
||||
internalFormat: GL_RED;
|
||||
width: face glyph width;
|
||||
height: face glyph height;
|
||||
border: 0;
|
||||
format: GL_RED;
|
||||
type: GL_UNSIGNED_BYTE;
|
||||
data: (FTFaceRec fromHandle: face getHandle) glyph bitmap buffer;
|
||||
yourself.
|
||||
tex2D := style loadChar: c asciiValue size: self fontSize.
|
||||
context texture0 setImage2D: tex2D.
|
||||
OpenGLTexture parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_S param: GL_CLAMP_TO_EDGE.
|
||||
OpenGLTexture parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_T param: GL_CLAMP_TO_EDGE.
|
||||
OpenGLTexture parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MIN_FILTER param: GL_LINEAR.
|
||||
OpenGLTexture parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MAG_FILTER param: GL_LINEAR.
|
||||
"fill the buffer"
|
||||
self fillVerticesBuffer: context buffer at: offset with: face.
|
||||
context vbo subData: GL_ARRAY_BUFFER offset:0 data: context buffer.
|
||||
((offset x > extent x) and: (tex2D width > 0)) ifTrue:[
|
||||
offset setX: 0.0 setY: (offset y )- (tex2D linespace * (self scale y)).].
|
||||
self fillVerticesBuffer: context buffer at: offset tex: tex2D.
|
||||
context vbo subData: GL_ARRAY_BUFFER offset: 0 data: context buffer.
|
||||
OpenGL drawArrays: GL_TRIANGLES first:0 count:6.
|
||||
offset setX: (offset x + ((face glyph advanceX )* (self scale x)) ) setY: offset y.
|
||||
offset setX: (offset x + ((tex2D advance x )* (self scale x)) ) setY: offset y.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fillVerticesBuffer: buffer at: offset with: face [
|
||||
|x y w h i|
|
||||
x := offset x + ((face glyph hBearingX )*(self scale x)).
|
||||
y := offset y - (((face glyph height) - (face glyph hBearingY))*(self scale y)).
|
||||
w := (face glyph width)*(self scale x).
|
||||
h := (face glyph height)*(self scale y).
|
||||
DiyaText >> fillVerticesBuffer: buffer at: offset tex: tex [
|
||||
|x y w h i uvs|
|
||||
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).
|
||||
i := 1.
|
||||
{x. y + h. 0.0. 0.0.
|
||||
uvs := { 0@0. 0@1. 1@1. 0@0. 1@1. 1@0 }.
|
||||
self gltf:{x@(y+h). x@y. (x+w)@y. x@(y+h). (x+w)@y. (x+w)@(y+h). } do:[:cx :cy| |uv|
|
||||
uv := uvs at: ((i -1)/4) + 1.
|
||||
buffer at:i put: cx.
|
||||
buffer at: i +1 put: cy.
|
||||
buffer at: i + 2 put: uv x.
|
||||
buffer at: i + 3 put: uv y.
|
||||
i := i+4.
|
||||
].
|
||||
"{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. }
|
||||
do: [ :e| buffer at:i put:e. i := i+1 ]
|
||||
x + w. y + h. 1.0. 0.0. }"
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -117,7 +113,7 @@ DiyaText >> fontName [
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontName: anObject [
|
||||
fontName := anObject
|
||||
fontName := anObject.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -127,7 +123,7 @@ DiyaText >> fontSize [
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontSize: anObject [
|
||||
fontSize := anObject
|
||||
fontSize := anObject.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -137,14 +133,14 @@ DiyaText >> fontStyle [
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontStyle: anObject [
|
||||
fontStyle := anObject
|
||||
fontStyle := anObject.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaText >> initialize [
|
||||
super initialize.
|
||||
fontStyle := 'Regular'.
|
||||
fontName := 'Ubuntu'.
|
||||
fontSize := 40.
|
||||
self fontName: 'Ubuntu'.
|
||||
self fontStyle: 'Regular'.
|
||||
self fontSize: 14.
|
||||
data := nil.
|
||||
]
|
||||
|
@ -63,6 +63,11 @@ OpenGL class >> end [
|
||||
^ self ffiCall: #(void glEnd( void ))
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
OpenGL class >> getError [
|
||||
^self ffiCall: #(GLenum glGetError( void))
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
OpenGL class >> getIntegerv: pname data: data [
|
||||
^self ffiCall: #(void glGetIntegerv( GLenum pname,GLint * data))
|
||||
|
@ -38,6 +38,7 @@ Class {
|
||||
'GL_LINE_LOOP',
|
||||
'GL_LINE_STRIP',
|
||||
'GL_LINK_STATUS',
|
||||
'GL_MAX_TEXTURE_SIZE',
|
||||
'GL_ONE_MINUS_SRC_ALPHA',
|
||||
'GL_PACK_ALIGNMENT',
|
||||
'GL_POINTS',
|
||||
@ -45,6 +46,7 @@ Class {
|
||||
'GL_QUADS',
|
||||
'GL_QUAD_STRIP',
|
||||
'GL_RED',
|
||||
'GL_RGB',
|
||||
'GL_SHADER_SOURCE_LENGTH',
|
||||
'GL_SHADER_TYPE',
|
||||
'GL_SHORT',
|
||||
@ -103,7 +105,8 @@ OpenGLConstants class >> initCommonConstants [
|
||||
GL_RED := 16r1903.
|
||||
GL_BLUE := 16r1905.
|
||||
GL_GREEN := 16r1904.
|
||||
GL_ALPHA := 16r1903.
|
||||
GL_ALPHA := 16r1906.
|
||||
GL_RGB := 16r1907.
|
||||
]
|
||||
|
||||
{ #category : #'class initialization' }
|
||||
@ -166,6 +169,7 @@ OpenGLConstants class >> initTextureConstants [
|
||||
GL_TEXTURE_MAG_FILTER := 16r2800.
|
||||
GL_LINEAR := 16r2601.
|
||||
GL_TEXTURE_UNIT_BASE := 16r84C0.
|
||||
GL_MAX_TEXTURE_SIZE := 16r0D33
|
||||
|
||||
]
|
||||
|
||||
|
71
Diya/OpenGLFontTex.class.st
Normal file
71
Diya/OpenGLFontTex.class.st
Normal file
@ -0,0 +1,71 @@
|
||||
Class {
|
||||
#name : #OpenGLFontTex,
|
||||
#superclass : #OpenGLTexImage2D,
|
||||
#instVars : [
|
||||
'bearing',
|
||||
'advance',
|
||||
'linespace'
|
||||
],
|
||||
#pools : [
|
||||
'OpenGLConstants',
|
||||
'OpenGLTypes'
|
||||
],
|
||||
#category : #'Diya-Fonts'
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
OpenGLFontTex class >> fromFace: face [
|
||||
^self new fromFace: face; yourself
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> advance [
|
||||
^ advance
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> advance: anObject [
|
||||
advance := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> bearing [
|
||||
^ bearing
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> bearing: anObject [
|
||||
bearing := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> fromFace: aFTFace [
|
||||
|size glyph rec|
|
||||
glyph := aFTFace glyph.
|
||||
size := glyph width * glyph height.
|
||||
data := FFIExternalArray externalNewType: #uint8 size:size.
|
||||
rec := (FTFaceRec fromHandle: aFTFace getHandle).
|
||||
data autoRelease.
|
||||
LibC memCopy: (rec glyph bitmap buffer) to:data getHandle size: size.
|
||||
level := 0.
|
||||
internalFormat := GL_ALPHA.
|
||||
width := glyph width.
|
||||
height := glyph height.
|
||||
linespace := (rec size metrics height / 64) asInteger.
|
||||
border := 0.
|
||||
format := GL_ALPHA.
|
||||
type := GL_UNSIGNED_BYTE.
|
||||
target := GL_TEXTURE_2D.
|
||||
bearing := (glyph hBearingX )@ (glyph hBearingY).
|
||||
advance := (glyph advanceX )@ (glyph advanceY).
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> linespace [
|
||||
^ linespace
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLFontTex >> linespace: anObject [
|
||||
linespace := anObject
|
||||
]
|
@ -39,6 +39,19 @@ OpenGLTexImage2D >> data: anObject [
|
||||
data := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLTexImage2D >> debug [
|
||||
self
|
||||
stdlog: 'Target:',target hex;
|
||||
stdlog: 'level:',level asString;
|
||||
stdlog: 'border :',border asString;
|
||||
stdlog: 'width :',width asString;
|
||||
stdlog: 'height :',height asString;
|
||||
stdlog: 'type :',type hex;
|
||||
stdlog: 'format :',format hex;
|
||||
stdlog: 'internalformat :',internalFormat hex
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLTexImage2D >> format [
|
||||
^ format
|
||||
|
@ -88,9 +88,19 @@ OpenGLTexture >> initialize [
|
||||
unit := 0.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
OpenGLTexture >> maxTextureSize [
|
||||
|ptr v|
|
||||
ptr := FFIExternalArray externalNewType: GLint size:1.
|
||||
ptr at:1 put: -1.
|
||||
OpenGL getIntegerv: GL_MAX_TEXTURE_SIZE data: ptr getHandle.
|
||||
v := ptr at:1.
|
||||
ptr free.
|
||||
^v
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
OpenGLTexture >> setImage2D: tex2D [
|
||||
self active.
|
||||
self bind: tex2D target.
|
||||
self class image2D: tex2D target
|
||||
level: tex2D level
|
||||
@ -100,7 +110,7 @@ OpenGLTexture >> setImage2D: tex2D [
|
||||
border: tex2D border
|
||||
format: tex2D format
|
||||
type: tex2D type
|
||||
data: tex2D data
|
||||
data: tex2D data getHandle.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
|
@ -17,134 +17,8 @@ uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
void main(void) {
|
||||
gl_FragColor = texture2D(u_texture, texcoord); //vec4(1, 1, 1, texture2D(u_texture, texcoord).r) * vec4(1,1,1,1);
|
||||
}'!
|
||||
|
||||
|pkgn dest pkg fileReference fileName writer core hePackage ignoresClasses|
|
||||
FFIMethodRegistry resetAll.
|
||||
dest := Smalltalk arguments first.
|
||||
pkgn := Smalltalk arguments at:2.
|
||||
|
||||
core := HEPackage new.
|
||||
core classes: OrderedCollection new.
|
||||
core traits: OrderedCollection new.
|
||||
core extensionMethods: OrderedCollection new.
|
||||
core packageName: pkgn.
|
||||
|
||||
packages := #(
|
||||
'Kernel-Chronology-Extras'
|
||||
'Jobs'
|
||||
'Collections-Arithmetic'
|
||||
'Ring-Deprecated-Core-Kernel'
|
||||
'Math-Operations-Extensions'
|
||||
'Collections-Atomic'
|
||||
'Collections-DoubleLinkedList'
|
||||
'DeprecatedFileStream'
|
||||
'Zinc-Resource-Meta-Core'
|
||||
'Zinc-Character-Encoding-Core'
|
||||
'FileSystem-Core'
|
||||
'FileSystem-Disk'
|
||||
'FileSystem-Memory'
|
||||
'Compression'
|
||||
'FileSystem-Zip'
|
||||
'Multilingual-Encodings'
|
||||
'Multilingual-Languages'
|
||||
'Multilingual-TextConversion'
|
||||
'Text-Core'
|
||||
'AST-Core'
|
||||
'Debugging-Core'
|
||||
'OpalCompiler-Core'
|
||||
'Kernel-Traits'
|
||||
'AST-Core-Traits'
|
||||
'Collections-Abstract-Traits'
|
||||
'Transcript-Core-Traits'
|
||||
'TraitsV2-Compatibility'
|
||||
'Alien-Core'
|
||||
'System-Model'
|
||||
'PragmaCollector'
|
||||
'UnifiedFFI'
|
||||
'UnifiedFFI-Legacy'
|
||||
'Slot-Core'
|
||||
'System-Localization'
|
||||
'STON-Core'
|
||||
'Diya'
|
||||
"
|
||||
'Graphics-Primitives'
|
||||
'Graphics-Transformations'
|
||||
'Graphics-Canvas'
|
||||
'FreeType'
|
||||
'Graphics-Display Objects'
|
||||
'EmbeddedFreeType'
|
||||
'Text-Scanning'
|
||||
'Multilingual-OtherLanguages'
|
||||
'Multilingual-TextConverterOtherLanguages'
|
||||
'Graphics-Fonts'
|
||||
'System-FileRegistry'
|
||||
'Graphics-Files'
|
||||
'Graphics-Shapes'"
|
||||
).
|
||||
|
||||
ignoresClasses := {
|
||||
RGCommentDefinition.
|
||||
RGMethodDefinition.
|
||||
ChangeRecord.
|
||||
PluggableListMorph.
|
||||
TextLine.
|
||||
TransformMorph.
|
||||
StringMorph.
|
||||
AthensCairoSDLSurface.
|
||||
SourceFileArray.
|
||||
GlyphForm
|
||||
}.
|
||||
|
||||
packages do:[:name | |pkg trait classes extensionMethods|
|
||||
Transcript show: 'Processing package ',name;cr.
|
||||
FFIMethodRegistry resetAll.
|
||||
pkg := RPackageOrganizer default packageNamed: name asSymbol.
|
||||
traits := (pkg definedClasses select: #isTrait) do: [ :e | core traits add:(HETrait for: e) ].
|
||||
(pkg definedClasses reject: #isTrait) do: [ :e |
|
||||
(ignoresClasses includes:e superclass) ifFalse:[
|
||||
core addClass: (HEClass for: e) ].
|
||||
].
|
||||
pkg extensionMethods do: [ :e |
|
||||
(ignoresClasses includes:e classBinding value) ifFalse:[
|
||||
core extensionMethods add:(HEMethod for: e)
|
||||
]
|
||||
].
|
||||
].
|
||||
|
||||
"SDL binding class"
|
||||
pkg := RPackageOrganizer default packageNamed: 'OSWindow-SDL2' asSymbol.
|
||||
(pkg classNamesForClassTag: 'Bindings') do:[:e|
|
||||
(ignoresClasses includes:e asClass) ifFalse:[
|
||||
core addClass:(HEClass for:e asClass) ]].
|
||||
|
||||
"FreeType binding class"
|
||||
|
||||
pkg := RPackageOrganizer default packageNamed: 'FreeType' asSymbol.
|
||||
(pkg classNamesForClassTag: 'Base') do:[:e|
|
||||
(ignoresClasses includes:e asClass) ifFalse:[
|
||||
core addClass:(HEClass for:e asClass) ]].
|
||||
(pkg classNamesForClassTag: 'Bindings') do:[:e|
|
||||
(ignoresClasses includes:e asClass) ifFalse:[
|
||||
core addClass:(HEClass for:e asClass) ]].
|
||||
"fixing some missing classes"
|
||||
core addClass: (HEClass for:OSWindowPlatformSpecificHandle);
|
||||
addClass: (HEClass for:ChunkWriteStream);
|
||||
addClass: (HEClass for:ChunkReadStream);
|
||||
addClass: (HEClass for:STCommandLineHandler);
|
||||
addClass: (HEClass for:FreeTypeFace)
|
||||
.
|
||||
|
||||
fileReference := (dest,'/',(pkgn replaceAll: Character space with: $-),'.hermes') asFileReference.
|
||||
fileName := fileReference fullName.
|
||||
writer := HEBinaryReaderWriter new
|
||||
stream: (File openForWriteFileNamed:fileName);
|
||||
yourself.
|
||||
core writeInto: writer.
|
||||
|
||||
writer stream flush.
|
||||
Transcript show: 'File exported to ', dest, '/', pkgn, '.hermes'; cr.
|
||||
gl_FragColor = vec4(1, 1, 1, texture2D(u_texture, texcoord).a) * vec4(1,1,1,1);
|
||||
}'
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
|
Loading…
Reference in New Issue
Block a user