Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Viewports and depth

dixciedixcie Member Posts: 3
Hello,

when I create my little game without viewport there's no problem. But when I use a viewport the objects are displayed in the order I created them and not in function of their Z coordinate...

Here's some code:
Initializing:
[CODE] Dim Present As PresentParameters = New PresentParameters
DispMode = Microsoft.DirectX.Direct3D.Manager.Adapters.Default.CurrentDisplayMode

Present.Windowed = bWindowed
Present.SwapEffect = SwapEffect.Discard
Present.BackBufferCount = 2
Present.BackBufferFormat = DispMode.Format
Present.BackBufferHeight = DispMode.Height
Present.BackBufferWidth = DispMode.Width

Present.PresentationInterval = PresentInterval.Immediate
Present.AutoDepthStencilFormat = DepthFormat.D16
Present.EnableAutoDepthStencil = True

'Device
Device = New Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, Present)
Device.IsUsingEventHandlers = False

'Render states
SetRenderStates()

'I do only use viewport(1) and it's all width and height
Viewport(1) = New Viewport
Viewport(2) = New Viewport

Viewport(1).X = 0
Viewport(1).Y = 0
Viewport(1).Width = DispMode.Width
Viewport(1).Height = DispMode.Height ' / 2
Viewport(2).X = 0
Viewport(2).Y = DispMode.Height / 2
Viewport(2).Width = DispMode.Width
Viewport(2).Height = DispMode.Height[/CODE]

In the loop:
[CODE] Device.Viewport = Viewport(1) 'IF I REMOVE THIS LINE THERE IS NO PROBLEM...

'----------------------- BEGIN -----------------------
Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Gray, 1.0, 0)

'I draw everything here

Device.EndScene() 'all drawings before this line
Device.Present()

[/CODE]

So, why isn't it working well with a viewport?
Thanks in advance!

dixcie

