Browse Source

increased accuracy of mouse, some more shader polish

naelstrof 7 years ago
parent
commit
f812b2a2cb

+ 1
- 1
CMakeLists.txt View File

21
 
21
 
22
 include_directories("${PROJECT_BINARY_DIR}")
22
 include_directories("${PROJECT_BINARY_DIR}")
23
 
23
 
24
-add_definitions(-DSLOP_VERSION="v5.3.35")
24
+add_definitions(-DSLOP_VERSION="v5.3.36")
25
 
25
 
26
 # The names have to be unique unfortunately.
26
 # The names have to be unique unfortunately.
27
 set(EXECUTABLE_NAME "slop")
27
 set(EXECUTABLE_NAME "slop")

+ 26
- 0
shaderexamples/blur1.frag View File

1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform sampler2D desktop;
5
+uniform vec2 screenSize;
6
+
7
+varying vec2 uvCoord;
8
+
9
+// Stolen from https://github.com/Jam3/glsl-fast-gaussian-blur kinda
10
+void main()
11
+{
12
+    float radius = 1;
13
+    vec2 upsideDownUV = vec2( uvCoord.x, -uvCoord.y );
14
+    vec4 color = vec4(0.0);
15
+    vec2 off1 = vec2(1.411764705882353) * vec2( radius, 0 );
16
+    vec2 off2 = vec2(3.2941176470588234) * vec2( radius, 0 );
17
+    vec2 off3 = vec2(5.176470588235294) * vec2( radius, 0 );
18
+    color += texture2D(desktop, upsideDownUV) * 0.1964825501511404;
19
+    color += texture2D(desktop, upsideDownUV + (off1 / screenSize)) * 0.2969069646728344;
20
+    color += texture2D(desktop, upsideDownUV - (off1 / screenSize)) * 0.2969069646728344;
21
+    color += texture2D(desktop, upsideDownUV + (off2 / screenSize)) * 0.09447039785044732;
22
+    color += texture2D(desktop, upsideDownUV - (off2 / screenSize)) * 0.09447039785044732;
23
+    color += texture2D(desktop, upsideDownUV + (off3 / screenSize)) * 0.010381362401148057;
24
+    color += texture2D(desktop, upsideDownUV - (off3 / screenSize)) * 0.010381362401148057;
25
+    gl_FragColor = (texture2D(texture, uvCoord) * color);
26
+}

+ 12
- 0
shaderexamples/blur1.vert View File

1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 24
- 0
shaderexamples/blur2.frag View File

1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform vec2 screenSize;
5
+
6
+varying vec2 uvCoord;
7
+
8
+// Stolen from https://github.com/Jam3/glsl-fast-gaussian-blur kinda
9
+void main()
10
+{
11
+    float radius = 1;
12
+    vec4 color = vec4(0.0);
13
+    vec2 off1 = vec2(1.411764705882353) * vec2( 0, radius );
14
+    vec2 off2 = vec2(3.2941176470588234) * vec2( 0, radius );
15
+    vec2 off3 = vec2(5.176470588235294) * vec2( 0, radius );
16
+    color += texture2D(texture, uvCoord) * 0.1964825501511404;
17
+    color += texture2D(texture, uvCoord + (off1 / screenSize)) * 0.2969069646728344;
18
+    color += texture2D(texture, uvCoord - (off1 / screenSize)) * 0.2969069646728344;
19
+    color += texture2D(texture, uvCoord + (off2 / screenSize)) * 0.09447039785044732;
20
+    color += texture2D(texture, uvCoord - (off2 / screenSize)) * 0.09447039785044732;
21
+    color += texture2D(texture, uvCoord + (off3 / screenSize)) * 0.010381362401148057;
22
+    color += texture2D(texture, uvCoord - (off3 / screenSize)) * 0.010381362401148057;
23
+    gl_FragColor = color;
24
+}

+ 12
- 0
shaderexamples/blur2.vert View File

1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 43
- 0
shaderexamples/crosshair.frag View File

1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform sampler2D desktop;
5
+uniform vec2 screenSize;
6
+uniform vec2 mouse;
7
+
8
+varying vec2 uvCoord;
9
+
10
+void main()
11
+{
12
+    // adjustable parameters
13
+    float circleSize = 128;
14
+    float borderSize = 2;
15
+    // The smaller this value is, the more intense the magnification!
16
+    float magnifyNerf = 1.1;
17
+    vec4 borderColor = vec4(0,0,0,1);
18
+    bool crosshair = true;
19
+
20
+    // actual code
21
+    vec2 mUV = vec2(mouse.x, -mouse.y)/screenSize + vec2(0,1);
22
+    float du = distance(mUV,uvCoord);
23
+    float dr = distance(mUV*screenSize,uvCoord*screenSize);
24
+    vec4 color = vec4(0);
25
+    if ( dr > circleSize+borderSize ) {
26
+        color = texture2D( texture, uvCoord );
27
+    } else if ( dr < circleSize ) {
28
+        if ( crosshair && (distance(mUV.x, uvCoord.x)<1/screenSize.x || distance(mUV.y,uvCoord.y)<1/screenSize.y) ) {
29
+            color = borderColor;
30
+        } else {
31
+            float t = 1-du;
32
+            vec2 b = uvCoord;
33
+            vec2 c = (mUV-uvCoord);
34
+            vec2 upsideDown = c/magnifyNerf*t*t+b;
35
+
36
+            vec4 textureColor = texture2D( texture, upsideDown );
37
+            color = texture2D( desktop, vec2(upsideDown.x, -upsideDown.y) )*(1-textureColor.a) + textureColor;
38
+        }
39
+    } else if ( dr < circleSize+borderSize ) {
40
+        color = borderColor;
41
+    }
42
+    gl_FragColor = color;
43
+}

