DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
Go Back  Xtreme Visual Basic Talk > > > > DirectX8 D3D Help! System.IntPtr


Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2006, 12:56 PM
anarchyPenguin anarchyPenguin is offline
Newcomer
 
Join Date: May 2006
Posts: 4
Default DirectX8 D3D Help! System.IntPtr


I'm having some trouble converting some VB6 code to .NET code for use with DIRECTX8 D3D. The problem lies at the bottom of DrawTile

Code:
Imports DxVBLibA
Imports DxVBLibA.CONST_D3DCONST
Imports DxVBLibA.CONST_D3DCLEARFLAGS
Imports DxVBLibA.CONST_D3DCREATEFLAGS
Imports DxVBLibA.CONST_D3DDEVTYPE
Imports DxVBLibA.CONST_D3DSWAPEFFECT
Imports DxVBLibA.CONST_D3DXENUM

Public Class Form1
    Inherits System.Windows.Forms.Form
    Const SCREENWIDTH As Long = 800
    Const SCREENHEIGHT As Long = 600
    Const FULLSCREEN As Boolean = False
    Const C_BLACK As Long = &H0
    Const C_RED As Long = &HFF0000

    'the DirectX objects
    Dim dx As DirectX8
    Dim d3d As Direct3D8
    Dim d3dx As New D3DX8
    Dim dispmode As D3DDISPLAYMODE
    Dim d3dpp As D3DPRESENT_PARAMETERS
    Dim d3ddev As Direct3DDevice8

    'Specials
    Dim hWnd As Int32 = Handle.ToInt32
    Dim a As Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

    'some surfaces
    Dim backbuffer As Direct3DSurface8
    Dim castle As Direct3DSurface8

'Windows form designer generated code"

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initialize Direct3D
        InitDirect3d(Me.hWnd, SCREENWIDTH, SCREENHEIGHT, FULLSCREEN)

        'get reference to the back buffer
        backbuffer = d3ddev.GetBackBuffer(0, CONST_D3DBACKBUFFERTYPE.D3DBACKBUFFER_TYPE_MONO)

        'load the bitmap file-castle.bmp is 1024x768
        castle = LoadSurface("Chapter4.castle.bmp", 1024, 1024)
    End Sub

    Private Sub InitDirect3D(ByVal hWnd As Long, ByVal lWidth As Long, ByVal lHeight As Long, ByVal bFullScreen As Boolean)

        'catch any errors here
        On Error Resume Next

        'create the DirectX object
        dx = New DirectX8

        'create the Direct3D object
        d3d = dx.Direct3DCreate()
        If d3d Is Nothing Then
            MsgBox("Error initializing Direct3D!")
            Shutdown()
        End If

        'tell D3D to use the current color depth
        d3d.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, dispmode)

        'set the disply setting used to create the dvice
        Dim d3dpp As D3DPRESENT_PARAMETERS
        d3dpp.hDeviceWindow = hWnd
        d3dpp.BackBufferCount = 1
        d3dpp.BackBufferWidth = lWidth
        d3dpp.BackBufferHeight = lHeight
        d3dpp.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_COPY_VSYNC
        d3dpp.BackBufferFormat = dispmode.Format

        'set windowed or fullscreen mode
        If bFullScreen Then
            d3dpp.Windowed = 0
        Else
            d3dpp.Windowed = 1
        End If

        'chapter 9
        d3dpp.MultiSampleType = CONST_D3DMULTISAMPLE_TYPE.D3DMULTISAMPLE_NONE
        d3dpp.AutoDepthStencilFormat = CONST_D3DFORMAT.D3DFMT_D32

        'create the D3d primary device
        d3ddev = d3d.CreateDevice( _
        D3DADAPTER_DEFAULT, _
        CONST_D3DDEVTYPE.D3DDEVTYPE_HAL, _
        hWnd, _
        CONST_D3DCREATEFLAGS.D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
        d3dpp)

        If d3ddev Is Nothing Then
            MsgBox("Error creating the Direct3D device!")
            Shutdown()
        End If
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        'clear the background of the screen
        d3ddev.Clear(0, System.IntPtr.Zero, D3DCLEAR_TARGET, C_BLACK, 1, 0)

        'draw the castle bitmap "tile" image
        DrawTile(castle, 0, 0, 511, 511, 25, 25)

        'send the back buffer to the screen
        d3ddev.Present(System.IntPtr.Zero, System.IntPtr.Zero, 0, System.IntPtr.Zero)
    End Sub


    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = 27 Then Shutdown()
    End Sub


    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Shutdown()
    End Sub

    Private Sub Shutdown()
        castle = Nothing
        d3ddev = Nothing
        d3d = Nothing
        dx = Nothing
        Application.Exit()
    End Sub

    Private Function LoadSurface(ByVal filename As String, ByVal width As Long, ByVal height As Long) As Direct3DSurface8
        On Error Resume Next

        Dim surf As Direct3DSurface8

        LoadSurface = Nothing

        'create the new surface
        surf = d3ddev.CreateImageSurface(width, height, dispmode.Format)
        If surf Is Nothing Then
            MsgBox("Error creating surface!")
            Exit Function
        End If

        d3dx.LoadSurfaceFromFile(surf, System.IntPtr.Zero, System.IntPtr.Zero, filename, System.IntPtr.Zero, D3DX_DEFAULT, 0, System.IntPtr.Zero)

        If surf Is Nothing Then
            MsgBox("Error loading " & filename & "1")
            Exit Function
        End If

        'return the new surface
        LoadSurface = surf
    End Function

    Private Sub DrawTile(ByRef source As Direct3DSurface8, ByVal sourcex As Long, ByVal sourcey As Long, ByVal width As Long, ByVal height As Long, ByVal destx As Long, ByVal desty As Long)
        'creast a RECT to describe the source image
        Dim sourceRect As RECT

        'set the upper left corner of the source image
        sourceRect.left = sourcex
        sourceRect.top = sourcey
        'set the bottom right corner of the source image
        sourceRect.right = sourcex + width
        sourceRect.bottom = sourcey + height

        'create a POINT to define the destination
        Dim point1 As POINT
        'set the upper left corner of where to draw the image
        point1.x = destx
        point1.y = desty

        'draw the source bitmap tile image
        'Here is my problem I get an error message with the
        'parameters....sourceRect and point1 cannot be converted
        ' to System.IntPtr I have no idea what this means or how to fix it
        ' Any help? I've tried looking up infor on System.IntPtr but that
        ' just doesn't help me
        d3ddev.CopyRects(source, sourceRect, 1, backbuffer, point1)

    End Sub
End Class
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
 
DirectX8 D3D Help! System.IntPtr
DirectX8 D3D Help! System.IntPtr
 
-->