mirror of
https://github.com/lxsang/Diya-API.git
synced 2025-03-12 10:32:48 +01:00
correct mouse position inside shader coodinate system
This commit is contained in:
parent
81548622cc
commit
1ebd4a748c
@ -80,11 +80,11 @@ DiyaBoot >> initialize [
|
|||||||
DiyaBoot >> processEvent: event [
|
DiyaBoot >> processEvent: event [
|
||||||
|mappedEvt|
|
|mappedEvt|
|
||||||
mappedEvt := event mapped.
|
mappedEvt := event mapped.
|
||||||
mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...'. ^running := false. ].
|
mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...';cr. ^running := false. ].
|
||||||
mappedEvt type = SDL_QUIT ifTrue:[ ^running:= false ].
|
mappedEvt type = SDL_QUIT ifTrue:[ ^running:= false ].
|
||||||
mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ].
|
mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ].
|
||||||
mappedEvt type = SDL_FINGERMOTION ifTrue:[^self setCursorPosition: mappedEvt ].
|
mappedEvt type = SDL_FINGERMOTION ifTrue:[^self setCursorPosition: mappedEvt ].
|
||||||
mappedEvt type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: mappedEvt].
|
mappedEvt type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: (mappedEvt x) @ (mappedEvt y)].
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
|
@ -15,8 +15,10 @@ uniform vec2 u_mouse;
|
|||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 mouse = vec2(u_mouse)/vec2(u_resolution);
|
vec2 mouse = u_mouse / u_resolution;
|
||||||
gl_FragColor = vec4(mouse.x, mouse.y, abs(sin(u_time)), 1.0);
|
vec2 px = (gl_FragCoord.xy/u_resolution);
|
||||||
|
|
||||||
|
gl_FragColor = vec4(px/mouse, abs(sin(u_time)), 1.0);
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
]
|
]
|
||||||
|
@ -214,7 +214,7 @@ OpenGLSL >> locateUniforms [
|
|||||||
OpenGLSL >> setUniform: uname value: values [
|
OpenGLSL >> setUniform: uname value: values [
|
||||||
|uniform|
|
|uniform|
|
||||||
uniform := uniforms at: uname asSymbol ifAbsent:[
|
uniform := uniforms at: uname asSymbol ifAbsent:[
|
||||||
^self error: 'Uniform', uname, 'is not defined in this program'].
|
^self error: 'Uniform ', uname, ' is not defined in this program'].
|
||||||
uniform value: values
|
uniform value: values
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ SimpleDiyaRenderer >> initialize [
|
|||||||
super initialize.
|
super initialize.
|
||||||
vertexBuffer := OpenGLVertexBuffer new.
|
vertexBuffer := OpenGLVertexBuffer new.
|
||||||
arrayBuffer := OpenGLVertexArray new.
|
arrayBuffer := OpenGLVertexArray new.
|
||||||
bufferData := FFIExternalArray externalNewType: GLfloat size: 9.
|
bufferData := FFIExternalArray externalNewType: GLfloat size: 12.
|
||||||
bufferData autoRelease.
|
bufferData autoRelease.
|
||||||
shader := GLSimpleShader uniqueInstance.
|
shader := GLSimpleShader uniqueInstance.
|
||||||
|
|
||||||
@ -36,13 +36,15 @@ SimpleDiyaRenderer >> render [
|
|||||||
shader setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat.
|
shader setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat.
|
||||||
shader setUniform: #u_resolution value: { context resolution x. context resolution y }.
|
shader setUniform: #u_resolution value: { context resolution x. context resolution y }.
|
||||||
context mouse ifNotNil: [
|
context mouse ifNotNil: [
|
||||||
shader setUniform: #u_mouse value: { context mouse x. context mouse y }.
|
"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 }.
|
||||||
].
|
].
|
||||||
|
|
||||||
arrayBuffer enableAttribute: 0.
|
arrayBuffer enableAttribute: 0.
|
||||||
vertexBuffer bind: GL_ARRAY_BUFFER.
|
vertexBuffer bind: GL_ARRAY_BUFFER.
|
||||||
OpenGLVertexArray vertexAttributePointerIndex: 0 size:3 type: GL_FLOAT normalized: GL_FALSE stride: 0 pointer: nil .
|
OpenGLVertexArray vertexAttributePointerIndex: 0 size:3 type: GL_FLOAT normalized: GL_FALSE stride: 0 pointer: nil .
|
||||||
OpenGL drawArrays: GL_TRIANGLES first:0 count: 3.
|
OpenGL drawArrays: GL_QUADS first:0 count: 4.
|
||||||
arrayBuffer disableAttribute: 0.
|
arrayBuffer disableAttribute: 0.
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -55,9 +57,12 @@ bufferData
|
|||||||
at: 4 put: 1.0;
|
at: 4 put: 1.0;
|
||||||
at: 5 put: -1.0;
|
at: 5 put: -1.0;
|
||||||
at: 6 put: 0;
|
at: 6 put: 0;
|
||||||
at: 7 put: 0;
|
at: 7 put: 1.0;
|
||||||
at: 8 put: 1.0;
|
at: 8 put: 1.0;
|
||||||
at: 9 put: 0.
|
at: 9 put: 0;
|
||||||
|
at: 10 put: -1.0;
|
||||||
|
at: 11 put: 1.0;
|
||||||
|
at: 12 put: 0.
|
||||||
arrayBuffer bind.
|
arrayBuffer bind.
|
||||||
vertexBuffer bind: GL_ARRAY_BUFFER.
|
vertexBuffer bind: GL_ARRAY_BUFFER.
|
||||||
vertexBuffer data: GL_ARRAY_BUFFER data:bufferData usage: GL_STATIC_DRAW.
|
vertexBuffer data: GL_ARRAY_BUFFER data:bufferData usage: GL_STATIC_DRAW.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user