Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: does opengl support object oriented paradigm

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Posts
    4

    does opengl support object oriented paradigm

    Hi ..
    I have just started learning Opengl and I have a fundamental doubt.....I want to know if object orientation is supported in Opengl.
    For example, while selecting an object from the viewscreen, can I directly access the object which it represents. In the sense, instead of pushing the name of the object into the namestack, by saying glPushName(objectname), can I instead push the pointer to the underlying object into the namestack ???
    Thanx...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    Re: does opengl support object oriented paradigm

    No, not at all - absolutely not. OpenGL does not `support' object oriented programming.

    That is something that programmers do. All of my code is Object Oriented for all of my OpenGL applications.

  3. #3
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: does opengl support object oriented paradigm

    Since it is just a number, converting your base object to an unsigned 32 seems like it should work. As long as when you get the number back, you cast it back to your base object pointer.
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  4. #4
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: does opengl support object oriented paradigm

    Oh, and as far as object oriented opengl...Robbo is right. Absolutely not supported.
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2002
    Posts
    4

    Re: does opengl support object oriented paradigm

    Hi..
    Thanx for the reply....Could u please let me know how object orientation can be implemented in opengl ??
    My main problem is , I have around 50,000 objects. When a primitive is selected in viewscreen, the unique id of that primtive would be pushed into the namestack. Now, in order to access the object itself I would need to search through the 50000 objects to match the unique id. This would be very inefficient.
    can u please suggest me if there is any other better way to do it....
    Thanx.

  6. #6
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: does opengl support object oriented paradigm

    Well, if you know what your base object pointer is, then that IS your object. When I say "base object" I am refering to the class at the top of the hierarchy from which all of your objects inherit from. From this, you can call virtual functions on your specific object.
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2002
    Posts
    4

    Re: does opengl support object oriented paradigm

    I have been thinking about typecasting but, the problem in doing that is twofold .. One, there are multiple base classes, so with just the unsigned int , I will not be aware of the object that I would need to typecast it to.
    Secondly, I feel that is not a good idea to do direct typecasting and mess around with memory locations. This I feel is not object oriented bcoz something like this can be better done in C , where the compiler is more forgiving with respect to typecasting.
    So, I am wondering if there is a way around this..
    Thanx..

  8. #8
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    Re: does opengl support object oriented paradigm

    There is absolutely no way you should be passing in a pointer as a name (pushing and retrieving it). It is just a happy coincidence that your 32 bit pointer = a value you can push on the name stack.

    If you want to be object oriented with your selection, you will need to loop through a list of candidates instances of some base class, looking at its name id:

    class MyObjectBase {

    public:

    int m_glName;

    };

    for ( int c = 0; c < Size; c++ )
    {
    if ( Object [c].m_glName == SelectedName ) {
    .... Object has been selected
    }
    }

    I should say also that having 50,000 possible candidates is not a good idea. You really should be performing some kind of frustum culling, so only a subset of your 50,000 are sent through the picking render in the first case.

    Hope this helps some.

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    Johannesburg, Gauteng, South-Africa
    Posts
    12

    Re: does opengl support object oriented paradigm

    If you absolutely want to stick to your 50 000
    objects, make sure the objects are ordered, and use a binary search perhaps to speed up your search.

  10. #10
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: does opengl support object oriented paradigm

    Yes, make sure you use the right saerch method. Don't store them in one huge linear list, like an array, and search element by element until you get a hit. For example, if you use C++, which I assume you do since you talk about base classes, use the map container in the STL library, and store the object id mapped to the actual object. With a 50000 object list, you (read, the map) should be able to get the correct object within an average of about 20 searches.

    Should be something like this.
    Code :
    #include <map>
    using namespace std;
    struct myObject
    {
        ...
    };
    map<unsigned int, myObject> mapIdToObject;

Page 1 of 2 12 LastLast

Similar Threads

  1. Ork: a new object-oriented API on top of OpenGL
    By Eric Bruneton in forum OpenGL: General
    Replies: 17
    Last Post: 11-20-2010, 03:32 PM
  2. Object Oriented OpenGL
    By alberto in forum OpenGL: Advanced Coding
    Replies: 15
    Last Post: 09-13-2007, 11:36 AM
  3. Object-Oriented OpenGL
    By ethorteran in forum OpenGL: General
    Replies: 7
    Last Post: 09-10-2001, 04:46 AM
  4. Object Oriented OpenGL!
    By ms3d in forum OpenGL: General
    Replies: 8
    Last Post: 03-08-2001, 12:12 AM
  5. Object Oriented Programming with OpenGL
    By Frank Black in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-03-2000, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean