October 26, 2016
Hot Topics:

DirectX - An Overview - Part 2

  • November 19, 2002
  • By Tommy Cason
  • Send Email »
  • More Articles »

First add a reference to DirectX then set the properties of Form1 as follows:

Autoredraw=falseborderstyle=0controlbox=falsemaxbutton=falseminbutton=falsescalemode=3 (pixels)windowstate=2 (Maximised)

This is a generalization, as in different instances; you will want a form complete with the captions and everything. (See below for a good example of what I mean.)

I personally am one of those people guilty of just assuming that if a program compiles and runs fine on my box, it will run just about anywhere. We all know that is not the case. When working with high-end graphics, we have to take into account the multitude of resolutions and configurations out there. As with the golf game Links386 that was released a few years back, sometimes we might want to consider adding a utility to help our users fine-tune their graphics settings, or we might want to try to detect the optimal configuration. By taking a look at Enumeration, we can find a good approach resolving this issue.

So, lets get started. Make a new project, (dont forget your reference to the DirectX type libraries) and make a form. In this instance, the caption, etc. does not really matter, so set the general properties however you like. Lastly, add a ComboBox, name it Combo1 and set the Style property to 2.
Put this code in the form:

'(DECLARATIONS)Dim DX As New DirectX7Sub GetDisplayCards()Dim ddEnum As DirectDrawEnumDim strGuid As StringSet ddEnum = DX.GetDDEnum()For i = 1 To ddEnum.GetCount()strGuid = ddEnum.GetGuid(i)GetDisplayModes strGuidNextEnd Sub'The Guid (Graphical User Interface Device) Number 'is used by DirectX to determine what you are talking 'to. Each GFX 'board in your computer will have a different number.Sub GetDisplayModes(sGuid As String)Dim DisplayModesEnum As DirectDrawEnumModesDim ddsd2 As DDSURFACEDESC2Dim dd As DirectDraw7Set dd = DX.DirectDrawCreate(sGuid)dd.SetCooperativeLevel Me.hWnd, DDSCL_NORMAL Set DisplayModesEnum = dd.GetDisplayModesEnum(0, ddsd2)Dim OutPut As StringFor i = 1 To DisplayModesEnum.GetCount()DisplayModesEnum.GetItem i, ddsd2OutPut = Trim(Str(ddsd2.lWidth) &  x & Str(ddsd2.lHeight) &  x &Str(ddsd2.ddpfPixelFormat.lRGBBitCount))Combo1.AddItem OutPut, 0 Adds the new item to the top of the list:Youll get it in decending Numerical OrderNextSet dd = NothingEnd SubPrivate Sub Form_Load()Me.ShowGetDisplayCardsEnd Sub

You will end up with a list of various resolutions and color depths that your card supports. Obviously, there are a number of ways you can use this information to assist you and those running your programs.

Whether it is an intro screen to your game or you are making a multimedia presentation using DirectX (one fellow I know went all the way in his database app - he made a cube that rotated and exploded the side the user was working on after the correct data was entered) At some point you are going to get the urge to add some dynamic text to your application. Using the text method, you can output text from any string to any location on the screen.

Surface.DrawText X,Y,Text, b as boolean

The Text can be written straight into the line, or from a pre-defined variable. The X,Y specify the top-left corner of the text. b doesnt seem to affect Visual Basic, it is best left to false.

To specify a font other than the system font, use the following code:

'in (Declarations):Global myfont As New StdFont'wherever! (Init_DX or BLT)ddsBack.SetForeColor RGB(255, 255, 255)   'Set the colour of the text.myfont.Name = Terminal   'a system font.myfont.Size = 9myfont.Bold = FalseddsBack.SetFont myfont  'Apply the font to the surface. 

You will need to make sure that the end-user has the font you wish to use as well; otherwise Windows will attempt a substitution. Keep in mind that you can make your own font (like in Diablo) using commercial tools such as Macromedias Fontographer or many great font makers scattered over the net.

Page 2 of 4

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel