Author Topic: Implimenting DirectX9  (Read 3490 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
Implimenting DirectX9
« on: March 15, 2013, 04:55:25 AM »
Hi all

I have started a new Project for creating DirectX9 Interfaces , so i took a quickly locks in voice.inc.

but get an error , any help please

here is the codes
Code: [Select]

'-----------------------------------------
'DirectX9 stuff by Emil Halim  15-3-2013
'=========================================

  #case capital


  'standalone definitions ad hoc

  #define __in
  #define __out
  #define __in_opt      optional
  #define __out_opt     optional
  #define __RPC__in_opt optional

  typedef sys      HANDLE,HRESULT,HWND,WMSG,WPARAM,LPARAM
  typedef dword    DWORD,ULONG,UINT
  typedef qword    ULONGLONG
  typedef bool     BOOL
  typedef zstring2 *LPCWSTR
  typedef word     USHORT
  typedef void     * PVOID
 
  #define D3D_SDK_VERSION 31

  extern lib "D3D9.DLL"
      IDirect3D9* Direct3DCreate9(dword SDKVersion)
  end extern
   
  'from Unknwn.h

extern virtual

  '-------------
  class IUnknown
  '=============

    HRESULT QueryInterface(refiid id, pvObject* ppv)
    ULONG   AddRef()
    ULONG   Release()

  end class


  '--------------------
  ' IDirect3D9
  '--------------------
  class IDirect3D9
  '====================

    'public

    from IUnknown
               
          /*** IDirect3D9 methods ***/
          HRESULT RegisterSoftwareDevice)()
          HRESULT GetAdapterCount)()
          HRESULT GetAdapterIdentifier)()
          HRESULT GetAdapterModeCount)()
          HRESULT EnumAdapterModes)()
          HRESULT GetAdapterDisplayMode)()
          HRESULT CheckDeviceType)()
          HRESULT CheckDeviceFormat)()
          HRESULT CheckDeviceMultiSampleType)()
          HRESULT CheckDepthStencilMatch)()
          HRESULT CheckDeviceFormatConversion)()
          HRESULT GetDeviceCaps)()
          HRESULT GetAdapterMonitor)()
          HRESULT CreateDevice)()
   end class

end extern

   
test program
Code: [Select]
'-----------------------------------------
' Test DX9 No# 1     15-3-2013
'=========================================

  $ filename "TestDX9_1.exe"
  '#include "../../inc/RTL32.inc"
  '#include "../../inc/RTL64.inc"
  #include "../../inc/COM/DirectX9.inc"
 

  '---------------------
  function main() as sys
  '=====================
 

  end function

  main

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #1 on: March 15, 2013, 05:29:38 AM »
Hi Emil,

the voice api work with the demos in examples/com

I know quite a bit about Opengl but nothing about DirectX. Many of us are wary of Microsoft lock-ins.

Can you show a simple example in C showing which header files are needed etc.

Charles

Emil_halim

  • Guest
Re: Implimenting DirectX9
« Reply #2 on: March 15, 2013, 05:43:09 AM »

thanks charles.

but may i ask the reason for that wary of Microsoft?

anyway , i was changing this piece of code from My Old Sphinx C--
Code: [Select]
#define D3D_SDK_VERSION 31

extern WINAPI "D3D9.DLL"
{
   dword Direct3DCreate9();
}

//IUnknown methods
struct IDirect3D9 {

    /*** IUnknown methods ***/
  long stdcall (*QueryInterface)();
  long stdcall (*AddRef)();
  long stdcall (*Release)();

    /*** IDirect3D9 methods ***/
  long stdcall (*RegisterSoftwareDevice)();
  long stdcall (*GetAdapterCount)();
  long stdcall (*GetAdapterIdentifier)();
  long stdcall (*GetAdapterModeCount)();
  long stdcall (*EnumAdapterModes)();
  long stdcall (*GetAdapterDisplayMode)();
  long stdcall (*CheckDeviceType)();
  long stdcall (*CheckDeviceFormat)();
  long stdcall (*CheckDeviceMultiSampleType)();
  long stdcall (*CheckDepthStencilMatch)();
  long stdcall (*CheckDeviceFormatConversion)();
  long stdcall (*GetDeviceCaps)();
  long stdcall (*GetAdapterMonitor)();
  long stdcall (*CreateDevice)();

};

BTW  does Oxygen understand something like that?
     

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #3 on: March 15, 2013, 05:56:32 AM »
The main problem is that DirectX is not used outside Microsoft, whereas Opengl is extensively deployed across many platforms, and looks much the same in different languages too. MS made a regressive decision not to back Opengl, many years ago (not invented here!), probably for commercial reasons.

That struct needs a little work to turn it into a class that o2 will accept.

Charles

Emil_halim

  • Guest
Re: Implimenting DirectX9
« Reply #4 on: March 15, 2013, 06:04:38 AM »


ok , i got it well.

