Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

A Clicker Game within DirectX 1/4

$
0
0
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 describes 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 Window JP Edition, I'd like readers to adjust those tags to be applied 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 continues... thanks for reading

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>