GLGroup class


I would like to implement a GLGroup class which would contain a collection of OPenGL objects (spheres, cubes etc).

In this class I see that there would be a pointer keeping track of objects list and some members like
and one

My main problem is that I want to be able to select those objects on the screen and tell which one I have selected somehow

so in the selection mode I will have a

loop over objects

But I add/delete objects from the list how do I keep track of their names?

You associate the names with the objects, it is entirely up to you what you want to do with the names. The name does not have to be a list index, it could be cast from a pointer for example.

could you please give me a brief example of how you would write this class?

I’m not talking about writing a class, I’m talking about storing a pointer to your class as the name.

Or you could use an array of pointers and use i as the index you sent to the pick stack, however I’d just go with the direct cast and cast back.

I don’t understand what you mean by “the direct cast and cast back” can you pls give me an example?

Yeah dorbie, give him an example :stuck_out_tongue:

I’m going to answer, but I also want a moderator to move the answer to the “for beginners” section.


For each object, allocate a struct, which allows you to keep track of the object, which group it is in, etc.

The pointer to this struct can be cast to an int, on all 32-bit platforms, and on 64-bit platforms with 64-bit ints. Cast the pointer-to-struct to int for each object.

This casted pointer is your name. Now, when you get a specific name back, you just cast back to pointer, and dereference – voila, there is a struct telling you what the object is!

If you need to do this on a platform where names are 32 bit, but pointers are 64 bit, you can also just put all the different struct pointers into a vector, and make the index into the vector be the name.

Thanks but I still don’t understand this casting stuff.

What I plan to do is:

  1. Create a GLobject class wich contains variables like name etc
  2. create a List Pointer (like QT’s QPtrList) containing all the GLobjects
  3. iterate thru the list and give i to PushName
  4. once I have i (the selected object) I can get the object via the List Pointer and then its name via its variable or a function.

Is there something wrong with this?

This is off topic, if you don’t know what a cast is or how to cast in C++ then you need to do some more work on your basic programming knowledge.

Closing thread now.