Comments

  • dixciedixcie Member Posts: 3
    Ok it's solved now, I just had to set the minZ and maxZ of the viewports to 0 and 1, but I didn't knew that before...

    However I've another question concerning the viewports:
    when I use different viewports, the fog is only displayed in the first one... Other renderstates like alphablendenable etc seem to work well in each of them.
    Here is the code I put after opening each viewport:

    [CODE]
    With Device.RenderState
    .FogStart = 2000
    .FogEnd = 7000
    .FogColor = Color.Gray
    .FogTableMode = FogMode.Linear
    .FogEnable = True
    End With
    [/CODE]

    Do you know how to solve this problem please?
    Thanks in advance!

    : Hello,
    :
    : when I create my little game without viewport there's no problem.
    : But when I use a viewport the objects are displayed in the order I
    : created them and not in function of their Z coordinate...
    :
    : Here's some code:
    : Initializing:
    : [CODE] Dim Present As PresentParameters = New
    : PresentParameters
    : DispMode =
    : Microsoft.DirectX.Direct3D.Manager.Adapters.Default.CurrentDisplayMod
    : e
    :
    : Present.Windowed = bWindowed
    : Present.SwapEffect = SwapEffect.Discard
    : Present.BackBufferCount = 2
    : Present.BackBufferFormat = DispMode.Format
    : Present.BackBufferHeight = DispMode.Height
    : Present.BackBufferWidth = DispMode.Width
    :
    : Present.PresentationInterval = PresentInterval.Immediate
    : Present.AutoDepthStencilFormat = DepthFormat.D16
    : Present.EnableAutoDepthStencil = True
    :
    : 'Device
    : Device = New Direct3D.Device(0,
    : Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me,
    : CreateFlags.HardwareVertexProcessing, Present)
    : Device.IsUsingEventHandlers = False
    :
    : 'Render states
    : SetRenderStates()
    :
    : 'I do only use viewport(1) and it's all width and height
    : Viewport(1) = New Viewport
    : Viewport(2) = New Viewport
    :
    : Viewport(1).X = 0
    : Viewport(1).Y = 0
    : Viewport(1).Width = DispMode.Width
    : Viewport(1).Height = DispMode.Height ' / 2
    : Viewport(2).X = 0
    : Viewport(2).Y = DispMode.Height / 2
    : Viewport(2).Width = DispMode.Width
    : Viewport(2).Height = DispMode.Height[/CODE]
    :
    : In the loop:
    : [CODE] Device.Viewport = Viewport(1) 'IF I REMOVE THIS LINE
    : THERE IS NO PROBLEM...
    :
    : '----------------------- BEGIN -----------------------
    : Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer,
    : Color.Gray, 1.0, 0)
    :
    : 'I draw everything here
    :
    : Device.EndScene() 'all drawings before this line
    : Device.Present()
    :
    : [/CODE]
    :
    : So, why isn't it working well with a viewport?
    : Thanks in advance!
    :
    : dixcie
    :

  • dixciedixcie Member Posts: 3
    The fog appeared again... Don't know how, but its solved...

    : Ok it's solved now, I just had to set the minZ and maxZ of the
    : viewports to 0 and 1, but I didn't knew that before...
    :
    : However I've another question concerning the viewports:
    : when I use different viewports, the fog is only displayed in the
    : first one... Other renderstates like alphablendenable etc seem to
    : work well in each of them.
    : Here is the code I put after opening each viewport:
    :
    : [CODE]
    : With Device.RenderState
    : .FogStart = 2000
    : .FogEnd = 7000
    : .FogColor = Color.Gray
    : .FogTableMode = FogMode.Linear
    : .FogEnable = True
    : End With
    : [/CODE]
    :
    : Do you know how to solve this problem please?
    : Thanks in advance!
    :
    : : Hello,
    : :
    : : when I create my little game without viewport there's no problem.
    : : But when I use a viewport the objects are displayed in the order I
    : : created them and not in function of their Z coordinate...
    : :
    : : Here's some code:
    : : Initializing:
    : : [CODE] Dim Present As PresentParameters = New
    : : PresentParameters
    : : DispMode =
    : : Microsoft.DirectX.Direct3D.Manager.Adapters.Default.CurrentDisplayMod
    : : e
    : :
    : : Present.Windowed = bWindowed
    : : Present.SwapEffect = SwapEffect.Discard
    : : Present.BackBufferCount = 2
    : : Present.BackBufferFormat = DispMode.Format
    : : Present.BackBufferHeight = DispMode.Height
    : : Present.BackBufferWidth = DispMode.Width
    : :
    : : Present.PresentationInterval = PresentInterval.Immediate
    : : Present.AutoDepthStencilFormat = DepthFormat.D16
    : : Present.EnableAutoDepthStencil = True
    : :
    : : 'Device
    : : Device = New Direct3D.Device(0,
    : : Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me,
    : : CreateFlags.HardwareVertexProcessing, Present)
    : : Device.IsUsingEventHandlers = False
    : :
    : : 'Render states
    : : SetRenderStates()
    : :
    : : 'I do only use viewport(1) and it's all width and height
    : : Viewport(1) = New Viewport
    : : Viewport(2) = New Viewport
    : :
    : : Viewport(1).X = 0
    : : Viewport(1).Y = 0
    : : Viewport(1).Width = DispMode.Width
    : : Viewport(1).Height = DispMode.Height ' / 2
    : : Viewport(2).X = 0
    : : Viewport(2).Y = DispMode.Height / 2
    : : Viewport(2).Width = DispMode.Width
    : : Viewport(2).Height = DispMode.Height[/CODE]
    : :
    : : In the loop:
    : : [CODE] Device.Viewport = Viewport(1) 'IF I REMOVE THIS LINE
    : : THERE IS NO PROBLEM...
    : :
    : : '----------------------- BEGIN -----------------------
    : : Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer,
    : : Color.Gray, 1.0, 0)
    : :
    : : 'I draw everything here
    : :
    : : Device.EndScene() 'all drawings before this line
    : : Device.Present()
    : :
    : : [/CODE]
    : :
    : : So, why isn't it working well with a viewport?
    : : Thanks in advance!
    : :
    : : dixcie
    : :
    :
    :

Sign In or Register to comment.