Results 1 to 20 of 20

Thread: Simple DX8 - Why won't it work?

  1. #1

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417

    Simple DX8 - Why won't it work?

    I am...pretty new to DX in VB. But I'm trying. So I would like anyone to help me figuring out why this won't work.. I'm trying to render a triangle in Full-Screen mode..:P
    VB Code:
    1. Dim DX As New DirectX8
    2. Dim D3D As Direct3D8
    3. Dim D3DDevice As Direct3DDevice8
    4.  
    5. Private Const MyFVF = D3DFVF_XYZ Or D3DFVF_DIFFUSE
    6. Private Type VERTEX
    7.     X As Single
    8.     Y As Single
    9.     Z As Single
    10.     Color As Long
    11. End Type
    12.  
    13. Dim Trekant(0 To 2) As VERTEX
    14. Dim bStop As Boolean
    15.  
    16. Private Sub Form_Click()
    17. bStop = True
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21. Set DX = New DirectX8
    22. Set D3D = DX.Direct3DCreate
    23.  
    24. Call Initialize
    25. Call CreateGeometry
    26.  
    27. Do Until bStop = True
    28. Render
    29. DoEvents
    30. Loop
    31.  
    32. Unload Me
    33. End
    34. End Sub
    35.  
    36. Sub Initialize()
    37.  
    38. Dim DisplayMode As D3DDISPLAYMODE
    39. Dim D3DPP As D3DPRESENT_PARAMETERS
    40.  
    41. DisplayMode.Format = D3DFMT_R5G6B5
    42. DisplayMode.Width = 640
    43. DisplayMode.Height = 480
    44.  
    45. D3DPP.SwapEffect = D3DSWAPEFFECT_FLIP
    46. D3DPP.BackBufferCount = 1
    47. D3DPP.BackBufferWidth = 640
    48. D3DPP.BackBufferHeight = 480
    49. D3DPP.BackBufferFormat = DisplayMode.Format
    50. D3DPP.hDeviceWindow = Form1.hWnd
    51.  
    52. Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, _
    53.                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DPP)
    54.                                
    55. D3DDevice.SetRenderState D3DRS_LIGHTING Or D3DRS_CULLMODE, False Or D3DCULL_NONE
    56. D3DDevice.SetVertexShader MyFVF
    57. End Sub
    58.  
    59. Sub Render()
    60. D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 1#, 0
    61.  
    62. D3DDevice.BeginScene
    63.  
    64. D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLELIST, 1, Trekant(0), Len(Trekant(0))
    65.  
    66. D3DDevice.EndScene
    67. D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
    68. End Sub
    69. Sub CreateGeometry()
    70. Trekant(0) = CrtVertex(10, 10, 0, RGB(255, 0, 0))
    71. Trekant(1) = CrtVertex(10, 200, 0, RGB(255, 0, 0))
    72. Trekant(2) = CrtVertex(200, 10, 0, RGB(255, 0, 0))
    73. End Sub
    74.  
    75. Private Function CrtVertex(X As Single, Y As Single, Z As Single, Color As Long) As VERTEX
    76. CrtVertex.X = X
    77. CrtVertex.Y = Y
    78. CrtVertex.Z = Z
    79. CrtVertex.Color = Color
    80. End Function

    In advance, thank you
    -Lars Espen Rosness
    Last edited by rEaL iGoR; May 11th, 2002 at 02:11 PM.
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Try changing R5G6B5 to R8G8B8, and make sure your 3D card supports display acceleration.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Actually, It did not work anyways
    32bit resolution : Check
    640x480: Check
    Code:
    Option Explicit
    
    Dim DX As New DirectX8
    Dim D3D As Direct3D8
    Dim D3DDev As Direct3DDevice8
    
    Const MyFVF = D3DFVF_XYZ Or D3DFVF_DIFFUSE
    
    Private Type VERTEX
        X As Single
        Y As Single
        Z As Single
        Color As Long
    End Type
    
    Dim Triangle(0 To 2) As VERTEX
    
    Private Sub Form_Load()
    Me.Show
    InitProject
    CreateGeom
    
    Do
    RenderProject
    DoEvents
    Loop
    
    Set DX = Nothing
    Set D3D = Nothing
    Set D3DDev = Nothing
    End Sub
    
    
    Sub InitProject()
    
    Set DX = New DirectX8
    Set D3D = DX.Direct3DCreate
    
    Dim DisplayMode As D3DDISPLAYMODE
    DisplayMode.Format = D3DFMT_X8R8G8B8
    DisplayMode.Width = 640
    DisplayMode.Height = 480
    
    D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DisplayMode
    
    Dim D3PP As D3DPRESENT_PARAMETERS
    D3PP.Windowed = 1
    D3PP.BackBufferCount = 1
    D3PP.BackBufferFormat = DisplayMode.Format
    D3PP.BackBufferWidth = 640
    D3PP.BackBufferHeight = 480
    D3PP.SwapEffect = D3DSWAPEFFECT_FLIP
    D3PP.hDeviceWindow = Form1.hWnd
    Set D3DDev = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, _
                D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3PP)
    
    D3DDev.SetVertexShader MyFVF
    D3DDev.SetRenderState D3DRS_LIGHTING, False
    End Sub
    
    Sub CreateGeom()
    Triangle(0).X = 0
    Triangle(0).X = 0
    Triangle(0).X = 0
    Triangle(0).Color = vbRed
    
    Triangle(1).X = 0
    Triangle(1).Y = 200
    Triangle(1).Z = 0
    Triangle(1).Color = vbRed
    
    Triangle(2).X = 200
    Triangle(2).X = 200
    Triangle(2).X = 0
    Triangle(2).Color = vbRed
    End Sub
    
    
    Sub RenderProject()
    D3DDev.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 1#, 0
    
    D3DDev.BeginScene
    
    D3DDev.DrawPrimitiveUP D3DPT_TRIANGLELIST, 1, Triangle(0), Len(Triangle(0))
    D3DDev.EndScene
    
    D3DDev.Present ByVal 0, ByVal 0, 0, ByVal 0
    End Sub
    My problem is: Though my window turns black and clearly refreshes(I can see my mouse flickers), The triangle I supposably should be viewing is NOT there.
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  4. #4
    Zaei
    Guest
    Try turning backface culling off:
    Code:
    D3DDevice.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)
    If something doesnt show up the way you expect, turn culling off. If it shows up, you know that you defined your vertices in the wrong order. Simply flop the last 2 vertex definition's orders.

    As to the error you were getting; Create a new Module, and define your VECTOR type there, as Public. It should work then.

    Z.

  5. #5

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    VECTOR type? You mean VERTEX type?
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  6. #6

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    GOD DAMN no, it does'nt show. You don't find anything possible mistakes I've made the should prevent it from showing up?
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  7. #7
    Zaei
    Guest
    Wait. I just ran your code, and I know what is wrong =).

    You dont have either a View or Projection matrix created or set. You need to do a few more things. Go and take a look in the SDK docs for Tutorial 3. Take a look though the code. You mostly want to look at the sections that deal with the View, Projection, and World matrices. In a nutshell, the Projection Matrix is what transforms a 3D point into a 2D one. The View Matrix defines your camera, and the World matrix defines world transformations (for instance, you want to move and rotate a mesh. You use the world matrix for those tasks).

    Z.

  8. #8

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Yeah...but I don't believe Jack Hoxley uses it at 3rd Tutorial at DX4VB..I downloaded his code, and it works :P Cannot understand why cause our code is practicly identical...
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  9. #9
    Zaei
    Guest
    To make it show in 2D, Add a Single to your vertex type, AFTER the x, y, and z values, but before everything else, called RHW. Always set it to 1.0 =). Change the first constant in your FVF, to D3DFVF_XYZRHW, and change our vertex definitions so you set the RHW to 1.0. Try that.

    Z.

  10. #10

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    aha. thank you for that. very much. I've come to realize that learning DX in VB is pretty...tiresome. Why? Well, evertime you do something, even COPY that god damn code, it just won't show! I'm getting pretty frustrated here. Because. Now, I attempt a simple textureloading. And I cannot see *** is wrong this time. It's basicly the same code, I just added a few things..
    VB Code:
    1. Dim DX As DirectX8
    2. 'Dimensioning a new object, how exciting!
    3. Dim D3DX As D3DX8
    4. Dim D3D As Direct3D8
    5. Dim D3DDevice As Direct3DDevice8
    6.  
    7. Const MyFVF = D3DFVF_XYZRHW Or D3DFVF_DIFFUSE Or D3DFVF_TEX1 Or D3DFVF_SPECULAR
    8. Private Type VERTEX
    9.     X As Single
    10.     Y As Single
    11.     Z As Single
    12.     RHW As Single
    13.     Color As Long
    14.     Specular As Long
    15.     TU As Single
    16.     TV As Single
    17. End Type
    18.  
    19. 'Dimentioning variables...INCLUDING my new texturevariable!
    20. Dim MTexture As Direct3DTexture8
    21. Dim Square(0 To 3) As VERTEX
    22. Dim Square2(0 To 3) As VERTEX
    23. Dim bStop As Boolean
    24.  
    25. Private Sub Form_Click()
    26. bStop = True
    27. End Sub
    28.  
    29. Private Sub Form_Load()
    30. Set DX = New DirectX8
    31. 'Here is a whole new object. Guess I need it...
    32. Set D3DX = New D3DX8
    33. Set D3D = DX.Direct3DCreate
    34.  
    35. Call Initialize
    36. Call CreateGeometry
    37.  
    38. Do Until bStop = True
    39. Render
    40. DoEvents
    41. Loop
    42.  
    43. Unload Me
    44. End
    45. End Sub
    46.  
    47. Sub Initialize()
    48.  
    49. Dim DisplayMode As D3DDISPLAYMODE
    50. Dim D3DPP As D3DPRESENT_PARAMETERS
    51.  
    52. DisplayMode.Format = D3DFMT_R5G6B5
    53. DisplayMode.Width = 640
    54. DisplayMode.Height = 480
    55.  
    56. D3DPP.SwapEffect = D3DSWAPEFFECT_FLIP
    57. D3DPP.BackBufferCount = 1
    58. D3DPP.BackBufferFormat = DisplayMode.Format
    59. D3DPP.BackBufferWidth = 640
    60. D3DPP.BackBufferHeight = 480
    61. D3DPP.hDeviceWindow = Form1.hWnd
    62.  
    63. Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, _
    64.                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DPP)
    65.                                
    66. D3DDevice.SetRenderState D3DRS_LIGHTING, False
    67. D3DDevice.SetVertexShader MyFVF
    68.  
    69. 'Here is some added code to load the texture
    70. Set MTexture = D3DX.CreateTextureFromFile(D3DDevice, App.Path & "\ExampleTexture.bmp")
    71. End Sub
    72.  
    73. Sub Render()
    74. D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 1#, 0
    75.  
    76. D3DDevice.BeginScene
    77.  
    78. 'Here is some added code to use the texture
    79. D3DDevice.SetTexture 0, MTexture
    80. D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Square(0), Len(Square(0))
    81. D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Square2(0), Len(Square2(0))
    82.  
    83. D3DDevice.EndScene
    84. D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
    85. End Sub
    86.  
    87. Sub CreateGeometry()
    88. 'My nice square that shows up, but without textures
    89. Square(0) = CrtVertex(10, 10, 0, 1, RGB(255, 255, 255), 0, 0, 0)
    90. Square(1) = CrtVertex(210, 10, 0, 1, RGB(255, 255, 255), 0, 1, 0)
    91. Square(2) = CrtVertex(10, 210, 0, 1, RGB(255, 255, 255), 0, 0, 1)
    92. Square(3) = CrtVertex(210, 210, 0, 1, RGB(255, 255, 255), 0, 1, 1)
    93. 'Here is another square. It's there, but it's not textured..
    94. Square2(0) = CrtVertex(210, 10, 0, 1, RGB(255, 255, 255), 0, 0, 0)
    95. Square2(1) = CrtVertex(420, 10, 0, 1, RGB(255, 0, 0), 0, 1, 0)
    96. Square2(2) = CrtVertex(210, 210, 0, 1, RGB(255, 0, 255), 0, 0, 1)
    97. Square2(3) = CrtVertex(420, 210, 0, 1, RGB(0, 255, 255), 0, 1, 1)
    98. End Sub
    99.  
    100. Private Function CrtVertex(X As Single, Y As Single, Z As Single, RHW As Single, Color As Long, _
    101.                             Specular As Long, TU As Single, TV As Single) As VERTEX
    102. CrtVertex.X = X
    103. CrtVertex.Y = Y
    104. CrtVertex.Z = Z
    105. CrtVertex.Color = Color
    106. CrtVertex.Specular = Specular
    107. CrtVertex.TU = TU
    108. CrtVertex.TV = TV
    109. End Function
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  11. #11
    Zaei
    Guest
    Remove the Specular component of your variable type, the reference to it in your FVF declaration, and any references to it in your code. it should work then.

    Z.

  12. #12

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Nope. It does'nt..The texture still won't show...anything else?
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  13. #13
    Zaei
    Guest
    I have had this problem before. If you go and change the clear color to something like &H000000ff, you will see that your squares are still drawing, but the texture is being applied incorrectly. I dont remember how I fixed it, but I will see if I can find it.

    Z.

  14. #14
    Zaei
    Guest
    Ok, it seems to be that the D3DX functions are the problem. It probably doesnt like your texture format. Try this. Open the DirectX Texture tool (it comes with the SDK, its in the Utilities folder of your start menu), and convert your textuer to .dds format. It should work.

    Z.

  15. #15

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Are you sure about that? Because, Jack Hoxley uses the exact same format...I've copied his code. Well, I've written so it kind of matches his. Then, I've cut down on his code so that it's exactly the same as mine. And HIS code works :P
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  16. #16
    Zaei
    Guest
    Try using the same image that he uses.

    This is why I wrote my own texture format for TOW =).

    Z.

  17. #17

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Well...I am using a copy of his picture
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  18. #18
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I had this problem before and what I did was change the textureload command to the Extended function... that worked for me... give it a try if you haven't yet
    Sanity is a full time job

    Puh das war harter Stoff!

  19. #19

    Thread Starter
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    Hell! I'm soon-to-giveup this! It still won't work
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  20. #20
    Zaei
    Guest
    Eh, I know exactly how it feels. Try changing the Pool value to something else (from D3DPOOL_DEFAULT to _MANAGED or _SYSTEMMEM) (I think there is a pool value needed in the D3DX load texture call) (ack, my brain is degrading!!!). You might want to try copying the entire source from Jack's example, then strip it down until it doesnt work, and see whats going wrong.

    Z.

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