Reputation: 11
I am drawing a cube using OpenGL in a gtk drawing area widget. Now i want to attach events like "clicked" to the cube so that it can be selected for drag and drop etc. How should i proceed?
Upvotes: 1
Views: 637
Reputation: 162327
OpenGL is not a scene graph (*gah* I'm, getting tired, writing this again, and again, and again). It draws things. You give it a bunch of triangles in 3D space, and it projects them to 2D, draws them to your desire, then forgets about it.
After you've drawn your cube, there's no longer anything around in OpenGL that would identify it as a coherent structure. That's entirely on your part.
What you have to do is:
Keywords to follow are "OpenGL object picking"
so that it can be selected for drag and drop
BTW: You can't just drag around "objects" in OpenGL, because it doesn't know of "objects", in the sense of geometrical structures. OpenGL specifies objects, but those are actually abstracted sources of data, like textures or buffers of vertex and index data. Nothing that would make a manipulatable scene.
If you change something in a scene, with OpenGL you have to completely redraw it.
Upvotes: 6