Criticise my proposed rendering method

This is a discussion on Criticise my proposed rendering method within the Game Programming forums, part of the General Programming Boards category; So I was thinking about this: Basically I'll have a class, CRenderClass, that looks something like this: Code: class CRenderTask ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Criticise my proposed rendering method

    So I was thinking about this:

    Basically I'll have a class, CRenderClass, that looks something like this:

    Code:
    class CRenderTask
    {
    public:
        virtual void Draw() = 0;
    };
    My little rendering system will keep a (std:: )list of these which it will iterate, calling the Draw() function on each one.

    BUT, this means for everything I want to render I'll have to derive a class from this class. Is there a more manageable but similar approach?

    Yes, this is the first time I've written a renderererer.

    Oh yeah:

    SDL. For the Nth time: DirectX can rot until I get some books. Yes books, I mean you.
    Last edited by cboard_member; 04-26-2006 at 10:42 AM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    I don't see a particular reason why DirectX is better than OpenGL, Since SDL allready uses OpenGL, just learn GL.
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I've learnt enough OpenGL, I just want to use SDL. I didn't mean to compare DirectX and OpenGL.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Allright, i'm sorry for bringing that up ... now a new GL vs DirectX war will begin...
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I think one virtual lookup per rendered object isn't a big deal.

    You could also have your rendering system store a list of functions pointers and have each object register it's rendering function with the rendering system.

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Quantum1024
    I think one virtual lookup per rendered object isn't a big deal.

    You could also have your rendering system store a list of functions pointers and have each object register it's rendering function with the rendering system.
    Sounds like a plan. I'll use this thread to post any probs - I bet y'all can't wait.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Are you gonna use it like this, 'cause that seems fine.
    Code:
    class render
    {
    private:
    public:
           virtual void draw() = 0;
    };
    
    class tile : public render
    {
          ....
          void draw()
          {
               ...
          }
    };
    
    class something : public render
    {
          ...
    };
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Function pointers = bad idea.

    Try it.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    yes, turns out they would be pointless in this case since a function pointer to a virtual member function dose a virtual lookup anyway.

  10. #10
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yeah that kinda went... wrong. Methinks I need to rethink this.
    EDIT: Not only didn't the function pointer not work, the performance was terrible.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    LOL sorry for sugesting that it seamed like a good idea at the time. Just stick with your origional idea.

  12. #12
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Well, to note one major thing.

    MOST (not all) geometry should be drawn in virtually the SAME way!

    There are only a couple things you should have different drawing methods for...

    Models: (make all models subscribe to a vertex array or something similar format)

    Terrain: (Might be same as above, but use triangle_fans for this guy, it would be faster!)

    Thats all I can think of that is really different...

    So then you're only deriving two classes from that main drawing class! Imagine that!

    If you can keep everything virtually the same (in terms of drawing methods) you'll have an instantly relatively cleaned up renderer!
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  13. #13

    Join Date
    May 2005
    Posts
    1,041
    Virtual functions are function pointers.

    I use a similar method, in that there's a different rendering method per renderable type, but I don't use any Object Oriented programming to do it.

    I also don't implement shaders or any spectacular rendering effects...
    I'm not immature, I'm refined in the opposite direction.

  14. #14
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    I completely agree with the plan to make some sort of a empty base class for tieing all of your renderable objects together, but you may want to add more than just draw() to it so that next time you want to relate all this data for something you dont need to make another class, put every thing you think you will need in that class, which may or may not be more than just draw(). Just think ahead i guess on what other properties a renderable object may need, mabe its distance from the camera, mabe a boolean value that tell if it needs to be rendered or not, ect.

  15. #15
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Ok guys I'll give it some more thought.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  4. Overriding a method in C
    By DavidDobson in forum C Programming
    Replies: 1
    Last Post: 07-05-2008, 07:51 AM
  5. scene graph rendering techniques
    By ichijoji in forum Game Programming
    Replies: 7
    Last Post: 03-18-2006, 11:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21