Imports DX = SlimDX.Direct3D9
Imports System
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports SlimDX
Imports SlimDX.Direct3D9
#Region "Structs"
<StructLayout(LayoutKind.Sequential)> Public Structure Vector2DColoredTextured
Public PositionRhw As Vector4
Public Color As Integer
Public UV As Vector2
Public Shared ReadOnly Property SizeBytes() As Integer
Get
Return System.Runtime.InteropServices.Marshal.SizeOf(GetType(Vector2DColoredTextured))
End Get
End Property
Public Shared ReadOnly Property Format() As Direct3D9.VertexFormat
Get
Return (Direct3D9.VertexFormat.PositionRhw Or Direct3D9.VertexFormat.Diffuse Or Direct3D9.VertexFormat.Texture1)
End Get
End Property
Public Sub New(ByVal X As Single, ByVal Y As Single, ByVal VectorColor As Color, ByVal U As Single, ByVal V As Single)
Me.New(X, Y, VectorColor.ToArgb(), U, V)
End Sub
Public Sub New(ByVal X As Single, ByVal Y As Single, ByVal VectorColor As Integer, ByVal U As Single, ByVal V As Single)
Me.PositionRhw = New Vector4(X, Y, 1.0F, 1.0F)
Me.UV = New Vector2(U, V)
Me.Color = VectorColor
End Sub
End Structure
#End Region
<System.ComponentModel.DesignerCategory("")> Public Class clsDX9
Inherits System.Windows.Forms.Form
Private _device As DX.Device = Nothing
Private _parameters As DX.PresentParameters = New DX.PresentParameters
Private D3D As DX.Direct3D = New DX.Direct3D
Private Box As Vector2DColoredTextured() = New Vector2DColoredTextured(4) {}
Private _texture As Texture
Private bufVertexes
Public Sub Main()
With _parameters
.EnableAutoDepthStencil = False
.BackBufferCount = 1
.BackBufferHeight = 600
.BackBufferWidth = 800
.PresentationInterval = DX.PresentInterval.Immediate
.SwapEffect = DX.SwapEffect.Discard
.DeviceWindowHandle = Me.Handle
.Windowed = True
End With
Box(0) = New Vector2DColoredTextured(0, 0, ARGB(255, 255, 255, 255), 0, 0)
Box(1) = New Vector2DColoredTextured(0, 800, ARGB(255, 255, 255, 255), 0, 1)
Box(2) = New Vector2DColoredTextured(600, 0, ARGB(255, 255, 255, 255), 1, 0)
Box(3) = New Vector2DColoredTextured(600, 800, ARGB(255, 255, 255, 255), 1, 1)
_device = New DX.Device(D3D, 0, SlimDX.Direct3D9.DeviceType.Hardware, Me.Handle, SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, _parameters)
_texture = New Texture(_device, 800, 600, 0, Usage.None, Format.A8R8G8B8, Pool.Managed)
_device.SetRenderState(RenderState.ZEnable, True)
_device.SetRenderState(RenderState.Lighting, False)
Me.Show()
End Sub
Public Sub Render()
_device.Clear(SlimDX.Direct3D9.ClearFlags.Target, Drawing.Color.CornflowerBlue, 0, 0)
_device.BeginScene()
_device.VertexFormat = Vector2DColoredTextured.Format
_device.SetTexture(0, _texture)
_device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Box)
_device.EndScene()
_device.Present()
End Sub
Public Function ARGB(ByVal A As Byte, ByVal R As Byte, ByVal G As Byte, ByVal B As Byte) As Integer
ARGB = System.Drawing.Color.FromArgb(A, R, G, B).ToArgb
End Function
End Class
[Edited by - rp11lz on June 1, 2009 1:37:06 AM]
[SlimDX] Primitives not Rendering
I'm just not sure at this point why this isn't at least rendering a white square. (It doesn't render anything if I create a texture from file either). It only clears the screen to CornflowerBlue.
EDIT: Note, I do have my program calling render in a loop.
Two thoughts. First, you're telling Direct3D not to create a depth buffer, and then you try to enable said non-existent depth buffer. I'd probably try to make up my mind about that one.
Second, try disabling culling. If your geometry shows up after that, you've got the vertex winding backwards.
Second, try disabling culling. If your geometry shows up after that, you've got the vertex winding backwards.
I'll try disabling culling, although I'm not sure that will help.
I tested with a much simpler vertex format, which rendered just fine.
So now I'm wondering if something is wrong with the other structure I have defined.
I tested with a much simpler vertex format, which rendered just fine.
<StructLayout(LayoutKind.Sequential)> _Structure VertexType Public PositionRhw As Vector4 Public Color As IntegerEnd Structure
So now I'm wondering if something is wrong with the other structure I have defined.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement