abcdef
abcdef

Reputation: 246

opengl function which displays in a key callback function

I'm using openGL using GLUT. I'm making my own header file with some functions. One of them is a rectangle where you can enter digits and save them. the problem here is that the if I want to know wich key is pressed, I need to put the function in de keyboardFunc callback, but I also want to display the rectangle, so I also need to put it in the display callback because you can't draw anything in the keyboard callback function.

I can make two functions: one for to display the rectangle and one for the keys, but I want one function for both. How can I do this?

Upvotes: 1

Views: 1227

Answers (2)

Andrew
Andrew

Reputation: 1784

GLFW is almost the same as GLUT for everything you want but it doesnt make everything a nightmare like GLUT does. You get to control your display function! In GLFW you can define your own call back when a key is pressed. That callback can then save the char pressed into a vector or char array if its fixed length. You will then be able to render the text in your display loop. Be careful with accessing the text array you may need some control over that.

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409166

You can't, as you say yourself. You have to use one function to handle the keyboard events, and one for doing the drawing.

What you can do, is save all valid key-presses in a global variable, and in the display function simply draw them.

If you want to tell GLUT to redisplay as soon as possible, you can call glutPostRedisplay in the keyboard callback function.

Upvotes: 1

Related Questions