anyway I will stop that project , no one here will inserting.

i will dig in my old libs that made for OpenGl ,

see you. 

Aurel

  • Guest
Re: Implimenting DirectX9
« Reply #5 on: March 15, 2013, 06:18:31 AM »
I use directx in Ebasic but not to much ,only for simple demos or demos of games
but ebasic use dx3d9r.dll for DirectX programming and work fine with this compiler.
if you ask me directX work far better on any windows computer then openGL
and most of big games are created directX not openGL...
but for what i need in oxygen is GDI graphic very good.

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #6 on: March 15, 2013, 07:13:54 AM »
If you think we could benefit from DirectX, Emil, we can give it a try. It's up to you :)
The tricky bit, as in Opengl, is getting the thing booted up.

Emil_halim

  • Guest
Re: Implimenting DirectX9
« Reply #7 on: March 15, 2013, 09:19:31 AM »

@Aurel ,

yes , DirectX is faster and better then Opengl. you know my recent Library "MagicPro.dll" is under DX9 and it's
size after UPX is 6,927KB. it is a collections of many projects such as OGRE3D Irrlicht3D some features from a DarkBasic ,indieLibrary 2D, and more ... all in directx9.

@charles ,

No problem i will starting a coding with OpenGl.

BTW please can you show me the changes of struct to work with Oxygen basic , that will be great for the sack of learning Oxygen more.     
 

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #8 on: March 15, 2013, 09:26:48 PM »
Hi Emil,

how do you normally define parameters for your methods?

This is the original MS  SDK version of the interface you gave in sphinx c-- (above):

Code: [Select]
DECLARE_INTERFACE_(IDirect3D9, IUnknown)
{
    /*** IUnknown methods ***/
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;

    /*** IDirect3D9 methods ***/
    STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
    STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
    STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier) PURE;
    STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter,D3DFORMAT Format) PURE;
    STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode) PURE;
    STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed) PURE;
    STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) PURE;
    STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels) PURE;
    STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) PURE;
    STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat) PURE;
    STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps) PURE;
    STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
    STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) PURE;
    
    #ifdef D3D_DEBUG_INFO
    LPCWSTR Version;
    #endif
};

and the startup:

IDirect3D9* Direct3DCreate9(
  UINT SDKVersion
);


Charles

PS:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb174300(v=vs.85).aspx
« Last Edit: March 15, 2013, 09:50:09 PM by Charles Pegge »

Emil_halim

  • Guest
Re: Implimenting DirectX9
« Reply #9 on: March 16, 2013, 07:33:37 AM »

Hi Mr, Charles.

actually , Sphinx c-- allows this features , so it did not check for the parameters just like asm language.
 
you can consider it in intermediate point between C & ASM, can OxyGen support that ?

about the MS interface declaration , thanks you for the link , already know it.

the question here is that does Oxygen accept MS declarations and if not please show me the changes.     
 

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #10 on: March 16, 2013, 11:39:50 AM »
Oxygen understands C headers pretty well but there is always something disruptive in MS headers, and they benefit from a simple cleaup. It's gradually getting better.

Like C--, we can accept declarations without prototypes, but I have not extended this ability to methods yet. Do you think it would be useful? I like the idea.

Something like this:
Code: [Select]
#define D3D_SDK_VERSION 31

extern stdcall lib "D3D9.DLL"

sys Direct3DCreate9 (sys SDKVersion)

extern virtual


//IUnknown methods
class IDirect3D9
{
  /*** IUnknown methods ***/
  !   QueryInterface)(any*,any;
  !   AddRef;
  !   Release;

    /*** IDirect3D9 methods ***/
  !   RegisterSoftwareDevice;
  !   GetAdapterCount;
  !   GetAdapterIdentifier;
  !   GetAdapterModeCount;
  !   EnumAdapterModes;
  !   GetAdapterDisplayMode;
  !   CheckDeviceType;
  !   CheckDeviceFormat;
  !   CheckDeviceMultiSampleType;
  !   CheckDepthStencilMatch;
  !   CheckDeviceFormatConversion;
  !   GetDeviceCaps;
  !   GetAdapterMonitor;
  !   CreateDevice;

};

end extern

Charles

Emil_halim

  • Guest
Re: Implimenting DirectX9
« Reply #11 on: March 16, 2013, 12:22:33 PM »

nice work Charles.

i think it is useful because it faster shorter easier method than the usual one.

BTW you have to add a way to tell the compiler about the type of call i.g. stdcall , fastcall , cdecl..........   

Charles Pegge

  • Guest
Re: Implimenting DirectX9
« Reply #12 on: March 16, 2013, 12:47:12 PM »
Yes, We could treat method the same as functions, with and without prototypes. Also with or without calling convention.

At present, the calling convention is applied to the whole class, as specified in the extern statement. (except for methods with ellipsis prototypes, which are never stdcall)