Page 2 of 2 FirstFirst 12
Results 41 to 44 of 44

Thread: DirectX 2D Tutorials For VB5/VB6/VB.NET

  1. #41

    Thread Starter
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: DirectX 2D Tutorials For VB5/VB6/VB.NET

    Also coming soon, I'm writing C# DirectX9 tutorials as well.

  2. #42

    Thread Starter
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: DirectX 2D Tutorials For VB5/VB6/VB.NET

    I've decided to go truely Massive and plan to dedicate my tutorials to a website with my own domain name which I haven't created yet. The following languages will be covered (and I'm not kidding):
    • Visual C++ 6.0 - DirectX7 / DirectX8 / DirectX9
    • Visual C++ 2008 - DirectX9
    • Visual C++ 2010 - DirectX9
    • Visual C# 2008 - DirectX9
    • Visual C# 2010 - DirectX9
    • Visual Basic 6.0 - DirectX7 / DirectX8
    • Visual Basic.Net 2008 - DirectX9
    • Visual Basic.Net 2010 - DirectX9

    I have tons of tutorials made already in all these languages, with all of em being consistant in structure, variable names, functions, etc. I will also have a Word document explaining step by step on how to initialize DirectX to your IDE in all these languages. It's been a lot of hard work and there are no plans yet to include DirectX10 and DirectX11 or XNA but if I decide to, I'll include it. Also there are no plans whether I should include Visual Studio.Net 2003 / 2005, because the damn links have been removed by MS. So your wisest choice is to upgrade to VS 2008 or VS 2010. Each of these tutorials will be simplified and only have one file to work with. So there won't be no header files or anything in C++. Just one Main.cpp. C# will only have one Main.cs. VB6 only one Main.frm, etc. And each language will consist of a ton of tutorials to cover, but no idea on how many for each just yet, in both 2D and 3D, but not limited to just DirectDraw 2D, it'll have Direct3D 2D as well.

    When I said consistantcy, I meant it. Compare these 2 languages for example:
    c++ Code:
    1. #include <windows.h>
    2. #include <d3d8.h>
    3.  
    4. struct CUSTOM_VERTEX
    5. {
    6.     float X, Y, Z, RHW;
    7.     DWORD Color;
    8. };
    9.  
    10. #define CUSTOM_VERTEX_FORMAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
    11.  
    12. const D3DFORMAT COLOR_DEPTH_16_BIT = D3DFMT_R5G6B5;
    13. const D3DFORMAT COLOR_DEPTH_24_BIT = D3DFMT_A8R8G8B8;
    14. const D3DFORMAT COLOR_DEPTH_32_BIT = D3DFMT_X8R8G8B8;
    15.  
    16. LPDIRECT3D8 Direct3D = NULL;
    17. LPDIRECT3DDEVICE8 Direct3D_Device = NULL;
    18. D3DDISPLAYMODE Display_Mode;
    19. D3DPRESENT_PARAMETERS Direct3D_Window;
    20. HWND hWnd;
    21. MSG msg;
    22. bool Fullscreen_Enabled;
    23. bool Running;
    24. CUSTOM_VERTEX Vertex_List[3];
    25.  
    26. CUSTOM_VERTEX Create_Custom_Vertex();
    27. void Create_Polygon();
    28. void Draw_Polygon();
    29. void Render();
    30. void Game_Loop();
    31. void Main();
    32. void Shutdown();
    33. void DirectX8_Initialize();
    34. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    35.  
    36. CUSTOM_VERTEX Create_Custom_Vertex(float X, float Y, float Z, float RHW, DWORD Color)
    37. {
    38.     CUSTOM_VERTEX Vertex;
    39.  
    40.     Vertex.X = X;
    41.     Vertex.Y = Y;
    42.     Vertex.Z = Z;
    43.     Vertex.RHW = RHW;
    44.     Vertex.Color = Color;
    45.  
    46.     return Vertex;
    47. }
    48.  
    49. void DirectX8_Initialize()
    50. {
    51.     Direct3D = Direct3DCreate8(D3D_SDK_VERSION);
    52.     memset(&Direct3D_Window, 0, sizeof(D3DPRESENT_PARAMETERS));
    53.  
    54.     if (Fullscreen_Enabled == true)
    55.     {
    56.        Display_Mode.Width = 800;
    57.        Display_Mode.Height = 600;
    58.        Display_Mode.Format = COLOR_DEPTH_16_BIT;
    59.        Direct3D_Window.Windowed = FALSE;
    60.        Direct3D_Window.BackBufferCount = 1;
    61.        Direct3D_Window.BackBufferWidth = Display_Mode.Width;
    62.        Direct3D_Window.BackBufferHeight = Display_Mode.Height;
    63.        Direct3D_Window.hDeviceWindow = hWnd;
    64.     }
    65.     else
    66.     {
    67.        Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &Display_Mode);
    68.        Direct3D_Window.Windowed = TRUE;
    69.     }
    70.     Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY;
    71.     Direct3D_Window.BackBufferFormat = Display_Mode.Format;
    72.     Direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &Direct3D_Window, &Direct3D_Device);
    73. }
    74.  
    75. void Create_Polygon()
    76. {
    77.     Vertex_List[0] = Create_Custom_Vertex(0, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, 255));
    78.     Vertex_List[1] = Create_Custom_Vertex(100, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, 255));
    79.     Vertex_List[2] = Create_Custom_Vertex(0, 100, 0, 1, D3DCOLOR_RGBA(255, 255, 255, 255));
    80.     Vertex_List[3] = Create_Custom_Vertex(100, 100, 0, 1, D3DCOLOR_RGBA(255, 255, 255, 255));
    81. }
    82.  
    83. void Draw_Polygon()
    84. {
    85.     Direct3D_Device->SetVertexShader(CUSTOM_VERTEX_FORMAT);
    86.     Direct3D_Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Vertex_List, sizeof(CUSTOM_VERTEX));
    87. }
    88.  
    89. void Render()
    90. {    
    91.     Direct3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 0, 0, 255), 1.0f, 0); // clear frame
    92.     Direct3D_Device->BeginScene();
    93.     Create_Polygon();
    94.     Draw_Polygon();
    95.     Direct3D_Device->EndScene();
    96.     Direct3D_Device->Present(NULL, NULL, NULL, NULL);
    97. }
    98.  
    99. void Game_Loop()
    100. {
    101.     while (Running == true)
    102.     {
    103.         if (PeekMessage(&msg,NULL,0,0,PM_REMOVE) > 0)
    104.         {
    105.             if (WM_QUIT == msg.message) break;
    106.             TranslateMessage (&msg);
    107.             DispatchMessage (&msg);
    108.         }
    109.         else
    110.             Render();
    111.     }
    112. }
    113.  
    114. void Main()
    115. {
    116.     DirectX8_Initialize();
    117.     Running = true;
    118. }
    119.  
    120. void Shutdown()
    121. {
    122.     Running = false;
    123.     Direct3D_Device->Release();
    124.     Direct3D->Release();
    125.     PostQuitMessage (0);
    126.     HANDLE Process;
    127.     Process = OpenProcess(PROCESS_ALL_ACCESS , true , GetCurrentProcessId());
    128.     TerminateProcess(Process , 0);
    129. }
    130.  
    131. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
    132. {
    133.    
    134.     WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC, WindowProcedure, 0, 0, hInstance, NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, "DX_TUT", NULL};
    135.     RegisterClassEx(&wc);
    136.  
    137.     if (MessageBox(hWnd, "Click Yes to go to fullscreen (Recommended)", "", MB_ICONQUESTION | MB_YESNO) == IDYES)
    138.        Fullscreen_Enabled = true;
    139.  
    140.     if (Fullscreen_Enabled == true)
    141.         hWnd = CreateWindowEx (0, "DX_TUT", "DirectX Tutorial", WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 330, 250, HWND_DESKTOP, NULL, hInstance, NULL);
    142.     else
    143.         hWnd = CreateWindowEx (0, "DX_TUT", "DirectX Tutorial", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 330, 250, HWND_DESKTOP, NULL, hInstance, NULL);
    144.     ShowWindow (hWnd, nCmdShow);
    145.     Main();
    146.     Game_Loop();
    147.     return msg.wParam;
    148. }
    149.  
    150. LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    151. {
    152.     switch (msg)
    153.     {
    154.         case WM_DESTROY:
    155.             Shutdown();
    156.             break;
    157.         case WM_KEYDOWN:
    158.             if(wParam == VK_ESCAPE)
    159.             {
    160.                 DestroyWindow(hWnd);
    161.                 return(0);
    162.             }
    163.         default:
    164.             return DefWindowProc (hWnd, msg, wParam, lParam);
    165.     }
    166.     return 0;
    167. }

    vb Code:
    1. Option Explicit
    2.  
    3. Private Type CUSTOM_VERTEX
    4.  
    5.     X As Single
    6.     Y As Single
    7.     Z As Single
    8.     RHW As Single
    9.     Color As Long
    10.    
    11. End Type
    12.  
    13. Private Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5
    14. Private Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8
    15. Private Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8
    16.  
    17. Private Const CUSTOM_VERTEX_FORMAT As Long = D3DFVF_XYZRHW Or D3DFVF_DIFFUSE
    18.  
    19. Private DX As DirectX8
    20. Private Direct3D As Direct3D8
    21. Private Direct3D_Device As Direct3DDevice8
    22. Private Display_Mode As D3DDISPLAYMODE
    23. Private Direct3D_Window As D3DPRESENT_PARAMETERS
    24.    
    25. Private Fullscreen_Enabled As Boolean
    26. Private Running As Boolean
    27.  
    28. Private Vertex_List(3) As CUSTOM_VERTEX
    29.  
    30. Private Function Create_Custom_Vertex(X As Single, Y As Single, Z As Single, RHW As Single, Color As Long) As CUSTOM_VERTEX
    31.  
    32.     Create_Custom_Vertex.X = X
    33.     Create_Custom_Vertex.Y = Y
    34.     Create_Custom_Vertex.Z = Z
    35.     Create_Custom_Vertex.RHW = RHW
    36.     Create_Custom_Vertex.Color = Color
    37.    
    38. End Function
    39.  
    40. Private Sub DirectX_Initialize()
    41.  
    42.     Set DX = New DirectX8
    43.     Set Direct3D = DX.Direct3DCreate()
    44.    
    45.     If Fullscreen_Enabled = True Then
    46.         Display_Mode.Width = 800
    47.         Display_Mode.Height = 600
    48.         Display_Mode.Format = COLOR_DEPTH_16_BIT
    49.         Direct3D_Window.Windowed = False
    50.         Direct3D_Window.BackBufferCount = 1
    51.         Direct3D_Window.BackBufferWidth = Display_Mode.Width
    52.         Direct3D_Window.BackBufferHeight = Display_Mode.Height
    53.         Direct3D_Window.hDeviceWindow = frmMain.hWnd
    54.     Else
    55.         Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode
    56.         Direct3D_Window.Windowed = True
    57.     End If
    58.    
    59.     Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
    60.     Direct3D_Window.BackBufferFormat = Display_Mode.Format
    61.  
    62.     Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
    63.  
    64. End Sub
    65.  
    66. Private Sub Create_Polygon()
    67.  
    68.     Vertex_List(0) = Create_Custom_Vertex(0, 0, 0, 1, D3DColorRGBA(255, 255, 255, 255))
    69.     Vertex_List(1) = Create_Custom_Vertex(100, 0, 0, 1, D3DColorRGBA(255, 255, 255, 255))
    70.     Vertex_List(2) = Create_Custom_Vertex(0, 100, 0, 1, D3DColorRGBA(255, 255, 255, 255))
    71.     Vertex_List(3) = Create_Custom_Vertex(100, 100, 0, 1, D3DColorRGBA(255, 255, 255, 255))
    72.  
    73. End Sub
    74.  
    75. Private Sub Draw_Polygon()
    76.  
    77.     Direct3D_Device.SetVertexShader CUSTOM_VERTEX_FORMAT
    78.     Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex_List(0), Len(Vertex_List(0))
    79.  
    80. End Sub
    81.  
    82. Private Sub Render()
    83.  
    84.     Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 0, 255), 1#, 0
    85.     Direct3D_Device.BeginScene
    86.     Create_Polygon
    87.     Draw_Polygon
    88.     Direct3D_Device.EndScene
    89.     Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0
    90.  
    91. End Sub
    92.  
    93. Private Sub Game_Loop()
    94.  
    95.     Do While Running = True
    96.         Render
    97.         DoEvents
    98.     Loop
    99.  
    100. End Sub
    101.  
    102. Private Sub Main()
    103.  
    104.     If MsgBox("Click Yes to go to fullscreen (Recommended)", vbQuestion Or vbYesNo, "Options") = vbYes Then Fullscreen_Enabled = True
    105.    
    106.     With Me
    107.         .Show
    108.         .Caption = "DirectX Tutorial"
    109.         If Fullscreen_Enabled = True Then .BorderStyle = vbBSNone
    110.     End With
    111.    
    112.     DirectX_Initialize
    113.     Running = True
    114.     Game_Loop
    115.    
    116. End Sub
    117.  
    118. Private Sub Shut_Down()
    119.  
    120.     Running = False
    121.     Set Direct3D_Device = Nothing
    122.     Set Direct3D = Nothing
    123.     Set DX = Nothing
    124.     Unload Me
    125.    
    126. End Sub
    127.  
    128. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    129.  
    130.     If KeyCode = vbKeyEscape Then Shut_Down
    131.  
    132. End Sub
    133.  
    134. Private Sub Form_Load()
    135.  
    136.     Main
    137.  
    138. End Sub
    139.  
    140. Private Sub Form_Unload(Cancel As Integer)
    141.  
    142.     Shut_Down
    143.    
    144. End Sub

  3. #43

    Thread Starter
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: DirectX 2D Tutorials For VB5/VB6/VB.NET

    Its official. DirectX7 - DirectX11 will be covered with whatever languages support them, along with XNA. I will be covering 2D, 3D, and DirectDraw. The websites up www.massivedirectxtutorial.com but is still undergoing construction since the sites relatively new. I will be covering every aspect of directX possible that no other tutorial has dared to cover, including handling the dreaded Alt Tab issue, which I have completed in C++, C#, VB6, and VB.Net. I hope for this to be the greatest DirectX tutorial online. Its been a hell of a learning process for me and I want to share it with the world.

  4. #44
    Banned
    Join Date
    Dec 2020
    Posts
    1

    Re: DirectX 2D Tutorials For VB5/VB6/VB.NET

    Please allow me to translate your tutorial and publish it. Your name will be signed, but there is no money for you. Whether you agree or not, I will translate. This is your pleasure, you must accept it! (PS: I am a campus security from Greater China)

Page 2 of 2 FirstFirst 12

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