Results 1 to 2 of 2

Thread: Visual Basic 6 and DirectX8 Tutorial

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    6

    Visual Basic 6 and DirectX8 Tutorial

    Game Programming Tutorial -
    Beginners Guide -
    HTML Code:
    '--------------------------
    'Game Programming Tutorial - Part 1
    'Drawing a colored Screen
    'For the time being we will use the Main Form, will change later
    'MainForm.frm 
    'Since we are using MainForm public can be dim on the const and objects, but set them to public becase they will be moved to a MODULE in the upcoming Tutorials
    '--------------------------
    'Make sure all variables are declared
    Option Explicit
    
    'CONSTANTS NEEDED
    'CUSTOMIZE PROGRAM HERE
    'desired width
    Public Const SCREENWIDTH as Long = 800
    'desired height
    public Const SCREENHEIGHT AS LONG = 600
    'change to true when all 'code works
    public Const FULLSCREEN AS BOOLEAN = FALSE
    'COLORS
    Public Const C_BLACK as long = &h0
    
    'Direct Objects that will be needed
    'this will be explained in Sub InitDirect
    public dx as directx8
    public d3d as direct3d8
    public d3dpp as D3DPRESENT_PARAMETERS
    Public dispmode as D3DDISPLAY_MODE
    Public d3ddev as direct3dDevice8
    'This Sub Procedure Initializes The Direct and Direct3D object
    'along with setting the display parameters and creating the primary display device,

    HTML Code:
    Public Sub InitDirect( _
         ByVal hwnd as long, _
         ByVal lWidth as long, _
         ByVal lHeight as long, _
         ByVal bFullScreen as Boolean)
         'catch errors
         on local error goto error_handler
         'Create the DirectX Object
         Set dx = New DirectX8
         'Create the Direct3D Object
         Set d3d = dx.Direct3DCreate()
         if d3d is nothing then
             MsgBox "Error Initializing Direct3D!"
             Shutdown
         End If
         'use the current color depth
         d3d.GetAdapterDisplayMode D3DADAPTER_DEFAULT, dispmode
         
         'Set up the Present Parameters For Windowed Mode
         With d3dpp
             .hDeviceWindow = hwnd
             .backbuffercount = 1
             .backbufferwidth = lWidth
             .backbufferheight = lHeight
             .SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
              'If change FULLSCREEN to TRue then Windowed = 0 (Fullscreen Mode)
              'else  then Windowed = 1 (Normal Mode)
              if bFullscreen then
                  .Windowed = 0
              else
                  .Windowed = 1
              End If
          End With
    
           'Create the Primary Display Device
            Set d3ddev = d3d.CreateDevice( _
            D3DADAPTER_DEFAULT, _
            D3DDEVTYPE_HAL, _
            hwnd, _
            D3D_CREATE_SORTWARE_VERTEXPROCESSING, _
            d3dpp)
    
            if d3ddev is nothing then
                msgbox "Error Creating Primary Display Device!"
                Shutdown
            End if
    
         exit sub
         error_handler:
         MsgBox "Error Creating Direct Objects!"
         Shutdown
    End Sub
    On Form Load Event

    HTML Code:
    Private Sub Form_Load()
         me.caption = "Color Screen"
         me.scalemode = 3
         me.width = screen.twipsPerPixelX * (SCREENWIDTH + 12)
         me.height = screen.twipsPerPixelY * (SCREENHEIGHT + 30)
         me.show
    
         'Initialize Direct3D
         InitDirect Me.hwnd, SCREENWIDTH, SCREENHEIGHT, FULLSCREEN
          
         'Clear the Screen
         d3ddev.Clear 0, ByVal 0, D3DCLEAR_TARGET, C_BLACK, 1, 0
         
         'Refresh the screen with the color
         d3ddev.Present ByVal 0, ByVal 0, 0, ByVal 0
          
    End Sub
    I hope some people can use this
    Also I am not good with graphics so if someone can send me a small 2D tile game world map, I will show users how a character moves around
    Size 1600 x 1200, Tile Size Does not matter, but I normally use for my world 64 x 64, 32, x 32 is fine. I have a site that I can get the sprites from just not the tiles for the map.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Visual Basic 6 and DirectX8 Tutorial

    Moved To The CodeBank

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width