Advertisement Jump to content
Sign in to follow this  

Sprite Class Problems

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. ( 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 
            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 
                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).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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!