These are chat archives for opentk/opentk

30th
Apr 2018
chatbridge
@chatbridge
Apr 30 2018 06:14
(Discord) winterhell: it shouldnt
(Discord) winterhell: I can guess what is happening
(Discord) winterhell: with the first count you are drawing 1 cube
(Discord) winterhell: with the second drawing you are adding the next cube and changing the texture
(Discord) winterhell: so it renders both, but you already have the first cube occupying the same space as the first cube from the previous rendering, but with different texture
(Discord) winterhell: The second pass cube is culled by the Z-buffer
(Discord) winterhell: If you want you can try drawing the first object with one texture, then change the texture and redraw again and see if it changes or it keeps the same
chatbridge
@chatbridge
Apr 30 2018 15:57
(Discord) Zaphyk: how can I create a KeyboardKeyEventArgs and set it's fields? I need to simulate a key press for the sake of an automation test but it seems like the only constructor takes an already created KeyboardKeyEventArgs
(Discord) Zaphyk: any ideas?
chatbridge
@chatbridge
Apr 30 2018 16:04
(Discord) Hawk: try
new KeyboardKeyEventArgs 
{
    Key = Key.A
}
Ghost
@ghost~59d9ee50d73408ce4f7916bf
Apr 30 2018 16:10

Or easy explanation:

KeyboardState keyState = Keyboard.GetState();
if(keyState.isKeyDown(Key.A))
{
  ....
}

Please make sure Constructor or Update method with if else statement with input of Mouse and Keyboard.

