0

Can we pass additional parameter to glutKeyboardFunc? I have a class and I want to modify the data of the class when certain key is pressed. The class is in global scope but the object of the class is local to certain function. Further I don't want to make the object global.

pranphy
  • 1,787
  • 4
  • 16
  • 22
  • 2
    Unfortunately, GLUT's all about global data. It doesn't have a concept of passing data with callback functions. – radical7 Feb 18 '13 at 20:16
  • If the object is in a local function, then it will be destroyed when the function exits. What are you hoping will happen when your KeyboardFunc is called with a reference to the destroyed object? – Drew Dormann Feb 18 '13 at 20:18
  • @DrewDormann: It really depends on the capabilities of the programming language used. For example if the OP was using a language with built in support for closures or delegates it would work just fine. For example the D programming language supports this. Also passing additional parameters is a piece of cake if using a functional language. Either use a lambda function, or if the feature is available use currying; Haskell would be a language supporting this. And to be fair, using the ffcall library, you can even create closures with C. – datenwolf Feb 18 '13 at 22:27
  • Let's assume you have a `glutKeyboardFunc(onKeyboard);` call, so `onKeyboard` is the keyboard callback. In this function, you can call your object's setter method which modifies the appropriate variable's value depending on the key pressed. Why don't you do it this way? – Sk8erPeter Feb 28 '13 at 21:03
  • Could you please elaborate a bit about **setter method** , I am unaware about this term. – pranphy Mar 01 '13 at 05:27

0 Answers0