OpenGL DirectX 2D

This is a discussion on OpenGL DirectX 2D within the Game Programming forums, part of the General Programming Boards category; is it easier to use OpenGL or DirectX for makeing a 2d rpg style game?? and which is easier to ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    OpenGL DirectX 2D

    is it easier to use OpenGL or DirectX for makeing a 2d rpg style game?? and which is easier to use in general?? (the second half of the question has probably been asked many times before )

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Some people prefer OpenGL, some prefer DX. There is no "better". Try one, or both, then decide.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    I believe DirectX has a specific subsystem for 2D (directdraw?)

    What it really depends on is who your audiance is, as Microsoft is the only ones supporting DirectX, while many operating systems support OpenGL.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    >>I believe DirectX has a specific subsystem for 2D (directdraw?)

    Not anymore. It's just DirectGraphics now (DirectDraw+Direct3D)

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    I believe DirectX has a specific subsystem for 2D (directdraw?)
    They did, however it's been merged now.

    You may want to read
    http://www.xmission.com/~legalize/d3d-vs-opengl.html

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    I don't do any thing graphical (yet any way) so I haven't been keeping up with it. Most of the stuff I have been messing with in my free time related to that has been OpenGL based any ways, since I use Linux alot more then Windows.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    In order to do 2D in DirectX you must bypass the T&L pipeline.

    This will accomplish that.

    CObject2D.h
    Code:
    #ifndef COBJECT2D
    #define COBJECT2D
    
    
    #include <d3dx9.h>
    #include <string>
    
    struct TLVertex
    {
       D3DXVECTOR3 Position;
       float rhw;
       float u,v;
    
       static const DWORD FVF;
    
       TLVertex(void):Position(0.0f,0.0f,0.0f),rhw(1.0f),u(0.0f),v(0.0f) {}
       TLVertex(D3DXVECTOR3 _Pos,float _u,float _v):Position(_Pos),u(_u),v(_v) {}
    };
    
    class CObject2D
    {
      protected:
        D3DXVECTOR3 m_pPosition;
        D3DXVECTOR3 m_pRotation;
        
        IDirect3DDevice9 *m_pDevice;
        IDirect3DTexture9 *m_pTexture;
    
        TLVertex m_pVertices[4];
        float m_fHeight;
        float m_fWidth;
    
      public:
        CObject2D(void):m_pDevice(NULL),m_pTexture(NULL) {}
        virtual ~CObject2D(void) 
        {
          if (m_pTexture)
          {
             m_pTexture->Release();
             m_pTexture=NULL;
          }
        }
    
        void Create(IDirect3DDevice9 *device,std::string TexFilename,float fWidth,float fHeight);
        void Render(float fTimeDelta);
    
    };
    CObject2D.cpp
    Code:
    const DWORD TLVertex::FVF=D3DFVF_XYZRHW | D3DFVF_TEX1;
    
    void Create(IDirect3DDevice9 *device,std::string TexFilename,float fWidth,float fHeight);
    {
        m_pDevice=device;
        if (FAILED(D3DXCreateTextureFromFile(&Device,TexFilename.c_str(),&m_pTexture)))
        {
           ::MessageBox(0,"CObject2D::Create() - Failed to load texture",0,0);
           return
        }
        float Height2=Height*.5f;
        float Width2=Width *.5f;
       
        m_fHeight=fHeight;
        m_fWidth=fWidth;
           
        m_pVertices[0]=TLVertex(D3DXVECTOR3(-Width2,-Height2,0.0f),0.0f,0.0f);
        m_pVertices[1]=TLVertex(D3DXVECTOR3(Width2,-Height2,0.0f),1.0f,0.0f);
        m_pVertices[2]=TLVertex(D3DXVECTOR3(-Width2,Height2,0.0f),0.0f,1.0f);
        m_pVertices[3]=TLVertex(D3DXVECTOR3(Width2,Height2,0.0f),1.0f,1.0f);
    }  
    
    void Render(float fTimeDelta)
    {
       m_pDevice->SetTexture(0,m_pTexture);
       m_pDevice->SetFVF(TLVertex::FVF);
       m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,(TLVertex *)&m_pVertices,sizeof(TLVertex));
    }
    That should get you on the right track.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    When Bubba posts on direct3d vs opengl threads i feel like it's political propaganda because Bubba is a d3d .......... (im just playing)

    doing 2d is relatively easy (and the code he posted WILL get you on the right track).

    OpenGL, is, on the whole, easier to learn, as there tend to be fewer nit picky things that you have to figure out. However, when you get right down to it, for rendering, they're both pretty much the same thing.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    if im using OpenGL i need to use Win32 to make a window to use OpenGL in right?(i think i will go with OpenGL for portability) what about linux... what do i use to make the window in linux?? (GTK, GTK+, ...)

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    you could use either SDL or glut if you want as much portability as possible.
    Last edited by Shakti; 03-01-2005 at 09:31 AM.

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    I have touched on SDL, In Linux at least, and it works quite well. Also their is a new libary called OpenGLUT, which I believe is just trying to implement GLUT's calls in an open source library.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  12. #12
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Xipher
    I have touched on SDL, In Linux at least, and it works quite well. Also their is a new libary called OpenGLUT, which I believe is just trying to implement GLUT's calls in an open source library.
    theres always freeglut. I use it regularly and it works quite well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-22-2006, 03:39 PM
  2. Going from DirectX to OpenGL
    By Wraithan in forum Game Programming
    Replies: 19
    Last Post: 02-24-2006, 10:07 AM
  3. Allegro, OpenGL.. or even DirectX?
    By Zeusbwr in forum C++ Programming
    Replies: 1
    Last Post: 11-14-2004, 07:16 AM
  4. OpenGL 2 or DirectX ?
    By alex6852 in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-02-2003, 01:31 PM
  5. So.. what's the difference between DirectX and OpenGL?
    By QuestionC in forum Game Programming
    Replies: 6
    Last Post: 01-19-2002, 05:18 PM

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