chatbridge
@chatbridge
Apr 30 2018 16:26
(Discord) Zaphyk: @Hawk the thing is, Key has a private setter so I cant do that
chatbridge
@chatbridge
Apr 30 2018 16:31
(Discord) winterhell: You have couple of options
(Discord) winterhell: Basically you put
[DllImport("user32.dll")] static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
somewhere among the function declarations
(Discord) winterhell: And then
Process proc = Process.GetCurrentProcess(); PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_F5, 0);
(Discord) winterhell: This'll post the key to the same process/program you call it from
(Discord) Zaphyk: mmm
(Discord) winterhell: WM_KEYDOWN and VK_F5 are values from an enum
(Discord) Zaphyk: that will trigger the event for the while application
(Discord) Zaphyk: and I need to trigger it for a specific event listener
(Discord) winterhell: Or perhaps you want to send the key presses to a different program?
(Discord) winterhell: Sure the event listener is key presses
(Discord) winterhell: or key down
(Discord) Zaphyk: what I need is to just trigger a specifc class that is listening, not the entire process
(Discord) Zaphyk: I think I will create an empty KeyboardKeyEventArgs and change it's private fields via some nasty reflection
(Discord) winterhell: Then you use an Event
chatbridge
@chatbridge
Apr 30 2018 16:36
(Discord) winterhell: You make a custom event, and add it to that class
(Discord) winterhell: And you send the keys to the event
(Discord) winterhell: Perhaps here
(Discord) winterhell: The 3rd answer with the 4 Upvotes might be more consumable and tutorial like
(Discord) Zaphyk: It seems you are not understanding me, I'll give you an example. Imagine I have 3 listeners
public void ListenerA(object Sender, KeyboardKeyEventArgs EventArgs){}
public void ListenerB(object Sender, KeyboardKeyEventArgs EventArgs){}
public void ListenerC(object Sender, KeyboardKeyEventArgs EventArgs){}
(Discord) Zaphyk: I only want to trigger ListenerB
(Discord) Zaphyk: if I send a key press to the process I'll trigger the 3 of them
(Discord) Zaphyk: what I am looking to do is creating a custom KeyboardKeyEventArgs so I can do
(Discord) winterhell: That is exactly what the tutorial shows
chatbridge
@chatbridge
Apr 30 2018 16:41
(Discord) winterhell: public event Action<KeyboardKeyEventArgs>MyEvent;
private void MyEventHandler(KeyboardKeyEventArgs EventArgs) { //do your stuff here }
(Discord) winterhell: Then you trigger the event by
MyEvent(KeyPress);
(Discord) Zaphyk: that's what I am telling you
(Discord) Zaphyk: where do you get the KeyPress from?
(Discord) winterhell: You said you are generating it with the program
(Discord) winterhell: So that it can be automated
(Discord) Zaphyk: No, I said I need to generate it
(Discord) Zaphyk: that's the problem
(Discord) Zaphyk: I can't generate it
(Discord) winterhell: You lost me
(Discord) Zaphyk: let's start again
(Discord) Zaphyk: I need a new KeyboardKeyEventArgs
(Discord) Zaphyk: how do I create one?
(Discord) Jax (Nihlus): As far as I can see, you can't
(Discord) Jax (Nihlus): Looking at the source right now
(Discord) Jax (Nihlus): You can clone one
(Discord) Jax (Nihlus): But the key setter is internal
(Discord) winterhell: There is no KeyboardKeyEventArgs
chatbridge
@chatbridge
Apr 30 2018 16:46
(Discord) winterhell: use KeyPressEventArgs
(Discord) winterhell: This is OpenTK specific?
(Discord) Jax (Nihlus): Yes
(Discord) winterhell: Because KeyPressEventArgs is defined in both OpenTK and WindowsForms
(Discord) Zaphyk: @Jax (Nihlus) I see, I guess I will resort to reflection
(Discord) Zaphyk: thank you guys
(Discord) winterhell: Ah I see, KeyboardKeyEventArgs is defined in OpenTK.Input, thats why I didnt see it
(Discord) winterhell: OpenTK.Input.KeyboardKeyEventArgs myKey = new OpenTK.Input.KeyboardKeyEventArgs(); myKey.Key = OpenTK.Input.Key.BackSpace;
(Discord) Zaphyk: it has a private setter, you can't do that
(Discord) winterhell: Can you recompile OpenTK?
(Discord) Zaphyk: I'll use reflection
(Discord) winterhell: Reflection for what? It'll give you KeyPressEventArgs
(Discord) winterhell: But alright
chatbridge
@chatbridge
Apr 30 2018 16:55
(Discord) Zaphyk: for this
(Discord) Zaphyk: protected KeyboardKeyEventArgs SimulateKeyEvent(Key Press) { var keyEvent = new KeyboardKeyEventArgs(); keyEvent.GetType().GetField("key", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(keyEvent, Press); return keyEvent; }
(Discord) Zaphyk: then I can call
KeyboardKeyEventArgs keyEvent = this.SimulateKeyEvent(Key.W);
(Discord) winterhell: Wait so you use Reflection to set a private field that doesnt have a setter?
(Discord) Zaphyk: yeah
(Discord) winterhell: OOP is broken™
(Discord) Zaphyk: it's kind of hacky though
(Discord) Zaphyk: that's why I was looking for other options
(Discord) winterhell: I wish I knew about this 15 years ago so I could tell the teachers to stick it
chatbridge
@chatbridge
Apr 30 2018 17:02
(Discord) Jax (Nihlus): @winterhell Reflection is pretty much a free pass to tell the compiler to stick it
chatbridge
@chatbridge
Apr 30 2018 18:25
(Discord) tzachs: @Zaphyk another option would be to add an abstraction layer around the OpenTK events, so you
(Discord) tzachs: 're not relying on OpenTK implementation
(Discord) Zaphyk: yes, I thought of that but that would mean refactoring quite a bit of code which isnt really worth for making a test
chatbridge
@chatbridge
Apr 30 2018 18:36
(Discord) winterhell: @Jax (Nihlus) from time to time I see people here complaining that they cant get an OpenGL context when trying to connect remotely with a Linux server. Perhaps it could be similar to Windows where you have a retro compatibility function that is not being used. Unfortunately my knowledge of OGL on other platforms is limited
chatbridge
@chatbridge
Apr 30 2018 18:41
(Discord) Jax (Nihlus): Yeah, maybe