Skip to main content
gamedev.net
🔒 Locked

Z buffer problem

Started by Willywig 0 replies 250+ views
Original Post
Willywig
Willywig
When I use the following code nothing appears if the ZBuffer is enabled... The display is in a picturebox located within a VB form... Can anyone see what I am doing wrong... so that I can use a Z buffer.
      
 Call D3D.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, DispMode)
D3DWindow.Windowed = 1
D3DWindow.BackBufferCount = 1
D3DWindow.BackBufferFormat = DispMode.Format
D3DWindow.BackBufferWidth = DispMode.Width
D3DWindow.BackBufferHeight = DispMode.Height
D3DWindow.hDeviceWindow = Picture1.hWnd
D3DWindow.AutoDepthStencilFormat = D3DFMT_D16
D3DWindow.EnableAutoDepthStencil = 1
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC


If D3D.CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, _
        D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) = D3D_OK Then
  '//Enable a pure 32bit Depth buffer

  D3DWindow.AutoDepthStencilFormat = D3DFMT_D32
  D3DWindow.EnableAutoDepthStencil = 1
  Debug.Print "32 bit Depth buffer selected"

Else '//search for a 24 bit depth buffer


  If D3D.CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, _
          D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) = D3D_OK Then
    '//Enable a 24 bit depth buffer

    D3DWindow.AutoDepthStencilFormat = D3DFMT_D24X8
    D3DWindow.EnableAutoDepthStencil = 1
    Debug.Print "24 bit Depth buffer selected"

  Else
    If D3D.CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, _
            D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) = D3D_OK Then
      '//Enable a 16 bit depth buffer

      D3DWindow.AutoDepthStencilFormat = D3DFMT_D16
      D3DWindow.EnableAutoDepthStencil = 1
      Debug.Print "16 bit Depth buffer selected"

    Else '//hmm. No depth buffers available... Dont use one then :)

      D3DWindow.EnableAutoDepthStencil = 0
      Debug.Print "no Depth buffer selected"

    End If
  End If
End If

Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Picture1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)

D3DDevice.SetVertexShader Lit_FVF

D3DDevice.SetRenderState D3DRS_LIGHTING, False

D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE

'// enable our Z Buffer

D3DDevice.SetRenderState D3DRS_ZENABLE, 1
    
In the Debug Window it says it is choosing the 32 bit Depth buffer but i have tried it with all the buffers to no avail [edited by - willywig on August 9, 2002 11:49:17 AM]
S1CA
S1CA
1. When you call Clear() to clear the backbuffer, make sure you specify the D3DCLEAR_ZBUFFER flag. Also specify 1.0 for the Z parameter.

2. Ensure that the distance between the near and far clipping planes isn''t too big. These are usually specified when creating a perspective projection matrix.

3. Try initialising D3DRS_ZWRITEENABLE and D3DRS_ZFUNC to the defaults specified in the docs.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.