|
|
楼主 |
发表于 2015-4-24 00:28:11
|
显示全部楼层
2015-4-24 00:12:31
我真是日了doge了!
没用!没用!
怎么改都不行!
'初始化DX9设备
Public Sub InitDXBasic(ByRef frm As Form, w As Int16, h As Int16)
Randomize()
Dim presentParams As PresentParameters = New PresentParameters
presentParams.Windowed = True '窗口模式
presentParams.SwapEffect = SwapEffect.Discard '交换
presentParams.BackBufferWidth = w
presentParams.BackBufferHeight = h
'presentParams.MultiSample = MultiSampleType.None '多重采样=0
presentParams.EnableAutoDepthStencil = True
presentParams.AutoDepthStencilFormat = DepthFormat.D16 '16位位深
device = New Device(0, DeviceType.Hardware, frm, CreateFlags.SoftwareVertexProcessing, presentParams)
device.VertexFormat = CustomVertex.TransformedColored.Format
m_Sprite = New Sprite(device)
'为了能响应键盘事件,该属性必须设为true
frm.KeyPreview = True
'创建D字体对象,显示字符用,这两句不能放在场景中,否则会很慢
Dim winFont As New System.Drawing.Font("Arial", 9, FontStyle.Regular)
d3dfont = New Microsoft.DirectX.Direct3D.Font(device, winFont)
End Sub
测试用的过程:
Public Sub Test()
Dim v(5) As CustomVertex.TransformedColored
v(0) = CCV3(100, 100, 0.5, Color.Green)
v(1) = CCV3(200, 300, 0.5, Color.White)
v(2) = CCV3(0 + 400, 100 + 300, 0, Color.White)
v(3) = CCV3(0 + 400, -100 + 300, 0, Color.White)
v(4) = CCV3(100 + 400, 0 + 300, 0, Color.White)
v(5) = CCV3(-100 + 400, 0 + 300, 0, Color.White)
device.DrawUserPrimitives(PrimitiveType.LineList, 5, v)
End Sub Private Function CCV3(x As Single, y As Single, z As Single, c As Color) As CustomVertex.TransformedColored
CCV3.Position = New Vector4(x, y, z, 1.0F)
CCV3.Color = c.ToArgb
End Function 这个Test的结果是第一条线(z设成0.5的那条)画不出来,第二条线和第三条线正常画出来。
我怀疑是我devicebegin那部分有错,也贴出来。
'准备设备绘制
Public Sub BeginDevice()
device.BeginScene()
device.SetRenderState(RenderStates.ZEnable, True) '这边设置开启了深度检测
device.SetRenderState(RenderStates.ZBufferWriteEnable, True) '这里和下边一行是按着教程来的
device.SetRenderState(RenderStates.ZBufferFunction, 4) '教程说这里应该是2或者4,我这边2是黑屏,用的4
device.SetRenderState(RenderStates.CullMode, Cull.None)
device.SetRenderState(RenderStates.Lighting, True)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.AlphaTestEnable, False)
End Sub 以上应该就已经能说明问题了吧……求问到底错在那里了?怎么这z不是0就画不出东西来?
顺便说一句:
CCV3.Position = New Vector4(x, y, z, 1.0F)这句里边那个1.0F是指rhw,这个值我试了0.0f和1.0f都是z=0时能画出来,z=1时画不出来。

真是日了狗了……
再附,sprite的绘图过程我这么写的:
m_Sprite.Begin(SpriteFlags.AlphaBlend + SpriteFlags.SortDepthFrontToBack)
Public Sub DrawGraphR(x As Integer, y As Integer)
'分格图像绘制
Dim trans As Vector2 = New Vector2(x, y) 这个应该是指平移
Dim mat As Matrix
mat = Matrix.Transformation2D(Pcenter, 0, scale, Pcenter, rotation, trans) 矩阵的变换吧,我不懂,你们看吧
m_Sprite.Transform = mat 把变换好的矩阵放到sprite里
m_Sprite.Draw(m_Tex, New Rectangle(ix * cellW, iy * cellH, cellW, cellH), Nothing, Nothing, drColor) 在指定的rect里边画,那俩nothing是Center和Position,Center就是{0,0,0},Position我试过{0,0,z},z不是0也是画不出来的。

我就不懂了,这Z轴跟我什么仇什么怨?
求大神!
以上!
|
|