I'm new to OpenGL and C++. Say I start with a 2D square (on the very left) like shown in the picture below. I want to make it interactive with the glutKeyboardFunc()
so when I press a number a new box will draw next to the corresponding edge.
Figure the best way to do this is to have a tree structure that hold all the boxes. But I'm not sure how I can hold basic primitives into a data structure, a tree, for instance.
I'm aware that I can only call the glutDisplayFunc(myDisplay)
once, and the rest should handle by the glutKeyboardFunc()
Any help would be appreciated :)
Update: thanks for pointing out glutPostRedisplay()
but what if I want to make the box selectable and keep tracking the current selected box with glutMouseFunc()
, and from there when I add more boxes, I need to know how many child box it has created, so I can provide the right position when new box is drawn. Seems that makes more sense now to use a tree data structure ? Just not sure how I can store the information I need into a tree.