'---------------------------------
'Title: DirectX Tutorial
'
'Description: This is your first DirectX8 application.
' I made it to where this is the easiest
' method to initialize and render. No
' extra subs/functions, no error handling,
' no modules/classes, no nothing. It can't
' get any easier than this, and makes it easy
' for any beginner to understand.
'
'Author: Jacob Roman
'
'Date: 12/01/2005
'
'Contact: [email]jacob_c_roman@hotmail.com[/email]
'---------------------------------
Option Explicit
Private DirectX8 As DirectX8 'The master DirectX object.
Private Direct3D As Direct3D8 'Controls all things 3D.
Private Direct3D_Device As Direct3DDevice8 'Represents the hardware rendering.
Private Running As Boolean 'Helps determine whether the main game loop is running.
Private Sub Form_Activate()
frmMain.Caption = "DirectX Tutorial"
Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
Set DirectX8 = New DirectX8 'Creates the DirectX object.
Set Direct3D = DirectX8.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode 'Use the current display mode that you
'are already on. Incase you are confused, I'm
'talking about your current screen resolution. ;)
Direct3D_Window.Windowed = True 'The app will be in windowed mode.
Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
Direct3D_Window.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.
'Creates the rendering device with some useful info, along with the info
'we've already setup for Direct3D_Window.
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
Running = True 'Initializations all set. It's now ok to activate the game loop.
Do While Running = True
DoEvents 'Allow events to happen so the program doesn't lock up.
'----------------------------------------------------
'DirectX automatically handles the framerate for you
'which makes it run (at most) as fast as the monitors
'refresh rate, so you don't need to add extra code to
'slow down the loop and run at a certain number of frames
'per second.
'----------------------------------------------------
'Clears the backbuffer.
Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 0, 0), 1#, 0
'Rendering code goes here, but in this tutorial, it will be empty for now.
'Flips the backbuffer into the form window.
Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
Running = False 'Helps the program bail out of the game loop.
'Unload all of the DirectX objects
Set Direct3D_Device = Nothing
Set Direct3D = Nothing
Set DirectX8 = Nothing
Unload Me 'Unload the form
End 'Ends the program
'Although the Unload statement located above exits the program, you
'will end up with an Automation error after doing so. The End statement
'will help prevent that, and end the app completely.
End Sub