Sign in to follow this  
Po

"Fizzy Drink Problems" - Visual Basic.NET

Recommended Posts

Hello I've just joined up here as I'm attempting to learn some DirectX8 in VB.NET but I've come up with an problem. Should you have not figured out "Fizzy Drink Problems" refers to that the Sprites are the problem I've got. I believe the DirectX is initialized as the form changes colour due to Direct3DDevice8.Clear. I've not been able to dig up much tutorials or other online resources that can help with this. So with the few resources I've got to help I've then attempted to piece together how to draw an sprite (its only an 2D game I'm attempting) but on running it now gives me the following error;
Quote:
Unable to cast COM object of type 'System.__ComObject' to interface type 'DxVBLibA.D3DXSprite'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E8691849-87B8-4929-9050-1B0542D5538C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
And here is the code on this form so far, with the line that is giving the error shown in bold.
Public Class MainGame

    'DECLARATIONS
    Private DirectX As DirectX8
    Private Direct3D As Direct3D8
    Private Direct3DX As D3DX8
    Private Direct3DSprite As D3DXSprite
    Private Device As Direct3DDevice8
    Private Running As Boolean
    Const Radius = 3.14 / 180

    'INITIALIZATION CALL + RENDERING LOOP
    Private Sub MainGame_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Running = InitializeDirect()
        Do While Running = True
            Render()
            My.Application.DoEvents()
        Loop
        On Error Resume Next
        Device = Nothing
        Direct3D = Nothing
        DirectX = Nothing
    End Sub

    Function CreateTexture(ByVal Source As String) As Direct3DTexture8
        CreateTexture = Direct3DX.CreateTextureFromFile(Device, Source)
    End Function


    'DIRECT INITIALIZATION FUNCTION
    Public Function InitializeDirect()
        Try
            Dim Display As D3DDISPLAYMODE
            Dim Window As D3DPRESENT_PARAMETERS
            DirectX = New DirectX8
            Direct3D = DirectX.Direct3DCreate()
            Direct3D.GetAdapterDisplayMode(CONST_D3DCONST.D3DADAPTER_DEFAULT, Display) '//Retrieve the current display Mode

            Window.AutoDepthStencilFormat = Display.Format
            Window.BackBufferCount = 1
            Window.BackBufferFormat = Display.Format
            Window.BackBufferWidth = Me.Width
            Window.BackBufferHeight = Me.Height
            Window.EnableAutoDepthStencil = 0
            Window.hDeviceWindow = Me.Handle
            Window.MultiSampleType = CONST_D3DMULTISAMPLE_TYPE.D3DMULTISAMPLE_NONE
            Window.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_COPY_VSYNC
            Window.Windowed = 1

            Device = Direct3D.CreateDevice(CONST_D3DCONST.D3DADAPTER_DEFAULT, CONST_D3DDEVTYPE.D3DDEVTYPE_HAL, Me.Handle, CONST_D3DCREATEFLAGS.D3DCREATE_HARDWARE_VERTEXPROCESSING, Window)

            InitializeDirect = True
            Exit Function
        Catch
            MessageBox.Show("Error Number Returned: " & Err.Number, Err.Description)
            InitializeDirect = False
        End Try
    End Function

    'RENDERING SUBROUTINE
    Public Sub Render()
        Device.Clear(0, 0, CONST_D3DCLEARFLAGS.D3DCLEAR_TARGET, &HCCCCFF, 1.0#, 0)
        Device.BeginScene()

        Direct3DX = New D3DX8

        Dim TerrainTexture As Direct3DTexture8
        TerrainTexture = CreateTexture("C:\Documents and Settings\Mark\My Documents\Development\Malaya.jpg")
        Direct3DSprite = Direct3DX.CreateSprite(Device)
        Direct3DSprite.Begin()

        Dim TerrainScale As D3DVECTOR2
        TerrainScale.x = 1
        TerrainScale.y = 1

        Dim TerrainRotation As D3DVECTOR2
        TerrainRotation.x = 0
        TerrainRotation.y = 0

        Dim TerrainTranslation As D3DVECTOR2
        TerrainTranslation.x = 1
        TerrainTranslation.y = 1

        Dim Rotation As Integer = Radius * 0

        Direct3DSprite.Draw(TerrainTexture, 0, TerrainScale, TerrainRotation, Rotation, TerrainTranslation, Nothing)

        Direct3DSprite.End()
        Device.EndScene()
        Device.Present(0, 0, 0, 0)
    End Sub

End Class
Appreciate any advice given. Additional is that I've just noticed once posted that the bold doesn't seem to be showing up so the problem line is "Direct3DSprite = Direct3DX.CreateSprite(Device)".

Share this post


Link to post
Share on other sites
DirectX 8 didn't have .net wrappers, the DxVBLib was designed specifically as a VB6 library. It doesn't follow the COM specification fully beyond that, which is why the internal QueryInterface call fails here.

D3D8 is positively ancient technology anyway. If you can switch to D3D9, you can use SlimDX which is a good and modern .net wrapper library.

If you are absolutely stuck at D3D8, one option is to write your own native<->managed wrapper by using C++/CLR. The core DX8 objects do follow COM rules. That said, this would be a big project by itself, and certainly not suited for a D3D beginner.

Share this post


Link to post
Share on other sites
Alright bugger but appreciated. Wanted to stick to as ancient as I could really as my system is ancient anyway. But its got DX9 anyway and I'm not going to be able to write anything in C++ so sure I guess I gotta go DX9 then.

Is it just the latest SDK on this (http://slimdx.org/download.php) page that I need? Also I see that download called "End User Runtime" I'm guessing then that anyone who will want to use the program that I create will require to download that first?

Seems pointless for them to even include "DirectX 8 For Visual Basic Type Library" with Visual Basic Express 2005 then.

[Edited by - Po on April 26, 2010 8:20:06 AM]

Share this post


Link to post
Share on other sites
In addition to downloading the SlimDX SDK, I recommend downloading the latest DirectX SDK from MSDN.

The end users will require the runtime.

The DX8 VB library isn't included in Visual Studio. It resides on Windows systems to provide backwards compatibility for programs that were once written against it.

Since it is registered as a standard COM library, it merely shows up in the Visual Studio "Add reference" dialog. The list therein shows all public COM type libraries registered on the system, and most of those don't relate to Visual Studio at all. And just because a library is in that list doesn't mean that it is actually usable in a given version of VS - just that Visual Studio acknowledges its presence.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this