+ 12
- 0
shaderexamples/crosshair.vert View File

1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 21
- 0
shaderexamples/wiggle.frag View File

1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform vec2 screenSize;
5
+uniform float time;
6
+
7
+varying vec2 uvCoord;
8
+
9
+void main()
10
+{
11
+    // Higher strength means bigger wobble
12
+    float strength = 10;
13
+    float flatness = 4;
14
+    // Higher speed means faster wobble
15
+    float speed = 2;
16
+    float variation = cos(time);
17
+
18
+    float x = uvCoord.x + (sin( time*speed + uvCoord.y/flatness * screenSize.y/strength ) + 0.5)/screenSize.x*strength;
19
+    float y = uvCoord.y + variation*(cos( time*speed + uvCoord.x/flatness * screenSize.x/strength ) + 0.5)/screenSize.y*strength;
20
+    gl_FragColor = texture2D( texture, vec2( x, y ) );
21
+}

+ 12
- 0
shaderexamples/wiggle.vert View File

1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 5
- 2
src/framebuffer.cpp View File

6
     glGenTextures(1, &image);
6
     glGenTextures(1, &image);
7
     glBindTexture(GL_TEXTURE_2D, image);
7
     glBindTexture(GL_TEXTURE_2D, image);
8
     glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
8
     glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
9
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
10
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
9
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
10
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
11
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
11
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
12
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
12
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
13
     glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
13
     glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
41
 void slop::Framebuffer::setShader( slop::Shader* shader ) {
41
 void slop::Framebuffer::setShader( slop::Shader* shader ) {
42
     this->shader = shader;
42
     this->shader = shader;
43
     if ( shader->hasParameter( "desktop" ) && !generatedDesktopImage ) {
43
     if ( shader->hasParameter( "desktop" ) && !generatedDesktopImage ) {
44
+        // Try to keep the image from being changed under our feet.
45
+        XGrabServer(x11->display);
44
         XImage* image = XGetImage( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0xffffffff, ZPixmap );
46
         XImage* image = XGetImage( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0xffffffff, ZPixmap );
47
+        XUngrabServer(x11->display);
45
         glEnable(GL_TEXTURE_2D);
48
         glEnable(GL_TEXTURE_2D);
46
         glGenTextures(1, &desktopImage);
49
         glGenTextures(1, &desktopImage);
47
         glBindTexture(GL_TEXTURE_2D, desktopImage);
50
         glBindTexture(GL_TEXTURE_2D, desktopImage);

+ 6
- 4
src/slopstates.cpp View File

94
     char a = startPoint.y > mouse->getMousePos().y;
94
     char a = startPoint.y > mouse->getMousePos().y;
95
     char b = startPoint.x > mouse->getMousePos().x;
95
     char b = startPoint.x > mouse->getMousePos().x;
96
     char c = (a << 1) | b;
96
     char c = (a << 1) | b;
97
+    int xm = (mouse->getMousePos().x == 0 || mouse->getMousePos().x == WidthOfScreen(x11->screen)-1);
98
+    int ym = (mouse->getMousePos().y == 0 || mouse->getMousePos().y == HeightOfScreen(x11->screen)-1);
97
     switch ( c ) {
99
     switch ( c ) {
98
         case 0: mouse->setCursor( XC_lr_angle );
100
         case 0: mouse->setCursor( XC_lr_angle );
99
-                memory.rectangle->setPoints(startPoint+glm::vec2(0,0), mouse->getMousePos()+glm::vec2(1,1));
101
+                memory.rectangle->setPoints(startPoint+glm::vec2(0,0), mouse->getMousePos()+glm::vec2(1*xm,1*ym));
100
                 break;
102
                 break;
101
         case 1: mouse->setCursor( XC_ll_angle );
103
         case 1: mouse->setCursor( XC_ll_angle );
102
-                memory.rectangle->setPoints(startPoint+glm::vec2(0,0), mouse->getMousePos()+glm::vec2(1,1));
104
+                memory.rectangle->setPoints(startPoint+glm::vec2(0,0), mouse->getMousePos()+glm::vec2(1*xm,1*ym));
103
                 break;
105
                 break;
104
         case 2: mouse->setCursor( XC_ur_angle );
106
         case 2: mouse->setCursor( XC_ur_angle );
105
-                memory.rectangle->setPoints(startPoint+glm::vec2(0,1), mouse->getMousePos()+glm::vec2(1,0));
107
+                memory.rectangle->setPoints(startPoint+glm::vec2(0,1*ym), mouse->getMousePos()+glm::vec2(1*xm,0));
106
                 break;
108
                 break;
107
         case 3: mouse->setCursor( XC_ul_angle );
109
         case 3: mouse->setCursor( XC_ul_angle );
108
-                memory.rectangle->setPoints(startPoint+glm::vec2(1,1), mouse->getMousePos()+glm::vec2(0,0));
110
+                memory.rectangle->setPoints(startPoint+glm::vec2(1*xm,1*ym), mouse->getMousePos()+glm::vec2(0,0));
109
                 break;
111
                 break;
110
     }
112
     }
111
     if ( !mouse->getButton( 1 ) ) {
113
     if ( !mouse->getButton( 1 ) ) {