Programming Style with DirectX and Direct2D

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GoneFate
    New Member
    • May 2010
    • 4

    #1

    Programming Style with DirectX and Direct2D

    I been trying to learn DirectX and Direct2D with C++. I'm proficient in C++, but I'm not sure how to do several things in working with these APIs.

    First, I'm not sure how to program in a structured manner or style in context with DX and D2D. Is there reference material anyone would suggest?

    For instance, in Direct2D in order to create a 'render target' you must initialize a 'factory'. This factory should retain its life through out the entire program. For a better understanding of this you can go here:
    http://msdn.microsoft. com/en-us/library/dd535473(v=VS.8 5).aspx#step_2: _create_an_id2d 1factory

    I guess in asking for structured help, I'm also asking about encapsulation. I coded a class that would create a factory from the ID2D1Factory interface. I'm worried that what I'm doing is incorrect. Incorrect in that this code won't flow "properly" with anything else I program, or allow me to use D2D to its full extent.

    basically my intentions are:
    I don't want to make any objects of the interfaces (of DX or D2D) global, so I encapsulate it in a class. In doing that, isn't the object of that class still considered a global? Or how would I need to program so I can still use interface object effectively and keep the program efficient?

    or do I have the wrong mindset in all of this? Thanks for any responses.
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Have you followed the DirectX tutorials that ship with the SDK? Have you considered something like XNA?

    Comment

    • GoneFate
      New Member
      • May 2010
      • 4

      #3
      Yup, I followed those tutorials and some more I found online and in books. I have looked into XNA, which would require me to learn C#. I've actually heard good things about it, but I'd rather much stick with DirectX more or less for a learning experience.

      Actually, in the DirectX tutorial for initializing Direct3D, they create a global of the Direct3D object with IDirect3D9::Cre ateDevice. I wanted to know if having the object as a global is "correct" or "good" practice. Isn't there some sort of conflict later on as you program more advanced things? If isn't good practice than what is?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        I don't think a global direct 3d device object is a bad thing. In fact I think it is necessary. Since there is usually only one render target having more than one device object will not work. When you begin working on games you will see that many good coding practices are sacrificed to gain speed and performance. Globals are one way to increase this speed, but then it opens you up for more problems if you are not careful.

        Comment

        • GoneFate
          New Member
          • May 2010
          • 4

          #5
          Okay, so this is a give and take situation. Performance vs Structure. I can understand that.

          When you say problems you're referring to things like memory management? ie. if you create so many devices, buffers, render targets, etc, that inevitably have to be released at some point.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            Yea memory would be the main concern.

            Comment

            Working...