Results 1 to 6 of 6

Thread: Objects in GL

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Objects in GL

    I would like to make some sort of object support in my game engine. So it would be nice if I could define every object from vertex+bounding box data & maybe even some physics stuff. Only thing I can imagine right now is classes, but I still can't see how to implement that till the end. Maybe someone have tried that allready and could give me advice. The current sitution is that I must calculate physical&collision data & then draw geometry. But they aren't connected as one data stream. BTW, clases are prety costly, arn't they?

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2001
    Location
    Toledo OH
    Posts
    29

    Re: Objects in GL

    I usualy use dynamic arrays of structs, there pretty light weight.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Objects in GL

    Classes aren't that costly unless you mis-use them.
    Deiussum
    Software Engineer and OpenGL enthusiast

  4. #4
    Member Newbie
    Join Date
    Jun 2002
    Posts
    33

    Re: Objects in GL

    Hi,

    I often hear alot about using classes being expensive and alot of people defend them saying that as long as you use them correctly it will still be fast. Could you expand more on what you have to do to a class/program to make sure that they run quickly. (mention things even if you think they are too basic I am a self taught C++ person so my knowledge is patchy)

    Cheers, fringe

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: Objects in GL

    I did a little benchmark recently that showed me classes are _exactly_ as fast as structures (something a short time ago I was refusing in advanced forum, lol! ).
    You shouldn't be afraid to use classes even for smallest beings like vectors or triangles. Sizes of class and struct with same arguments are eqaul, not what some may think (I did too) they require some extra bytes.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Objects in GL

    I tend to use structs for things like vectors, vertices, color, etc. Usually I use classes for larger entities such as objects consisting of triangle strips, lists of objects, world data, etc.

    Some things that you can do to keep classes performing well include:

    - Use inline functions for simple Get/Set functions.
    - Don't rely too heavily on overloading operators. There can be some extra overhead involved in this. It's not something I would say avoid completely, but just be aware of where the overhead lies when you do use them. (Extra copying, function call overhead if not inline, etc.)
    - Where possible, provide constructors that can take in values to initialize the class.

    Anyway, I'm sure there are more things that I'm not thinking of at the moment, but I think the first couple points above are a couple of the biggest areas you can look at when keeping classes perfoming well.

    Just like in C, though, the absolute BEST way to keep your code running nicely is to use the right algorithm. If you use an algorithm that is O(n^3) for something that only requires an algorithm that is O(n), it doesn't matter what language you use, you're going to get less than ideal results.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. depth buffer: far objects bleed through closer objects
    By geohoffman49431 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-15-2004, 10:47 AM
  2. Replies: 4
    Last Post: 12-30-2003, 10:49 AM
  3. GLslang: no reuse of shader objects in other program objects?
    By Ostsol in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-29-2003, 11:22 PM
  4. Can nurbs objects and curves be used as b-spline objects?
    By BigShooter in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-04-2003, 09:42 AM
  5. Replies: 2
    Last Post: 05-24-2002, 06:21 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