Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276

    Arrow [TUT] VB.net DirectX [TUT]

    ~DIRECTX in VB.NET~

    Tutorial 1

    "The Basics - The BlueScreen"



    Interested in exploring the world of directX? Then read on!

    Alright lets see, where should we start? Ahhh yes, lets start with the basics, the very very basics, rendering a blank screen.
    lets get started.


    - What you need -

    {

    -Visual Basic 2008 or 2005
    -the most recent DirectX SDK - you can get it here Download details: DirectX SDK - (February 2010)
    -a decent video card.

    }

    - Creating the Project -

    {

    1. Create a new Windows project in Visual Basics 2008( will work with earlier versions of VB.net)
    2. Add a new reference to Microsoft.Microsoft.DirectX , Microsoft.DirectX.Direct3D , and Microsoft.DirectX.Direct3D.D3DX .
    If you don't know how to do this already, follow the Steps Listed in " -Adding the References- "

    }

    -Adding The References-

    {

    1. Goto to the "project" drop down menu and you should see "Add Reference". Wait for it to load up (sometimes it takes a minute or to as it is searching the computer for references)
    2. Scroll down and add all these References:
    Code:
     - Microsoft.Microsoft.DirectX , 
               Microsoft.DirectX.Direct3D , 
               Microsoft.DirectX.Direct3D.3DX
    }


    -Using the References-

    {

    1. Add these lines to the top of your code.

    Code:
    Imports Microsoft.DirectX
    Imports Microsoft.DirectX.Direct3D
    Imports Microsoft.DirectX.Direct3D.D3DX
    }

    We are not going to be using form1 Just yet. Instead we are going to be adding a class.

    -Creating the gameClass-

    {

    In this part of the tutorial we'll be adding a class to our project. Classes are very important. Without classes you would end up
    writing the same code over and over again, and that's not very fun or efficient. Using Classes also make your project much more organized. You'll understand why later on.

    Lets add a class to our project!

    1. GoTo the "Project" drop down menu and you should see "Add New Item", Click on it.
    2. Click on the Class template. Name our class "gameClass".
    3. Lets add the Imports Statements to the top of our class. (you can get rid of any other Statements)

    Code:
      Imports Microsoft.DirectX
           Imports Microsoft.DirectX.Direct3D
           Imports Microsoft.DirectX.Direct3D.D3DX
    }

    - Declaring our variables -

    {

    We need to add some variables to our class.
    1. Open up the code page for our gameClass
    2. add these variables :

    Code:
     Private displaySettings As DisplayMode
            
            Private deviceParameters As PresentParameters
    
            Public device As Device
            
            Public gameExit As Boolean
    }


    Now we need to add a new Sub to our class.

    - Adding the Initialize Sub -

    {

    1. Add a new Sub and call it Initialize.

    Code:
     Public Sub Initialize (ByVal fullScreen As Boolean)
    
              End Sub

    2. Add this code inside of the Sub:

    Code:
     If fullScreen Then
    
                displaySettings.Width = 800
               
                displaySettings.Height = 600
           
                displaySettings.Format = Format.X8R8G8B8
    
            Else
               
                displaySettings = Manager.Adapters.Default.CurrentDisplayMode
    
            End If
    What we just did:

    - first we checked to see if fullScreen is true
    if true, we set the resolution to 800 by 600 and set the format to 32bits, else we set it to the CurrentDisplayMode of the Computer.



    3. Now add this code right under it:

    Code:
     deviceParameters = New PresentParameters()
    
                deviceParameters.BackBufferWidth = displaySettings.Width
    
                deviceParameters.BackBufferHeight = displaySettings.Height
    
                deviceParameters.BackBufferFormat = displaySettings.Format
    
                deviceParameters.SwapEffect = SwapEffect.Discard
    
                deviceParameters.PresentationInterval = PresentInterval.Immediate
    
    
                If fullScreen Then
                  deviceParameters.Windowed = False
                Else
                  deviceParameters.Windowed = True
                End If

    What we just did:

    - We set the deviceParameters to the displaySettings. Then we set the SwapEffect to discard and then PresentInterval to Immediate.
    but what does SwapEffect and PresentationInterval even mean? Well the SwapEffect tells the device how to go from one frame to the next. We have set it to overwrite the previous frames. The PresentationInterval tells the device how often to show the frames. We've set it to show the frames immediately, not to wait for anything.
    - After we set up the deviceParameters, we checked if fullScreen was true again. If true we set the display window to Fullscreen, if false, We set the display window to windowed.

    }



    Lets add another sub to our gameClass

    - Adding the LoadContent sub -

    {

    The loadContent sub is where we are going to load all our textures and models later on.

    1.Add a new sub and call it loadContent()

    2.Add this line of code inside of it.

    Code:
     device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Form1.Handle, CreateFlags.SoftwareVertexProcessing, deviceParameters)
    3. add this code to the end of our initialize sub

    Code:
      loadContent()

    What we just did:
    - we set the up the device. Which gets the graphics adapter, sets the devicetype, gets the window to draw to, sets the vertex processing to Software processing, and gets the deviceParameters.
    i could explain this more if you would like..but i figured you just want to move along
    - then we told it to execute the loadContent sub inside of our initialize sub.

    info : You may be wondering what vertex's are? Well there the points that make up the triangles, and the triangles make up everything. Well be using triangles and verticals in the next tutorial.

    }

    We will be adding yet another sub to our gameClass.

    - Adding the Draw sub -

    {

    The Draw Sub is where we will be doing all our rendering.

    1. Add a new sub to your gameClass and call it Draw

    Code:
         Public Sub Draw()
               End sub

    2. now add this code inside the Draw sub:

    Code:
      Do While Not gameExit
    
              Loop
    
              
              thisExit()
    What we just did :

    - We added a loop inside of our Draw sub. We are going to render inside this loop. Then we told
    the game to excectute a sub called, thisExit(), if the loop is no longer true. We are going to create
    the thisExit() sub now. We are not finished with the draw sub yet, but will be back to it in a minute.

    }

    Lets now add the thisExit sub.

    - Adding the thisExit sub -

    {
    This sub will be the Exit sub for our app.

    1. Add a new sub to your gameClass and call it thisExit()

    2. add this code inside:

    Code:
     displaySettings = Nothing
             deviceParameters = Nothing
             device.Dispose()
             device = Nothing
             Application.Exit()

    What We just did.

    First we cleared the displaySettings, deviceParameters, and the device. Then We Exited the
    application.

    }

    Now we go back to our Draw sub

    - Setting up our Draw Sub -

    1. We need to add this code to our Draw Sub inside the loop we added earlier.

    Code:
    device.Clear(ClearFlags.Target, Color.CornFlowerBlue, 1, 0)
    
       device.BeginScene()
    
       device.EndScene()
       
       device.Present()
      
       Application.DoEvents()
    What We just did:

    -We set the device to clear the screen everytime the loop is executed. We set the back color to blue.
    then we began the drawScene(). This is were we draw everything. Then we Ended the Scene
    and we added Application.DoEvents to so that our application wont freeze and ignore keypresses.

    }

    We are now going to load our gameClass and detect keypresses.

    - Detecting Keypresses, loading our class, and Exiting the game -

    {

    1. Go to our Form1 one and go to the code page.

    2. Add this varable in our globals.

    Code:
        Dim game As New gameClass
    4. Add this code.

    Code:
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.Escape Then game.gameExit = True
    End sub
    5. Now add this code inside the Form1_Load sub:

    Code:
       Me.Show()
    
       game.Initialize(True)
       game.Draw()

    What we just did:

    - First We detected if the "Escape" key was pressed, then we told we set the gameExit to true which will exit the game.
    - then we loaded up our Initialize and Draw subs.

    }



    Now run this code and you should get a blue screen! Aren't you exited! A blue screen isn't very exciting is it. Don't worry, well be getting into some
    more exciting stuff in the next tutorial! Don't feel like you wasted your time. Its very important to get a grasp of the basics. Ive tried to help you do that. This code is the backbone for everything else.
    Suggestion: While your waiting for the next tutorial, i recommend learning it so you can write it out from memory. That should not be to difficult, as its not much code.

    Now that we have the base of our code set up, We are ready to start rendering. We will learn how to render a sprite, a triangle in 3d space, and
    draw text to our screen in the next tutorial "Basic rendering".



    Your gameClass Code should look something like this:

    Code:
    Imports Microsoft.DirectX
    Imports Microsoft.DirectX.Direct3D
    Imports Microsoft.DirectX.Direct3D.D3DX
    
    Public Class gameClass
    
        Private displaySettings As DisplayMode 
    
        Private deviceParameters As PresentParameters 
    
        Public device As Device 
    
        Public gameExit As Boolean
    
        Public Sub Initialize(ByVal fullScreen As Boolean)
    
    
    
    
    
            If fullScreen Then
    
                displaySettings.Width = 800
    
                displaySettings.Height = 600
    
                displaySettings.Format = Format.X8R8G8B8
    
            Else
    
                displaySettings = Manager.Adapters.Default.CurrentDisplayMode
    
            End If
    
    
    
    
            deviceParameters = New PresentParameters()
    
            deviceParameters.BackBufferWidth = displaySettings.Width
    
            deviceParameters.BackBufferHeight = displaySettings.Height
    
            deviceParameters.BackBufferFormat = displaySettings.Format
    
            deviceParameters.SwapEffect = SwapEffect.Discard
    
            deviceParameters.PresentationInterval = PresentInterval.Immediate
    
    
            If fullScreen Then
                deviceParameters.Windowed = False
            Else
                deviceParameters.Windowed = True
            End If
    
            LoadContent()
    
    
        End Sub
    
        Public Sub LoadContent()
            device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Form1.Handle, CreateFlags.SoftwareVertexProcessing, deviceParameters)
    
        End Sub
    
        Public Sub Draw()
    
            Do While Not gameExit
    
                device.Clear(ClearFlags.Target, Color.CornFlowerBlue, 1, 0)
    
                device.BeginScene()
    
                device.EndScene()
    
                device.Present()
    
                Application.DoEvents()
    
            Loop
    
    
            thisExit()
    
        End Sub
    
        Public Sub thisExit()
            displaySettings = Nothing
            deviceParameters = Nothing
            device.Dispose()
            device = Nothing
            Application.Exit()
        End Sub
    End Class

    Next Tutorial - " The Basics - Basic Rendering "

    Upcoming Tutorials:

    - "Basic Rendering"
    - "Loading a Model"
    - "Texturing"
    - "Cameras and Movement"
    Last edited by NextGen1; 02-23-2010 at 11:51 AM.

  2. The Following 15 Users Say Thank You to XGelite For This Useful Post:

    /b/oss (03-14-2010),Blubb1337 (02-23-2010),gamernuub (09-14-2010),guza44_44 (02-23-2010),Hassan (08-23-2010),jaake (03-14-2010),jxw (10-10-2012),Kryo4lex (04-20-2012),Lolland (02-23-2010),Neechan' (09-03-2011),NextGen1 (02-22-2010),why06 (02-23-2010),zifra (02-25-2010),Zoom (02-23-2010),|-|3|_][({}PT3R12 (02-22-2010)

  3. #2
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Something everyone has been waiting for


     


     


     



    The Most complete application MPGH will ever offer - 68%




  4. #3
    Threadstarter
    Synthetic Hacker
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    Quote Originally Posted by NextGen1 View Post
    Something everyone has been waiting for
    Thats good
    Im working on it right now!

  5. #4
    MugNuf's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Posts
    790
    Reputation
    9
    Thanks
    160
    My Mood
    Goofy
    So, what is this going to be. DirectX coding in VB, or coding both, VB and DirectX?

  6. #5
    Threadstarter
    Synthetic Hacker
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    Quote Originally Posted by MugNuf View Post
    So, what is this going to be. DirectX coding in VB, or coding both, VB and DirectX?
    How to use DirectX in VB.net.

  7. #6
    Zoom's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Your going on my 24/7 DDoS hit list.
    Posts
    8,552
    Reputation
    127
    Thanks
    5,970
    My Mood
    Happy
    Quote Originally Posted by XGelite View Post
    How to use DirectX in VB.net.
    OMG I have always wondering how to do it!
    -Rest in peace leechers-

    Your PM box is 100% full.

  8. #7
    Threadstarter
    Synthetic Hacker
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    /discard this post
    Last edited by XGelite; 02-22-2010 at 07:13 PM.

  9. #8
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    I put it in post one, Very good tut, very clean...
    I like it,


     


     


     



    The Most complete application MPGH will ever offer - 68%




  10. The Following User Says Thank You to NextGen1 For This Useful Post:

    XGelite (02-23-2010)

  11. #9
    |-|3|_][({}PT3R12's Avatar
    Join Date
    Nov 2008
    Gender
    male
    Location
    UnkwOwnS
    Posts
    449
    Reputation
    12
    Thanks
    472
    My Mood
    Twisted
    Nice job Really, really good.

    PS: I like the brackets around the different "functions" :P

  12. The Following User Says Thank You to |-|3|_][({}PT3R12 For This Useful Post:

    XGelite (02-23-2010)

  13. #10
    Threadstarter
    Synthetic Hacker
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    Ill be starting on "Basic Rendering" Next week. My plan is to release one every week if i have the time.
    These tutorials should draw more traffic to this section and mpgh.

  14. #11
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    I would like to do my own boxhead game LOLZ I'd be so proud of myself xD

    Thank you for your tutorial I'm going to read it when I'm done with my homework -_-

    ' Yes I do know adobe flash is better to create such games, however this should also be possible in vb, isn't it?

    Link didn't work for me tho...

    DX SDK -> Feb 2010 Download
    Last edited by Blubb1337; 02-23-2010 at 02:09 PM.



  15. #12
    Threadstarter
    Synthetic Hacker
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    Quote Originally Posted by Blubb1337 View Post
    I would like to do my own boxhead game LOLZ I'd be so proud of myself xD

    Thank you for your tutorial I'm going to read it when I'm done with my homework -_-

    ' Yes I do know adobe flash is better to create such games, however this should also be possible in vb, isn't it?

    Link didn't work for me tho...

    DX SDK -> Feb 2010 Download

    not sure what a boxhead game is.. but whatever it is, yeah you should be able to.

    hmm, my link work just fine for me.

  16. #13
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Boxhead 2Play - Spiele-Zone A less advanced for sure =D



  17. #14
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Lol. Im a little late to the party here, but very nice tut XGelite. This is excellent. Now perhaps the VB section can try to incorporate some DirectX stuff in their hacks.

    kudos!

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  18. The Following User Says Thank You to why06 For This Useful Post:

    XGelite (02-23-2010)

  19. #15
    Lolland's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Location
    Lolland!
    Posts
    3,156
    Reputation
    49
    Thanks
    868
    My Mood
    Inspired
    tl;dw, looks good.

    Thanks, may read in the future.

  20. The Following User Says Thank You to Lolland For This Useful Post:

    XGelite (02-23-2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. [TUT][VB.NET] Hardware ID Registration
    By steph777 in forum Programming Tutorials
    Replies: 23
    Last Post: 10-11-2022, 12:45 AM
  2. [Tut]Using VB.net to recieve emails
    By Bombsaway707 in forum Visual Basic Programming
    Replies: 25
    Last Post: 02-18-2011, 02:10 AM
  3. [VB.NET] Video TUTs[MADE BY ME]
    By Deto in forum Programming Tutorials
    Replies: 12
    Last Post: 02-03-2011, 09:01 PM
  4. [TUT] How to make an Updater [VB.net]
    By Ugleh in forum Visual Basic Programming
    Replies: 7
    Last Post: 02-23-2010, 04:20 PM
  5. Tut How To Set Up Mpgh.Net Publics
    By Cheesesong in forum CrossFire Hacks & Cheats
    Replies: 10
    Last Post: 07-28-2009, 10:12 AM

Tags for this Thread