Design question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • everguet@gmail.com

    Design question

    Hi,

    I have a small question about design, implemented in C++ of course ;)

    I have a set of objects A, B and C, which are pure C++ code (no GUI,
    I/O, ...). I need to draw them on screen (using OpenGL), but i don't
    want to put my OpenGL methods in my class A, B and C.

    How can i do that ? Using an aggregate object member of my class, using
    derivation, ... ?

    Thanks.

  • Marcelo Pinto

    #2
    Re: Design question


    everg...@gmail. com escreveu:
    [color=blue]
    > Hi,
    >
    > I have a small question about design, implemented in C++ of course ;)
    >
    > I have a set of objects A, B and C, which are pure C++ code (no GUI,
    > I/O, ...). I need to draw them on screen (using OpenGL), but i don't
    > want to put my OpenGL methods in my class A, B and C.
    >
    > How can i do that ? Using an aggregate object member of my class, using
    > derivation, ... ?
    >
    > Thanks.[/color]

    In order to isolate your logic from the specifics of OpenGL I would
    create a layer (drawing layer) of classes that would know how to draw
    your objects and would let a controller class coordinate the drawing
    passing to the drawing layer the objects to be drawn.

    HTH,

    Marcelo Pinto

    Comment

    • Gernot Frisch

      #3
      Re: Design question


      <everguet@gmail .com> schrieb im Newsbeitrag
      news:1138715369 .364617.107700@ g47g2000cwa.goo glegroups.com.. .[color=blue]
      > Hi,
      >
      > I have a small question about design, implemented in C++ of course
      > ;)
      >
      > I have a set of objects A, B and C, which are pure C++ code (no GUI,
      > I/O, ...). I need to draw them on screen (using OpenGL), but i don't
      > want to put my OpenGL methods in my class A, B and C.
      >
      > How can i do that ? Using an aggregate object member of my class,
      > using
      > derivation, ... ?[/color]

      class TRIANGLE
      {
      float xyz[3][3];
      };

      template <class CData> class GLDrawObject
      {
      virtual std::vector<TRI ANGLE>* GetTriangles() = 0;
      };

      class A
      {
      std::vector<TRI ANGLE>* GetTirangles()
      {
      yaddayadda;
      }
      };

      Just my .02$



      Comment

      • everguet@gmail.com

        #4
        Re: Design question

        Thanks, but i want to avoid a big switch case with all my object types
        in this layer. This is what you mean ?

        Comment

        • Marcelo Pinto

          #5
          Re: Design question


          everguet@gmail. com escreveu:
          [color=blue]
          > Thanks, but i want to avoid a big switch case with all my object types
          > in this layer. This is what you mean ?[/color]

          No it is not. If you fall in that situation you could use some factory
          and some hierarchy on the OpenGL side or you could use templates to
          parameterize the processing. But without seeing some code it is
          dificult to understand the exact problem you are facing.

          HTH,

          Marcelo Pinto

          Comment

          • Emmanuel V.

            #6
            Re: Design question

            I am on the design phase, no code for the moment ;-)

            Comment

            • Jim Langston

              #7
              Re: Design question

              <everguet@gmail .com> wrote in message
              news:1138715369 .364617.107700@ g47g2000cwa.goo glegroups.com.. .[color=blue]
              > Hi,
              >
              > I have a small question about design, implemented in C++ of course ;)
              >
              > I have a set of objects A, B and C, which are pure C++ code (no GUI,
              > I/O, ...). I need to draw them on screen (using OpenGL), but i don't
              > want to put my OpenGL methods in my class A, B and C.
              >
              > How can i do that ? Using an aggregate object member of my class, using
              > derivation, ... ?
              >
              > Thanks.[/color]

              Consider deriving from a base that does the openGL calls for you. If at
              some point you switch to, for instance, DirectX you would only have to
              change the base class. In theory.


              Comment

              • JustBoo

                #8
                Re: Design question

                On 31 Jan 2006 05:49:29 -0800, everguet@gmail. com wrote:
                [color=blue]
                >I have a set of objects A, B and C, which are pure C++ code (no GUI,
                >I/O, ...). I need to draw them on screen (using OpenGL), but i don't
                >want to put my OpenGL methods in my class A, B and C.[/color]

                Some good suggestions here. You might also consider the newsgroups
                below as they are populated with people who solve OpenGL problems
                on a daily basis.

                comp.graphics.a lgorithms
                comp.graphics.a pi.opengl

                What I did was basically wrap various OpenGL functions and sequences
                of functions into a few "stand alone" classes. I then called these
                from my GUI classes. I had reduced what could have been many calls to
                OpenGL "all over the place" to a few simple calls to the OpenGL
                classes. To pull those out and replace them with DX calls should be
                easy if it ever happens. (Which it won't as long as I breath. :-) ).

                A downside to this was I had created a tight coupling between my gui
                classes and the OpenGL classes. This was by design though. I created
                the whole "thing" to be a subsystem along the lines of the Facade
                pattern.

                HTH

                Comment

                • Dave Townsend

                  #9
                  Re: Design question


                  <everguet@gmail .com> wrote in message
                  news:1138715369 .364617.107700@ g47g2000cwa.goo glegroups.com.. .[color=blue]
                  > Hi,
                  >
                  > I have a small question about design, implemented in C++ of course ;)
                  >
                  > I have a set of objects A, B and C, which are pure C++ code (no GUI,
                  > I/O, ...). I need to draw them on screen (using OpenGL), but i don't
                  > want to put my OpenGL methods in my class A, B and C.
                  >
                  > How can i do that ? Using an aggregate object member of my class, using
                  > derivation, ... ?
                  >
                  > Thanks.
                  >[/color]

                  I've solved this type of graphics problem a number of times by using a
                  Visitor Pattern in conjunction with the Composite Pattern. The visitor
                  derived object then can take care of the particular graphics system outside
                  of the classes A, B, or C.



                  Comment

                  • Emmanuel V.

                    #10
                    Re: Design question

                    I will have a look to those patterns, thanks ;)

                    Comment

                    Working...