Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    2
  • comments
    0
  • views
    435

A Clicker Game within DirectX 1/4

Sign in to follow this  
aominmeiho

693 views

In the next term(includes 4 posts), I'll deal with a clicker game on this blog planned in submissions bypass Steam Direct previously.

Surely, There are useful famous DLLs to combine VB.net (or C#) and late DirectX, SlimDX and SharpDX existed.

This time, I used SlimDX. but it's capable in the same thing with SharpDX.

Now,  this article and a next one describe that how to code procedural gradient images in Direct2D with slimDX.

The most important information is the issue tales, in VB.net values/objects/classes,

Images shared on PC's main memory, and in Direct2D Brushes, Images shared on GPU's memory.

So both images composed the procedural gradient background, must be lower than PC and GPU memory specs during running applications.

Then I show samples up in source codes below.

1.Values Declarations

some exceptions exist, but most of Direct2D-.net combined objects are created from returning values with the function in another type of Direct2D objects, not from "new statements". 

    Public D2DF As Factory, Wrt As WindowRenderTarget, BasedTextFactory As DirectWrite.Factory
    Private Rtp As RenderTargetProperties, Wrtp As WindowRenderTargetProperties, Rgbp As RadialGradientBrushProperties = New RadialGradientBrushProperties 'Only G-Brush classes created from new statements.

    Public TF1, TF2, TF3, TF4 As SlimDX.DirectWrite.TextFormat
 

2.Making initializer

making it likely C++ programs

    Public Sub InitDx2D()
        Rtp.PixelFormat = New PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
        D2DF = New Factory(FactoryType.Multithreaded) : Form1.Width = 1366 : Form1.Height = 736
        Wrtp.PixelSize = New System.Drawing.Size(Form1.Width - SystemInformation.Border3DSize.Width, Form1.Height - 30)
        Wrtp.Handle = Form1.Handle : Wrt = New WindowRenderTarget(D2DF, Rtp, Wrtp)
        TextsInit() : ImagesInit() : InitOthers()
    End Sub

3.Making text-classes initializer

    Private Sub TextsInit()
        '"en-jp" In Windows JP Edition, I'd like readers to adjust those tags to be applied in your OS language.
        BasedTextFactory = New SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Isolated)
        TF1 = New SlimDX.DirectWrite.TextFormat(BasedTextFactory, "Verdana", SlimDX.DirectWrite.FontWeight.Light, SlimDX.DirectWrite.FontStyle.Oblique, SlimDX.DirectWrite.FontStretch.SemiCondensed, 14, "en-jp")
        TF2 = New SlimDX.DirectWrite.TextFormat(BasedTextFactory, "Times New Roman", SlimDX.DirectWrite.FontWeight.UltraLight, SlimDX.DirectWrite.FontStyle.Oblique, SlimDX.DirectWrite.FontStretch.SemiCondensed, 38, "en-jp")
        TF3 = New SlimDX.DirectWrite.TextFormat(BasedTextFactory, "Consolas", SlimDX.DirectWrite.FontWeight.Light, SlimDX.DirectWrite.FontStyle.Oblique, SlimDX.DirectWrite.FontStretch.SemiCondensed, 17, "en-jp")
        TF4 = New SlimDX.DirectWrite.TextFormat(BasedTextFactory, "Georgia", SlimDX.DirectWrite.FontWeight.Thin, SlimDX.DirectWrite.FontStyle.Normal, SlimDX.DirectWrite.FontStretch.SemiCondensed, 26, "en-jp")
    End Sub

4.Making ImageLoader

Honestly this function owns difficult logic relied on SlimDX-side peculiar system. Anyway, this function transforms .net image-resources into Direct2D data-format. 

    Public Function ImagesLoader(ByVal AnImageDotnetFormatted As Image) As SlimDX.Direct2D.Bitmap
        Dim b As New System.Drawing.Bitmap(AnImageDotnetFormatted), bmpD As System.Drawing.Imaging.BitmapData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)
        Dim Stm As SlimDX.DataStream = New SlimDX.DataStream(bmpD.Scan0, bmpD.Stride * bmpD.Height, True, False), BPro As New SlimDX.Direct2D.BitmapProperties : BPro.PixelFormat = New PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
        Dim Ret As SlimDX.Direct2D.Bitmap = New SlimDX.Direct2D.Bitmap(Wrt, b.Size, Stm, bmpD.Stride, BPro) : b.UnlockBits(bmpD) : Return Ret
    End Function
 

5.Set basic params up

    Private DRRBrush As SlimDX.Direct2D.Brush
    Private Sub InitOthers()
        DRRBrush = New SlimDX.Direct2D.SolidColorBrush(Wrt, New Color4(0.24, 0.87, 0.72))
        GColors(0) = New Color4(0.65, 0.1, 0.3, 0.62) : GColors(1) = New Color4(0.75, 0, 0.25, 0.15) : GColors(2) = New Color4(0.75, 0.35, 0.15, 0.45) : GColors(3) = New Color4(0.85, 0.2, 0.2, 0.2) : GColors(4) = New Color4(1, 0, 0.03, 0.05)
        ColorsInStrs = New Color4(0.85, 0.8, 0.95, 0.9) : InitColors = New Color4(1, 0.45, 0.61, 0.12) : BeingGenerated = True : ColoredPens = New SolidColorBrush(Wrt, New SlimDX.Color4(1, 0.083, 0.13, 0.18))
        EXT1Colors(1) = New SlimDX.Color4(0.8, 0.3, 0.85, 0.3) : EXT1Colors(2) = New SlimDX.Color4(0.8, 0.3, 0.3, 0.85) : EXT1Colors(3) = New SlimDX.Color4(0.8, 0.85, 0.3, 0.3)
        EXT2Colors(2) = Form1.Width / 2 : EXT2Colors(6) = Form1.Width / 2 : EXT2Colors(3) = Form1.Height / 2 : EXT2Colors(7) = Form1.Height / 2
    End Sub

6.1 - A Basic Format in Gradient Brushes  
    Private Sub BuildGradientParams(ByVal Pos As BasicPosInfo, ByVal GColors() As SlimDX.Color4, ByVal InflectionPoints() As Single)
        'Dim Rgbp As RadialGradientBrushProperties = New RadialGradientBrushProperties
        Dim GColorsB(GColors.Length) As GradientStop, CounterIndex As Integer
        For CounterIndex = 0 To GColors.Length - 1
            GColorsB(CounterIndex).Color = GColors(CounterIndex) : GColorsB(CounterIndex).Position = InflectionPoints(CounterIndex) : Next
        Dim Rgbp2 As GradientStopCollection = New GradientStopCollection(Wrt, GColorsB)
        Rgbp.CenterPoint = New PointF(Pos.XPos, Pos.YPos) : Rgbp.HorizontalRadius = Pos.Radius : Rgbp.VerticalRadius = Pos.Radius
        Dim GG_pen As SlimDX.Direct2D.RadialGradientBrush = New SlimDX.Direct2D.RadialGradientBrush(Wrt, Rgbp2, Rgbp)
    End Sub

continues...

thanks for reading

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!