DirectX and DirectDraw are things I’m trying to learn how to do, especially directdraw. I’ve tried a few various tutorials showing how to draw images or shapes but I’ve never been able to do them because visual basic always crashes. Not really, it just stops working for reasons that I will come to.
Okay, so I create a new project and go to references. First I reference the Microsoft.DirectX.dll. Now all of a sudden my computer starts working hard(the fan turns on and starts making a racket). Next I reference the Microsoft.DirectX.DirectDraw.dll. All is good. Next step in the tutorial, I put this in the top of my form’s code(this doesn’t need to be added to make it crash):
Now the problem arises. There are two ways of getting it to happen. #1 is to run the project and #2 is to save the project. After i run it nothing happens. Then after a little bit a message comes up. It’s the “Delay Notification” thing which has the “Switch To…” and “Continue Waiting” buttons”. Neither of them do anything (the message just comes up the next time I click on vb2010) and I have to end the program through task manager. After a little wait another dialog comes up that says “vshost32.exe has encountered a user-defined breakpoint.” Now I can’t hear the fan anymore and the computer is calm. I'm not sure if it makes a difference but i'm using the express version of vb.net so maybe that's the problem.
VB.Net 2010 tends to crash frequently for me too. Thats why I stick with 2008. But if you need help getting DX working here ya go. Be sure the references you link in VB.Net are exactly the same version or there will be problems:
Code:
How to setup DirectX on multiple platforms and languages
Note: BE SURE YOU INSTALLED THE LATEST VERSION OF THE DIRECTX SDK! The latest version contains DirectX9, DirectX10, and DirectX11. However if you want samples for all of the versions of the DirectX SDK's You'll need to install (in the proper order) DirectX 8.1 SDK, DirectX SDK October 2006 (DX9), DirectX SDK August 2008 (DX10), DirectX SDK June 2010 (DX11) (Check for later version of DirectX11 prior to downloading). If you do not do it in the proper order, it'll confuse the IDE and sometimes your DirectX apps won't work properly.
-------------------------------
VB6
-------------------------------
Setting up Project:
- Start a new project and create a Standard EXE.
Setting up for DirectX8:
- Go up in the menu to Project > References...
- Put a check next to "DirectX 8 For Visual Basic Type Library".
- Click Ok
Note For Windows 7 users: this will not be shown in your References. And you will only need to do these parts once ever:
- Put the dx8vb.dll file in your Windows\SysWOW64 folder.
- Drag it into regsvr32.exe to register it in order to use it in VB6 from now on and have it shown in References.
- Go ahead and reopen Visual Basic 6 and check the References again to see if it's there.
If it's still not there, the best approach is to run Command Prompt as an Administrator and reference it, as sometimes simply dragging a file into regsvr32 is not enough. To do this:
- Goto your Start Menu.
- click on the bottom where it says > All Programs and goto Accessories
- Right click Command Prompt.
- Click Run as administrator (should be located under Open).
- Next type regsvr32 "YOUR FILE PATH HERE OF DX8VB.DLL" For example:
regsvr32 "C:\Windows\SysWOW64\dx8vb.dll"
- Now open up a new project in VB, Go up in the menu to Project > References and see if its there? Tada!!! You can now use DirectX8 in VB6 on Windows 7 from now on and no longer need to go through all the BS of using regsvr32 and command prompt.
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------
Visual C++ 6.0
-------------------------------
Setting up Project:
- Go up in the menu and click File > New...
- Click the Projects tab if it's not there already
- Create a new empty Win32 Application Workspace
- Be sure Empty project is selected and click Finish
- Go back up in the menu and click File > New...
- Be sure Files tab is selected and select C++ Source file.
- Name the source file anything you want such as Main
- Click Ok
- Go back up in the menu and click Project > Settings...
- Click the C/C++ tab and remove all Preprocessor definitions. Leave it blank
- Click Ok
Setting up for DirectX8:
- Note: BE SURE DIRECTX8.1 SDK IS INSTALLED!
- Go up in the menu and click Project > Settings...
- Click the C/C++ tab
- Goto the combo box Category: and select Preprocessor
- Go down where it says Additional include directories and manually put in the path to the include directory for whatever DirectX SDK you wanna use
- Next click on the Link tab
- Goto the combo box Category: and select Input
- Go down where it says Additional library path: and manually put in the lib path for whatever DirectX SDK you wanna use. Be sure it's the same DirectX SDK as include!
- Next go back upto the combo box Category: and select General
- Go down to Object/library modules: and add in d3d8.lib and/or whatever DirectX libraries you wanna use that's within the DirectX SDK\lib directory with the correct consistant version number. It doesn't need to be all of them. It can be just one d3d# lib file if it's a simple basic DirectX app. However don't remove the other libraries within Object/library modules: or you won't be able to use them!
- Click Ok
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------
VB.Net 2008
-------------------------------
Setting up Project:
- Start a new project and create a Windows Forms Application.
Setting up for DirectX9:
- Go up in the menu to Project > Add Reference...
- Next goto .NET tab.
- Scroll down to Microsoft.DirectX and click it.
- Hold control and also add Microsoft.DirectX.Direct3D. You are welcome to adding more DirectX references if you choose.
- Click Ok. Now you are ready to code in DirectX9.
Note: If any of the DirectX stuff isn't located in your .NET tab, you may need to manually add it using your Browse tab under (your harddrive letter):\Windows\Microsoft.NET\DirectX For Managed Code\1.0.2902.0 and add your necessary .dll files such as Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll, etc. For any other new projects afterwards, if it's still not there, look under the Recent Tab.
Project must be in X86 for DirectX9 apps to run. And must be done for every new DirectX project. Here's how to set it up.
- Go up in the menu to Build > Configuration Manager...
- If Configuration Manager is not shown, you only need to do this one part once ever. On the Visual Studio Tools menu, click Options, expand Projects and Solutions, and then click General. Click to check Show advanced build configurations and Click Ok. Now it should show up in the menu bar within Build. Go up in the menu to Build > Configuration Manager...
- Go where it says Platform (and NOT Active Solution Platform). Select <New...>. A new window should pop up.
- Where it says New Platform, select x86.
- Click Ok.
- Both Platform and Active Solution Platform should have changed to x86. Click Close.
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------
VB.Net 2010
-------------------------------
Setting up Project:
- Start a new project and create a Windows Forms Application.
Setting up for DirectX9:
- Go up in the menu to Project > Add Reference...
- Next goto .NET tab.
- Scroll down to Microsoft.DirectX and click it.
- Hold control and also add Microsoft.DirectX.Direct3D. You are welcome to adding more DirectX references if you choose.
- Click Ok.
Note: If any of the DirectX stuff isn't located in your .NET tab, you may need to manually add it using your Browse tab under (your harddrive letter):\Windows\Microsoft.NET\DirectX For Managed Code\1.0.2902.0 and add your necessary .dll files such as Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll, etc. For any other new projects afterwards, if it's still not there, look under the Recent Tab.
Project must be in X86 for DirectX9 apps to run. And thankfully it's x86 by default. However the .Net Framework is 4.0 and needs changed to 3.5. Here's how to set it up:
- Go towards the right of the screen where it says Solution Explorer.
- Right click your project name and goto Properties.
- On the left side, select Compile.
- Click on the button Advanced Compile Options... A new window should pop up.
- On the bottom where it says Target Framework, select .NET Framework 3.5
- Click Ok.
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------
Visual C# 2008
-------------------------------
Setting up Project:
- Start a new project and create a Windows Forms Application.
Setting up for DirectX9:
- Go up in the menu to Project > Add Reference...
- Next goto .NET tab.
- Scroll down to Microsoft.DirectX and click it.
- Hold control and also add Microsoft.DirectX.Direct3D. You are welcome to adding more DirectX references if you choose.
- Click Ok. Now you are ready to code in DirectX9.
Note: If any of the DirectX stuff isn't located in your .NET tab, you may need to manually add it using your Browse tab under (your harddrive letter):\Windows\Microsoft.NET\DirectX For Managed Code\1.0.2902.0 and add your necessary .dll files such as Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll, etc. For any other new projects afterwards, if it's still not there, look under the Recent Tab.
Project must be in X86 for DirectX9 apps to run. And must be done for every new DirectX project. Here's how to set it up.
- Go up in the menu to Build > Configuration Manager...
- If Configuration Manager is not shown, you only need to do this one part once ever. On the Visual Studio Tools menu, click Options, expand Projects and Solutions, and then click General. Click to check Show advanced build configurations and Click Ok. Now it should show up in the menu bar within Build. Go up in the menu to Build > Configuration Manager...
- Go where it says Platform (and NOT Active Solution Platform). Select <New...>. A new window should pop up.
- Where it says New Platform, select x86.
- Click Ok.
- Both Platform and Active Solution Platform should have changed to x86. Click Close.
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------
Visual C# 2010
-------------------------------
Setting up Project:
- Start a new project and create a Windows Forms Application.
Setting up for DirectX9:
- Go up in the menu to Project > Add Reference...
- Next goto .NET tab.
- Scroll down to Microsoft.DirectX and click it.
- Hold control and also add Microsoft.DirectX.Direct3D. You are welcome to adding more DirectX references if you choose.
- Click Ok.
Note: If any of the DirectX stuff isn't located in your .NET tab, you may need to manually add it using your Browse tab under (your harddrive letter):\Windows\Microsoft.NET\DirectX For Managed Code\1.0.2902.0 and add your necessary .dll files such as Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll, etc. For any other new projects afterwards, if it's still not there, look under the Recent Tab.
Project must be in X86 for DirectX9 apps to run. And thankfully it's x86 by default. However the .Net Framework is 4.0 and needs changed to 3.5. Here's how to set it up:
- Go towards the right of the screen where it says Solution Explorer.
- Right click your project name and goto Properties.
- On the left side, select Application if it's not there already.
- Where it says Target Framework, select .NET Framework 3.5. Be sure to save your project prior to this or you will receive an error.
- You are now ready to code with DirectX
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
.....................CONTINUED NEXT POST
Last edited by Jacob Roman; Jan 28th, 2012 at 11:11 PM.
--------------------------------
Visual C++ 2008
--------------------------------
Setting up Project:
- Start a new project.
- Goto General and select Empty Project.
- Choose the name of your project.
- Choose the Location of your project.
- Click Ok
- Goto Source Files and right click it.
- Click Add New Item...
- Click C++ File(.cpp) and name it whatever you want.
- Click Ok.
Setting up for DirectX9:
For the first time of working with DirectX9, you'll only need to do this part once ever:
- Go up in the menu to Tools > Options
- Goto Projects and Solutions
- Goto VC++ Directories
- Goto the combobox where it says "Show directories for:" and clik Include files.
- If you do not see $(DXSDK_DIR)Include, click New Line and manually put it in. To avoid compiler confusion With multiple DirectX sDK's installed, remove all the other DirectX SDK file paths to the include directory by using Cut Line (Delete).
- Next goto the combobox where it says "Show directories for:" and click Library files.
- If you do not see $(DXSDK_DIR)lib\x86, click New Line and manually put it in. To avoid compiler confusion With multiple DirectX sDK's installed, remove all the other DirectX SDK file paths to the lib directory by using Cut Line (Delete).
- Click Ok.
- You no longer need to do these steps with Include and Library.
Now with every new project you will need to do this:
- On the left where your project name is within Solution Explorer, right click it and goto Properties.
- Goto Configuration Properties > Linker > Input.
- Towards the right where it says Additional Dependencies, click it to reveal a [...] and click that button.
- On top in the listbox add d3d9.lib. You are welcome to adding more dx librarys for what ever you need todo such as d3dx9.lib, dsound.lib, dplay.lib, etc.
- Click Ok.
- You are now ready to code with DirectX.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------
Visual C++ 2010
--------------------------------
Setting up Project:
- Start a new project.
- Goto General and select Empty Project.
- Choose the name of your project.
- Choose the Location of your project. Note: There's a bug that Microsoft is aware of in Visual C++ 2010 where the file path must be under 128 characters or it will not recoginze the location of your cpp file. Choose a short file path. And when your project is saved / compiled you can move it to a longer file path that you desire where you are free to edit and expand upon.
- Click Ok
- Goto Source Files and right click it.
- Click Add New Item...
- Click C++ File(.cpp) and name it whatever you want.
- Click Ok.
Setting up for DirectX9:
For the first time of working with DirectX9, you'll only need to do this part once ever:
- On the left where your project name is within Solution Explorer, right click it and goto Properties.
- Goto Configuration Properties > VC++ Directories
- Goto Include Directories and click it to reveal a [v]. Click it and goto <Edit...>.
- If you do not see $(DXSDK_DIR)Include, manually put it in and click Ok.
- Next goto Library Directories and click it to reveal a [v]. Click it and goto <Edit...>.
- If you do not see $(DXSDK_DIR)Lib\x86, manually put it in and click OK. You no longer need to do that with Include and Library.
Now with every new project you will need to do this:
- On the left where your project name is within Solution Explorer, right click it and goto Properties.
- Goto Configuration Properties and goto > Linker > Input.
- Towards the right where it says Additional Dependencies, click it to reveal a [v] and goto <Edit...>.
- On top in the listbox add d3d9.lib. You are welcome to adding more dx librarys for what ever you need todo such as d3dx9.lib, dsound.lib, dplay.lib, etc.
- You are now ready to code with DirectX.
This is a notepad that I made thats gonna be included in my massive directx tutorial I'm currently working on. Also If I were you I'd use Direct3D for 2D cause in DirectDraw there are limitations such as not being able to rotate surfaces or alphablend, etc. So you'll be limited. It's also easier to code 2D stuff using Direct3D than Directdraw. I have tons of examples if you would like to see.
Last edited by Jacob Roman; Jan 28th, 2012 at 11:13 PM.
I followed the one for vb2010 and got a lot farther than before. I was referencing the wrong files so at least now i've got the ones in "\Microsoft.NET\DirectX For Managed Code\1.0.2902.0\...". When i first tried to switch it to the 3.5 framework it said to save my project first. I saved it and then tried to switch it again. You can see the screenshot of what it said.
Note: BE SURE YOU INSTALLED THE LATEST VERSION OF THE DIRECTX SDK!
I'll try to get that as soon as i can and see if it fixes this problem.
This is a notepad that I made thats gonna be included in my massive directx tutorial I'm currently working on. Also If I were you I'd use Direct3D for 2D cause in DirectDraw there are limitations such as not being able to rotate surfaces or alphablend, etc. So you'll be limited. It's also easier to code 2D stuff using Direct3D than Directdraw. I have tons of examples if you would like to see.
Ok, i would have thought that directdraw could do those things but i guess d3d is the way to go. I'd love to see your examples! I'm checking you website quite frequently to see if it's up yet.
Here's a texture mapping example I made which works in VB.Net 2008/2010:
vb.net Code:
Option Explicit On
Option Strict On
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class frmMain
Private Device As Device
Private Display_Mode As DisplayMode
Private Screen As PresentParameters = New PresentParameters
Private Fullscreen_Enabled As Boolean
Private Running As Boolean = True
Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {}
Private Texture As Texture
Private Sub DirectX_Initialize()
If Fullscreen_Enabled = True Then
Display_Mode.Width = 800
Display_Mode.Height = 600
Display_Mode.Format = Format.R5G6B5
Screen.Windowed = False
Screen.BackBufferCount = 1
Screen.BackBufferWidth = Display_Mode.Width
Screen.BackBufferHeight = Display_Mode.Height
Else
Screen.Windowed = True
End If
Screen.SwapEffect = SwapEffect.Copy
Screen.BackBufferFormat = Display_Mode.Format
Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
End Sub
Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
Dim Vertex As CustomVertex.TransformedColoredTextured = New CustomVertex.TransformedColoredTextured
Set Device = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Screen)
End Sub
Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal RHW As Single, ByVal Color As Long, ByVal TU As Single, ByVal TV As Single) As CUSTOM_VERTEX
Create_Custom_Vertex.X = X
Create_Custom_Vertex.Y = Y
Create_Custom_Vertex.Z = Z
Create_Custom_Vertex.RHW = RHW
Create_Custom_Vertex.Color = Color
Create_Custom_Vertex.TU = TU
Create_Custom_Vertex.TV = TV
End Function
Private Sub Load_Texture(ByRef Texture As Direct3DTexture8, ByRef File_Path As String, ByVal Transparency_Color As Long)
The code looks really good! I put it into a test program and had some issues. First of all, i can't run it, same problem as before. I got a "File Load Exception was unhandled" error message when i ran it which said:
"Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."
I'm guessing that this is because the project isn't switched to the 3.5 framework. Do i even get that with the original install or do i need to download it? I can try that next. I got the latest directx sdk from microsoft and installed it.
Just a problem (or at least i think so) with the code. I had an error in the Load_Texture sub. TextureLoader is not declared.
You also have to reference Microsoft.DirectX.Direct3DX. Sorry that I forgot to mention it. Direct3DX is used for anything texture mapping related. Try it and TextureLoader along with everything else should work. Also I been using the Express edition of 2010 and 2008 and both come with the frameworks and both work fine.
[EDIT]
Also if you read the notepad for VB.Net 2010 you needed to do this to change the framework to 3.5 in your current project:
Code:
Project must be in X86 for DirectX9 apps to run. And thankfully it's x86 by default. However the .Net Framework is 4.0 and needs changed to 3.5. Here's how to set it up:
- Go towards the right of the screen where it says Solution Explorer.
- Right click your project name and goto Properties.
- On the left side, select Compile.
- Click on the button Advanced Compile Options... A new window should pop up.
- On the bottom where it says Target Framework, select .NET Framework 3.5
- Click Ok.
- You are now ready to code with DirectX
Last edited by Jacob Roman; Jan 30th, 2012 at 09:31 AM.
Wahoo!!! I just ran the example! I'm still having a problem switching to the 3.5 framework so i "cheated". I opened my project file in notepad and changed the line
I opened the project and it said that the target framework was 3.5. I was afraid the change was only on the surface but when i ran it, it worked.
On a matter of criticism on your code: I first ran it in windowed mode which is much easier for debugging. I made a change in the code so that the resize event now looks like this because before it would fire when the size is set in the Main sub.
Code:
Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Fullscreen_Enabled = False And Device IsNot Nothing Then
...
End If
End Sub
Other errors are:
An error when i resize the form
An error when i move the form off of the screen and then back on.
Besides the problems i put a Texture.jpg in the correct folder and right now have my first basic dx9 program running.
Edit:
You also have to reference Microsoft.DirectX.Direct3DX.
Right, i referenced it and the TextureLoader problem went away.
Last edited by cheesebrother; Jan 31st, 2012 at 09:46 AM.
The resize code I had was necessary cause if you were to stretch the window with no code in the Resize event the program would lock up and you would be forced to hit the stop button in IDE. Its the same in C#. I don't know why it was like that. VB6 and C++ you didn't have to cause you can stretch the window with no problem. So if I were you I'd keep it the way it was. Try not to change the code I had in resize or there will be errors like you mentioned. Also I find it weird that even with the steps I gave you, you still couldn't change the framework. Visual Basic.Net 2010 has all sorts of problems. Like the random crashing when trying to save. But thats not the only language with that problem. Visual C++.Net 2010 has issues to when creating a project into a directory thats over 128 characters. The C++ program you made when trying to run gives you errors that it cant find certain files in the directory. I have a feeling all the 2010 languages have issues. It's best to downgrade to 2008 until something better comes out. You don't really need 2010 unless you absolutely need it.
Last edited by Jacob Roman; Jan 31st, 2012 at 10:18 AM.
So do you have suggestions for fixing the errors that i mentioned? Also, would it be possible to share code for drawing opaque images (like .png) and how to alphablend images? That would be really super.
An error when i move the form off of the screen and then back on
Here's a solution to the Alt+Tab issue. I have it in all languages btw. When you alt tab out of a regular directx program without the alt tab solution and try to reenter in regardless of what language it was written in, it crashes the program. This solves it:
vb.net Code:
Option Explicit On
Option Strict On
Imports System.Threading
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class frmMain
Private Device As Device
Private Display_Mode As DisplayMode
Private Screen As PresentParameters = New PresentParameters
Private Running As Boolean = True
Private Vertex_List As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(3) {}
Private Sub DirectX_Initialize()
Display_Mode.Width = 800
Display_Mode.Height = 600
Display_Mode.Format = Format.R5G6B5
Screen.Windowed = False
Screen.BackBufferCount = 1
Screen.BackBufferWidth = Display_Mode.Width
Screen.BackBufferHeight = Display_Mode.Height
Screen.SwapEffect = SwapEffect.Copy
Screen.BackBufferFormat = Display_Mode.Format
Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
'Not needed but used in this example to put these back when reseting the device after entering back into the program
Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal RHW As Single, ByVal Color As Integer) As CustomVertex.TransformedColored
Dim Vertex As CustomVertex.TransformedColored = New CustomVertex.TransformedColored
Here's code to produce transparency so the background is removed from the sprite. Also the alpha values of the vertices can now be changed to where it can fade away or produce ghostlike results at any alpha you choose.
vb.net Code:
Option Explicit On
Option Strict On
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class frmMain
Private Device As Device
Private Display_Mode As DisplayMode
Private Screen As PresentParameters = New PresentParameters
Private Fullscreen_Enabled As Boolean
Private Running As Boolean = True
Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {} 'create an array of vertices
Private Texture As Texture
Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
Dim Vertex As CustomVertex.TransformedColoredTextured
Vertex.Position = New Vector4(X, Y, Z, 1)
Vertex.Color = Color
Vertex.Tu = TU
Vertex.Tv = TV
Return Vertex
End Function
Private Sub DirectX_Initialize()
If Fullscreen_Enabled = True Then
Display_Mode.Width = 800
Display_Mode.Height = 600
Display_Mode.Format = Format.R5G6B5
Screen.Windowed = False
Screen.BackBufferCount = 1
Screen.BackBufferWidth = Display_Mode.Width
Screen.BackBufferHeight = Display_Mode.Height
Else
Screen.Windowed = True
End If
Screen.SwapEffect = SwapEffect.Copy
Screen.BackBufferFormat = Display_Mode.Format
Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
Hmm, i tried that and it didn't really work. I drew a .png and it displayed alright on the black background which you've set it to clear to. Then i changed the clear color to white so that i could see the shadow of my image. Now it wasn't drawing anything. I changed it to various colors and each time the image was drawn semi transparent on the background color. It's like the image was being mixed with the background color. I also edited the Create_Polygon sub to try out vertex transparency like this.
Blast! You're probably right. I got the latest version of what i though was the sdk, it was "DirectX End-User Runtimes (June 2010) Full Download." I'll get the one called "June 2010 DirectX SDK", try it and see if it fixes these problems. This is the link where i've gotten it from: Webpage. I've only got the dx 8.1 sdk installed so there shouldn't be a problem there.
Actually i'm just seeing that the real sdk is 571.1 mb so i've definitely got the wrong thing.
You are better off getting all of em as the June 2010 SDK has no samples in VB.Net. Just C++ and C#. What I have shown are the latest versions for DirectX 8, 9, 10, and 11. Also try this instead so you see it partially fade. Having 0 would make it not appear at all cause the alpha's 0 and you would only see half the image:
You are better off getting all of em as the June 2010 SDK has no samples in VB.Net. Just C++ and C#. What I have shown are the latest versions for DirectX 8, 9, 10, and 11.
Ok, you're right. I'd rather have the examples for vb.net. I'm using XP so getting the sdks for 10 and 11 would be useless. So if i were to get the dx9 sdk that would be enough to run your example, right?
Well, I installed the October 06 sdk and so far the example doesn't run any differently. Do i need to reference different files? Right now the ones that i am referencing are in "C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0". I ran the sdk installer and i think that that's all that is needed for it to work but, as I said, there doesn’t seem to be any change except for a bunch of new things in my start menu. Also, I was looking at the documentation and found that all the examples are in C#, can this be changed?
I noticed that the latest SDK for DX 9 didn't have VB.Net examples either. Thats strange. As if Microsoft is trying to stay away from VB. I use to have an earlier sdk that did have em. But don't remember which one. Perhaps a google search would help. And you did claim that it did work until you set the background to white, in turn it drew nothing. So I'll do the same in this code example I'm about to show. I changed the color scheme from Color.Black to System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb to use as white so try that. I also added some extra code in resize cause when you reset the device, it removes all the alpha / color texture info. You have to have that reinitialized or otherwise after stretching the window, the sprite is no longer transparent. I tested this exact code and it works:
vb.net Code:
Option Explicit On
Option Strict On
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class frmMain
Private Device As Device
Private Display_Mode As DisplayMode
Private Screen As PresentParameters = New PresentParameters
Private Fullscreen_Enabled As Boolean
Private Running As Boolean = True
Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {} 'create an array of vertices
Private Texture As Texture
Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
Dim Vertex As CustomVertex.TransformedColoredTextured
Vertex.Position = New Vector4(X, Y, Z, 1)
Vertex.Color = Color
Vertex.Tu = TU
Vertex.Tv = TV
Return Vertex
End Function
Private Sub DirectX_Initialize()
If Fullscreen_Enabled = True Then
Display_Mode.Width = 800
Display_Mode.Height = 600
Display_Mode.Format = Format.R5G6B5
Screen.Windowed = False
Screen.BackBufferCount = 1
Screen.BackBufferWidth = Display_Mode.Width
Screen.BackBufferHeight = Display_Mode.Height
Else
Screen.Windowed = True
End If
Screen.SwapEffect = SwapEffect.Copy
Screen.BackBufferFormat = Display_Mode.Format
Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
And you did claim that it did work until you set the background to white, in turn it drew nothing.
Well actually i just tested the code you just posted on black with another .png image and it was a bit of a mess. You can see what the original looks like and what it looked like when drawn in directx (the orig is on the right).
Right now a jpg will draw perfectly but this .png will not. Making a vertice with a transparent alpha value will not draw properly in any case.
Okay. That's the message i just typed out 20 minutes ago. Now i would like to apologize to you for being a royal pain. I just did what i should have done a while ago. I tested your example on another pc. It worked. Drawing the ring properly worked and changing vertex alpha values worked. I'm not quite sure how to fix it on mine but at least i know that it's something with my hardware or more probably software that is the problem. Hopefully the latest drivers for my gc will be enough to fix it.
Edit: I found what isn't happening on my computer. When i rem this out on the computer which works:
It looks exactly the same as it does on mine(like in the picture below on the left). I've never had a problem running games with my gc so maybe there's still something we can do in vb to fix it.
Last edited by cheesebrother; Feb 5th, 2012 at 09:55 AM.
An interesting thing which i found was that when i change the devicetype of the device it works on my pc
Code:
Device = New Device(0, DeviceType.Reference, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
Alphablending works perfectly just like on the pc which works. The big problem with this is that it absolutely kills the render speed so it was an exciting but shallow discovery.
I got the latest drivers for my graphics card and that didn't work. I've got an nvidia 9600 gt so it doesn't seem like there would be a lack of capability on the part of that.
Only one thing, it doesn't work for changing alpha values on vertices. This is enough for most things though so i'm quite happy with it now. Thanks a lot for the examples and help.