smallbee
smallbee

Reputation: 343

keydown event not working in opngl langauge

How i can use keydown event in opengl language, here i paste some partial code but it not working, anyone help to fix this code.

bool keypress(int key) {
          return texelFetch(texture2D, ivec2(key,2),0).x != 0.0;  }

// in above code texture2D was iChannel0 so i change to texture2D according to my script but i think i mistake is this line

const int k = 17;      // 17 for CTRL

void main()
{ 
        vec2 p = gl_FragCoord.xy;
        vec2 uv = p / resolution.xy;
    
    float blend = 1.9-pow(1.5*cos(time/8.0),5.0);
    
        vec3 cul = texture2D(media, uv).rgb;
        vec3 col = texture2D(media, uv).rgb;
         
          if (keypress(k)) col = mix(cul,col,blend); 
         gl_FragColor = vec4(col, 1.0);
}

When i press CTRL key it will not execute this ==>> col = mix(cul,col,blend);
I don't know where i mistake.

Upvotes: 0

Views: 78

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474016

Shaders do not execute in any place where "keypress" is a thing that happens. Shaders are not like HTML or CSS properties in Javascript, where changing a property updates the view. You render something, and that rendering causes shaders to be executed. If you want to change how things are rendered, you must explicitly render them again.

If you want something to be rendered differently based on a keypress, then your keypress Javascript routine needs to set some state and tell your code to re-render the scene. The rendering code will use this state to adjust shader uniforms or other data accessible to your rendering system and then draw everything again.

For example:

const int k = 17;

That is a constant; hence the keyword const. It doesn't change. Ever. It's always 17. If you want to pass a value to the shader that represents a key, you would need a uniform, UBO, or something of the like. Certainly not a constant.

Upvotes: 2

Related Questions