Sprite Class Problems

Started by
-1 comments, last by Sinsys 18 years, 8 months ago
I have a problem with lighting with the spriteclass. I know that there is a way. Bicause if i set the ambient Lighting to (for example) blue. The white place's in the picture bicome blue. So I have Lighting. But not Directional or Pointlight. (vb.net 2005 code) Here is my intalize code:

Public Sub New(ByVal Handle As IntPtr, ByVal Width As Integer, ByVal Height As Integer, ByVal Depth As Integer, ByVal Window As Boolean)
        PresentParameters = New PresentParameters
        PresentParameters.BackBufferCount = 1 'backbuffer number
        PresentParameters.AutoDepthStencilFormat = DepthFormat.D16 'Z/Stencil buffer formats
        PresentParameters.EnableAutoDepthStencil = True 'active Z/Stencil buffer 
        PresentParameters.DeviceWindowHandle = Handle  'handle del form
        PresentParameters.SwapEffect = SwapEffect.Flip 'rendering type
        If Window Then
            PresentParameters.Windowed = True 'setting for windowed mode 
        Else
            PresentParameters.Windowed = False 'setting for fullscreen
            PresentParameters.BackBufferWidth = Width 'screen resolution 
            PresentParameters.BackBufferHeight = Height 'screen resolution 
            If Depth = 32 Then
                PresentParameters.BackBufferFormat = Format.X8R8G8B8 'backbuffer format at 32Bit 
            Else
                PresentParameters.BackBufferFormat = Format.R5G6B5 'backbuffer format at 32Bit 
            End If

        End If
        Device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Handle, CreateFlags.SoftwareVertexProcessing, PresentParameters)

        Device.RenderState.ZBufferEnable = True
    End Sub

        Device.Transform.Projection = Matrix.PerspectiveFovLH(1, 1.33, 1, 1000) ''Math.PI / 4
        Device.Transform.View = Matrix.LookAtLH(CamPos, LookAt, New Vector3(0, 1, 0))
        Device.Transform.World = Matrix.Identity
        Device.Transform.World = Matrix.RotationZ((Math.PI / 2) * 2)

Device.RenderState.AlphaBlendEnable = Enable
        Device.RenderState.SourceBlend = Blend.SourceAlpha
        Device.RenderState.DestinationBlend = Blend.InvSourceAlpha
Light Code

Device.Lights(0).Type = LightType.Directional
        Device.Lights(0).Direction = Pos
        Device.Lights(0).Ambient = Color.FromArgb(0, 0, 0, 0)
        Device.Lights(0).Diffuse = Col
        If Specular = True Then Device.Lights(0).Specular = Col
        Device.Lights(0).Update()
        Device.Lights(0).Enabled = True

        Device.RenderState.Lighting = True
        Device.RenderState.Ambient = Color.FromArgb(0, 5, 5, 5)
        Device.RenderState.SpecularEnable = Specular
Here when I start the sprite class :

    Public Sub StartRender()

        msprite.Begin(SpriteFlags.AlphaBlend Or SpriteFlags.Billboard Or SpriteFlags.ObjectSpace Or SpriteFlags.SortTexture)

        d3d.Device.RenderState.Lighting = True
        d3d.Device.RenderState.Ambient = Color.FromArgb(0, 64, 64, 64)
        Material.Ambient = Color.FromArgb(0, 255, 255, 255)    ' Reflects Red
        Material.Diffuse = Color.FromArgb(0, 255, 255, 255)   ' Reflects Color.Red
        Material.Specular = Color.FromArgb(0, 255, 255, 255)
        Material.SpecularSharpness = 20
        d3d.Device.Material = Material
        d3d.Device.RenderState.ZBufferEnable = True
        d3d.Device.RenderState.AlphaBlendEnable = True
        d3d.Device.RenderState.SourceBlend = Blend.SourceAlpha
        d3d.Device.RenderState.DestinationBlend = Blend.InvSourceAlpha
    
        msprite.End()

This topic is closed to new replies.

Advertisement