BBC BASIC for Windows
« DirectX9 tutorials for BB4W »

Welcome Guest. Please Login or Register.
Apr 6th, 2018, 12:29am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: DirectX9 tutorials for BB4W  (Read 1099 times)
Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #23 on: Jul 28th, 2015, 9:11pm »

Add this to the first bit...

Code:
      REM and then the parameters we are passing. See the call we made above.

      REM In fact this Device is an Interface, and so if we want we can
      REM define another structure and redirect it to this Interface's
      REM despatch table.
      DIM IDirect3DDevice9{                   \
      \QueryInterface%,                       \
      \AddRef%,                               \
      \Release%,                              \
      \TestCooperativeLevel%,                 \
      \GetAvailableTextureMem%,               \
      \EvictManagedResources%,                \
      \GetDirect3D%,                          \
      \GetDeviceCaps%,                        \
      \GetDisplayMode%,                       \
      \GetCreationParameters%,                \
      \SetCursorProperties%,                  \
      \SetCursorPosition%,                    \
      \ShowCursor%,                           \
      \CreateAdditionalSwapChain%,            \
      \GetSwapChain%,                         \
      \GetNumberOfSwapChains%,                \
      \Reset%,                                \
      \Present%,                              \
      \GetBackBuffer%,                        \
      \GetRasterStatus%,                      \
      \SetDialogBoxMode%,                     \
      \SetGammaRamp%,                         \
      \GetGammaRamp%,                         \
      \CreateTexture%,                        \
      \CreateVolumeTexture%,                  \
      \CreateCubeTexture%,                    \
      \CreateVertexBuffer%,                   \
      \CreateIndexBuffer%,                    \
      \CreateRenderTarget%,                   \
      \CreateDepthStencilSurface%,            \
      \UpdateSurface%,                        \
      \UpdateTexture%,                        \
      \GetRenderTargetData%,                  \
      \GetFrontBufferData%,                   \
      \StretchRect%,                          \
      \ColorFill%,                            \
      \CreateOffscreenPlainSurface%,          \
      \SetRenderTarget%,                      \
      \GetRenderTarget%,                      \
      \SetDepthStencilSurface%,               \
      \GetDepthStencilSurface%,               \
      \BeginScene%,                           \
      \EndScene%,                             \
      \Clear%,                                \
      \SetTransform%,                         \
      \GetTransform%,                         \
      \MultiplyTransform%,                    \
      \SetViewport%,                          \
      \GetViewport%,                          \
      \SetMaterial%,                          \
      \GetMaterial%,                          \
      \SetLight%,                             \
      \GetLight%,                             \
      \LightEnable%,                          \
      \GetLightEnable%,                       \
      \SetClipPlane%,                         \
      \GetClipPlane%,                         \
      \SetRenderState%,                       \
      \GetRenderState%,                       \
      \CreateStateBlock%,                     \
      \BeginStateBlock%,                      \
      \EndStateBlock%,                        \
      \SetClipStatus%,                        \
      \GetClipStatus%,                        \
      \GetTexture%,                           \
      \SetTexture%,                           \
      \GetTextureStageState%,                 \
      \SetTextureStageState%,                 \
      \GetSamplerState%,                      \
      \SetSamplerState%,                      \
      \ValidateDevice%,                       \
      \SetPaletteEntries%,                    \
      \GetPaletteEntries%,                    \
      \SetCurrentTexturePalette%,             \
      \GetCurrentTexturePalette%,             \
      \SetScissorRect%,                       \
      \GetScissorRect%,                       \
      \SetSoftwareVertexProcessing%,          \
      \GetSoftwareVertexProcessing%,          \
      \SetNPatchMode%,                        \
      \GetNPatchMode%,                        \
      \DrawPrimitive%,                        \
      \DrawIndexedPrimitive%,                 \
      \DrawPrimitiveUP%,                      \
      \DrawIndexedPrimitiveUP%,               \
      \ProcessVertices%,                      \
      \CreateVertexDeclaration%,              \
      \SetVertexDeclaration%,                 \
      \GetVertexDeclaration%,                 \
      \SetFVF%,                               \
      \GetFVF%,                               \
      \CreateVertexShader%,                   \
      \SetVertexShader%,                      \
      \GetVertexShader%,                      \
      \SetVertexShaderConstantF%,             \
      \GetVertexShaderConstantF%,             \
      \SetVertexShaderConstantI%,             \
      \GetVertexShaderConstantI%,             \
      \SetVertexShaderConstantB%,             \
      \GetVertexShaderConstantB%,             \
      \SetStreamSource%,                      \
      \GetStreamSource%,                      \
      \SetStreamSourceFreq%,                  \
      \GetStreamSourceFreq%,                  \
      \SetIndices%,                           \
      \GetIndices%,                           \
      \CreatePixelShader%,                    \
      \SetPixelShader%,                       \
      \GetPixelShader%,                       \
      \SetPixelShaderConstantF%,              \
      \GetPixelShaderConstantF%,              \
      \SetPixelShaderConstantI%,              \
      \GetPixelShaderConstantI%,              \
      \SetPixelShaderConstantB%,              \
      \GetPixelShaderConstantB%,              \
      \DrawRectPatch%,                        \
      \DrawTriPatch%,                         \
      \DeletePatch%,                          \
      \CreateQuery%                          }


      REM Phew! We will put all this stuff in a library so we don't have to
      REM type it out every time.


      REM Now, remember to redirect our structure we just typed out to the
      REM interface's despatch table.
      !(^IDirect3DDevice9{}+4) = !IDirect3DDevice9%


      REM Now we can do something with this device.
      REM For this tutorial we shall just change the background colour by
      REM cycling though some different RGB values 1000 times.

      D3DCLEAR_TARGET = 1

      FOR I%=1 TO 1000
  
        R% = 128 + 127 * SIN(TIME/50)
        G% = 128 + 127 * SIN(TIME/70)
        B% = 128 + 127 * SIN(TIME/90)
  
        REM Now we OR these values together to create an D3DCOLOR value
  
        C% = &FF000000 OR (R%<<16) OR (G%<<8) OR B%
  
        REM We could check the return values of these calls,
        REM but we won't bother here because we are in a tight
        REM loop and we want to get on with things. If we had
        REM a problem we could check the return values to aid
        REM our debugging process.
  
        SYS IDirect3DDevice9.Clear%, IDirect3DDevice9%, 0, 0, \
        \ D3DCLEAR_TARGET, C%, FNf(1.0), 0
  
        SYS IDirect3DDevice9.BeginScene%, IDirect3DDevice9%
  
  
        REM We will do lots of other things here!
  
  
        SYS IDirect3DDevice9.EndScene%, IDirect3DDevice9%
        SYS IDirect3DDevice9.Present%, IDirect3DDevice9%, 0,0,0,0
  
        PRINT TAB(0,0)"Frame : "; I%, " Colour : ";~C%
  
      NEXT

      PRINT "Finished."

      PROC_Cleanup

      END

      REM A cleanup routine.
      DEF PROC_Cleanup
      REM Release IDirect3DDevice9
      IDirect3DDevice9% += 0 : IF IDirect3DDevice9% THEN
        SYS IDirect3DDevice9.Release%, IDirect3DDevice9%
      ENDIF
      REM Release IDirect3D9
      IDirect3D9% += 0 : IF IDirect3D9% THEN
        SYS IDirect3D9.Release%, IDirect3D9%
      ENDIF
      REM Free the dll
      D3D9DLL% += 0 : IF D3D9DLL% THEN SYS "FreeLibrary", D3D9DLL%
      ENDPROC

      DEF PROC_Error
      SYS "MessageBox", @hwnd%, REPORT$, "Error : ", 0
      ENDPROC

      REM Convert to 32-bit float
      DEF FNf(A#)
      LOCAL A%,P%
      PRIVATE F%
      IF F%=0 THEN
        DIM P%10
        [OPT 2
        .F%
        mov esi,[ebp+2]:mov edi,[ebp+7]
        fld qword [esi]:fstp dword [edi]
        ret
        ]
      ENDIF
      A# *= 1.0#
      CALL F%,A#,A%
      =A%
 

User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #24 on: Jul 28th, 2015, 9:13pm »

....and it works in v6.00 trial!

grin

Um, Richard, I need an ungrade.exe I am afraid... new computer again..

Michael
« Last Edit: Jul 28th, 2015, 9:19pm by Michael Hutton » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #25 on: Jul 28th, 2015, 9:34pm »

on Jul 28th, 2015, 4:03pm, DDRM wrote:
If they are different, then your header (or at least a pointer to the vTable list) will DEFINITELY be useful!

OK, here it is. I've checked a few methods chosen at random to see if they have the expected offsets, and they do - which is all good!

Code:
      DIM IDirect3DDevice9{QueryInterface%,AddRef%,Release%,TestCooperativeLevel%, \
      \ GetAvailableTextureMem%,EvictManagedResources%,GetDirect3D%,GetDeviceCaps%, \
      \ GetDisplayMode%,GetCreationParameters%,SetCursorProperties%,SetCursorPosition%, \
      \ ShowCursor%,CreateAdditionalSwapChain%,GetSwapChain%,GetNumberOfSwapChains%, \
      \ Reset%,Present%,GetBackBuffer%,GetRasterStatus%,SetDialogBoxMode%,SetGammaRamp%, \
      \ GetGammaRamp%,CreateTexture%,CreateVolumeTexture%,CreateCubeTexture%,CreateVertexBuffer%, \
      \ CreateIndexBuffer%,CreateRenderTarget%,CreateDepthStencilSurface%,UpdateSurface%, \
      \ UpdateTexture%,GetRenderTargetData%,GetFrontBufferData%,StretchRect%,ColorFill%, \
      \ CreateOffscreenPlainSurface%,SetRenderTarget%,GetRenderTarget%,SetDepthStencilSurface%, \
      \ GetDepthStencilSurface%,BeginScene%,EndScene%,Clear%,SetTransform%,GetTransform%, \
      \ MultiplyTransform%,SetViewport%,GetViewport%,SetMaterial%,GetMaterial%,SetLight%, \
      \ GetLight%,LightEnable%,GetLightEnable%,SetClipPlane%,GetClipPlane%,SetRenderState%, \
      \ GetRenderState%,CreateStateBlock%,BeginStateBlock%,EndStateBlock%,SetClipStatus%, \
      \ GetClipStatus%,GetTexture%,SetTexture%,GetTextureStageState%,SetTextureStageState%, \
      \ GetSamplerState%,SetSamplerState%,ValidateDevice%,SetPaletteEntries%,GetPaletteEntries%, \
      \ SetCurrentTexturePalette%,GetCurrentTexturePalette%,SetScissorRect%,GetScissorRect%, \
      \ SetSoftwareVertexProcessing%,GetSoftwareVertexProcessing%,SetNPatchMode%, \
      \ GetNPatchMode%,DrawPrimitive%,DrawIndexedPrimitive%,DrawPrimitiveUP%,DrawIndexedPrimitiveUP%, \
      \ ProcessVertices%,CreateVertexDeclaration%,SetVertexDeclaration%,GetVertexDeclaration%, \
      \ SetFVF%,GetFVF%,CreateVertexShader%,SetVertexShader%,GetVertexShader%,SetVertexShaderConstantF%, \
      \ GetVertexShaderConstantF%,SetVertexShaderConstantI%,GetVertexShaderConstantI%, \
      \ SetVertexShaderConstantB%,GetVertexShaderConstantB%,SetStreamSource%,GetStreamSource%, \
      \ SetStreamSourceFreq%,GetStreamSourceFreq%,SetIndices%,GetIndices%,CreatePixelShader%, \
      \ SetPixelShader%,GetPixelShader%,SetPixelShaderConstantF%,GetPixelShaderConstantF%, \
      \ SetPixelShaderConstantI%,GetPixelShaderConstantI%,SetPixelShaderConstantB%, \
      \ GetPixelShaderConstantB%,DrawRectPatch%,DrawTriPatch%,DeletePatch%,CreateQuery%} 

If you don't want to clog up your memory with this declaration it's an ideal application for the CALL statement. Just add a RETURN as the last line of the file and then use:

Code:
      CALL @lib$+"IDirect3DDevice9" 

(or whatever name you have saved the file as).

Richard.

« Last Edit: Jul 28th, 2015, 9:42pm by rtr2 » User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #26 on: Jul 29th, 2015, 08:18am »

^^ I've done all the hard work with all those declarations. They are in a library ready for use. I am presuming people would like them? I'll have to upload them.

Michael
User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #27 on: Jul 29th, 2015, 10:02am »

on Jul 29th, 2015, 08:18am, Michael Hutton wrote:
I've done all the hard work

Hard work? I wrote a little program to scan D3D9.H and create the BB4W structure declarations automatically, so there theoretically shouldn't be any errors! I've uploaded the full file D3D9DECL.BBC to the Yahoo group here:

https://groups.yahoo.com/neo/groups/bb4w/files/Graphics/

It can also be downloaded from this direct link.

I wonder if it would be helpful to incorporate some other declarations, such as IID values and maybe constants. Any thoughts?

Richard.

User IP Logged

Torro
New Member
Image


member is offline

Avatar




PM


Posts: 25
xx Re: DirectX9 tutorials for BB4W
« Reply #28 on: Jul 29th, 2015, 11:52am »

cool so this can be done for directx12?
« Last Edit: Jul 29th, 2015, 11:53am by Torro » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #29 on: Jul 29th, 2015, 12:40pm »

on Jul 29th, 2015, 11:52am, Torro wrote:
cool so this can be done for directx12?

I haven't looked into it. Generally speaking I'm not very interested in technologies that work only on recent versions of Windows. Because BB4W runs fine on Windows XP (and earlier) - and indeed that's still what my main development PC has - I try to ensure that libraries do too. Also, the 'user demographic' probably suggests that the average BBC BASIC programmer doesn't own a Windows 8 PC!

But since BB4W can do (virtually) anything any other language can - if sometimes rather more slowly! - I assume that interfacing with DirectX 12 should be entirely possible.

Richard.
User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #30 on: Jul 29th, 2015, 8:46pm »

on Jul 29th, 2015, 10:02am, g4bau wrote:
Hard work? I wrote a little program to scan D3D9.H and create the BB4W structure declarations automatically, so there theoretically shouldn't be any errors! I've uploaded the full file D3D9DECL.BBC to the Yahoo group here:

... snip ...

I wonder if it would be helpful to incorporate some other declarations, such as IID values and maybe constants. Any thoughts?

Richard.



"some hard work" - I note that you said it wouldn't be trivial a few posts ago. What has changed?

I think I did the same thing a few years ago. My definitions file has a lot of the constants defined. I think also there were some functions as well, so not so good for a CALL. I do have to install BB4W on this computer before I can update you with any more of what I did those years ago.

I'll try to update.
Michael
« Last Edit: Jul 29th, 2015, 10:16pm by Michael Hutton » User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #31 on: Jul 29th, 2015, 8:50pm »

on Jul 29th, 2015, 11:52am, Torro wrote:
cool so this can be done for directx12?


Yes, it can. The caveat being that setting up DirectX10/11/12 is different from 9 and below. I only have a 'starter file', basically getting a device going but in theory it is vastly more powerful. What is a major difference is the use of HLSL or 'effect' '.fx' files to control the shaders which make access to DirectCompute and the higher level shaders easier. It is a bit of a stepping stone though and not lightly undertaken.

Michael
User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #32 on: Jul 29th, 2015, 9:45pm »

on Jul 29th, 2015, 8:46pm, Michael Hutton wrote:
I think I did the same thing a few years ago.

The thing is, we are trying to make a fresh start. What you did that long time ago was impressive in many ways, but your programs never worked on my (or several other people's) PCs because of their reliance on D3DX9, with all that entailed. Perhaps understandably - since the programs ran perfectly on your own machine - you never seemed particularly committed to resolving that issue.

As you are probably aware, the way the new D3D9LIB (and the original D3DLIB) are made independent of D3DX is by coding equivalent functions directly in BASIC (made easier and faster by using BB4W's array operators and arithmetic). Whilst that only provides 'simple' solutions for the maths functions in D3DX, it shows one way towards the ultimate goal of writing more complex 3D programs that will work on any modern PC.

So, from my perspective, I don't want to go back to where DirectX9 support in BB4W was when you jumped ship to PureBasic (and deleted all your Direct3D utilities and tutorials from Yahoo). I would rather start with D3D9LIB, which for the first time has made it possible to run simple Direct3D9 programs in BB4W on my own PC. Hopefully we can develop that approach further, perhaps with guidance from the 'Living without D3DX' blog site to which I linked.

Richard.
User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: DirectX9 tutorials for BB4W
« Reply #33 on: Jul 29th, 2015, 10:04pm »

on Jul 29th, 2015, 9:45pm, g4bau wrote:
- you never seemed particularly committed to resolving that issue.


I'm really not going to reinvent the wheel by recoding DirectX9 or whatever for BB4W! There is a vast resource out there and all one needs to do is download DirectX9 or whatever version they want. I did add some functions which are missing from the dll which were defined in inline files but really, the idea of recoding DirectX9 to BB4W functions is rather ludicrous, even more so when there are multiple updates of DirectX by a team of professional coders!

If you manage to do it. Well done, but I'm not even going to bother. I have way too many other things to do. I have uploaded the tutorials I made. If they are there for people to look at and change at their will. Good luck with the 'fresh start'!

..and yes, I did delete the lessons when I 'jumped ship'(!) but I understand you had 'ran away' to Liberty Basic also... 'pot and kettle' I am afraid RTR.

Before casting stones..... oh, but it all starts again. lipsrsealed

Michael

« Last Edit: Jul 29th, 2015, 10:09pm by Michael Hutton » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #34 on: Jul 29th, 2015, 11:06pm »

on Jul 29th, 2015, 10:04pm, Michael Hutton wrote:
There is a vast resource out there and all one needs to do is download DirectX9 or whatever version they want.

DirectX (8, 9 and typically later versions) comes pre-installed with all recent versions of Windows, it is not necessary to download anything. However the Direct3D extensions (D3DX), which are what are under discussion here, are neither pre-installed with Windows nor (legally at least - post D3DX8) downloadable from anywhere as a DLL.

The only legitimate way to make a D3DX DLL available to an end-user is to ship a massive Microsoft installer with your application, which makes no sense for a BB4W app.

Quote:
the idea of recoding DirectX9 to BB4W functions is rather ludicrous, even more so when there are multiple updates of DirectX by a team of professional coders!

You are muddling DirectX with the Direct 3D Extensions (D3DX). It is perfectly sensible to consider alternatives to D3DX, indeed the blog page I linked to previously explains why D3DX is deprecated (scroll down to Background at the end of the article). The solutions may involve BASIC code (which contrary to your claim is perfectly reasonable for the maths functions at least), other DLLs or open-source tools.

Quote:
..and yes, I did delete the lessons when I 'jumped ship'(!) but I understand you had 'ran away' to Liberty Basic also... 'pot and kettle' I am afraid RTR.

At no point did my 'absence' from the BB4W scene result in any of the support materials being deleted. After all I continued to market BB4W throughout that period so was both morally and legally obliged to provide ongoing support.

Richard.
« Last Edit: Jul 30th, 2015, 06:36am by rtr2 » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #35 on: Jul 30th, 2015, 09:29am »

on Jul 29th, 2015, 11:52am, Torro wrote:
cool so this can be done for directx12?

Further to Michael's reply, see this page (it's referring to migrating from Direct3D 9 to Direct3D 11, but the issues are no doubt similar):

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476190.aspx#direct3d_9_to_direct3d_11

Although it removes the dependency on D3DX, a D3DCompiler DLL (which is not installed with Windows earlier than 8.1) is still required. In the comments at the bottom of this page the issue of whether it is legal to distribute that DLL is discussed (with not a very clear answer):

http://blogs.msdn.com/b/chuckw/archive/2012/05/07/hlsl-fxc-and-d3dcompile.aspx

However it states there that "The latest version of the D3DCompiler (#47) is now included with the Windows 8.1 OS" so we are off the hook for that OS version at least (I don't know about Windows 10).

As it also states in that article, if the only reason you need a D3DX (or D3DCompiler) DLL on the target machine is to compile the shader(s), then a good solution is to pre-compile them to binary shader files and (legitimately) ship those with your application.

Richard.
« Last Edit: Jul 30th, 2015, 09:43am by rtr2 » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #36 on: Jul 30th, 2015, 12:39pm »

I can confirm that the Direct3D examples supplied with BB4W (TEAPOT.BBC, PYRAMID.BBC, WORLD.BBC), and LIGHTING.BBC from the website - oh, and BBCOWL too - all work perfectly in Windows 10 (64-bit, although that shouldn't matter). This is as expected, but it's nice to know that Direct3D 8 remains supported on the newest (and last, if we are to believe Microsoft) Windows platform.

Richard.
« Last Edit: Jul 30th, 2015, 1:32pm by rtr2 » User IP Logged

rtr2
Guest
xx Re: DirectX9 tutorials for BB4W
« Reply #37 on: Jul 30th, 2015, 2:58pm »

on Jul 30th, 2015, 2:29pm, Torro wrote:
You would not believe how many banks Ive seen still running XP for mission critical apps because they are tied to ie61

Nothing particularly wrong with that, so long as they pay Microsoft enough to keep security updates coming (and if that's cheaper/safer than updating the banks' systems everybody is happy!).

Richard.
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls