和我一起入门Direct3D的VB.net编程
2024-07-10 13:00:52
供稿:网友
注册会员,创建你的web开发资料库,我是个vb程序员,一直在做数据库应用程序的开发,做的时间长了就感觉很烦闷,很想换换口味,但苦于没有学习时间和资料,恰巧看到csdn上他人写的学习经验,我也就很快的入了门。好东西不敢独享,随着我学习的同时,把原来的c#程序改成了vb.net的代码,但思路还是一样的,仅供大家参考。
(感谢原文作者。原文:http://blog.csdn.net/ygrx/archive/2005/03/02/307781.aspx?pending=true)
imports microsoft.directx
imports microsoft.directx.direct3d
public class form1
inherits system.windows.forms.form
#region " windows 窗体设计器生成的代码 "
public sub new()
mybase.new()
'该调用是 windows 窗体设计器所必需的。
initializecomponent()
'在 initializecomponent() 调用之后添加任何初始化
me.setstyle(controlstyles.allpaintinginwmpaint or controlstyles.opaque, true)
end sub
'窗体重写 dispose 以清理组件列表。
protected overloads overrides sub dispose(byval disposing as boolean)
if disposing then
if not (components is nothing) then
components.dispose()
end if
end if
mybase.dispose(disposing)
end sub
'windows 窗体设计器所必需的
private components as system.componentmodel.icontainer
'注意: 以下过程是 windows 窗体设计器所必需的
'可以使用 windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()
'
'form1
'
me.autoscalebasesize = new system.drawing.size(6, 14)
me.clientsize = new system.drawing.size(292, 266)
me.name = "form1"
me.text = "form1"
end sub
#end region
阿游 发表于 2005-03-22 2:49 pm
private device as device
public sub initializegraphics()
'设置参数
dim presentparams as presentparameters = new presentparameters
presentparams.windowed = true '窗口模式
presentparams.swapeffect = swapeffect.discard '交换
'创建设备
device = new device(0, devicetype.hardware, me, createflags.softwarevertexprocessing, presentparams)
end sub
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
initializegraphics()
end sub
protected overrides sub onpaint(byval e as system.windows.forms.painteventargs)
device.clear(clearflags.target, system.drawing.color.cadetblue, 1.0f, 0)
dim verts(2) as customvertex.transformedcolored
verts(0).position = new vector4(me.width / 2.0f, 50.0f, 0.5f, 1.0f)
verts(0).color = system.drawing.color.aqua.toargb()
verts(1).position = new vector4(me.width - me.width / 5.0f, me.height - me.height / 5.0f, 0.5f, 1.0f)
verts(1).color = system.drawing.color.black.toargb()
verts(2).position = new vector4(me.width / 5.0f, me.height - me.height / 5.0f, 0.5f, 1.0f)
verts(2).color = system.drawing.color.purple.toargb()
device.beginscene()
device.vertexformat = customvertex.transformedcolored.format
device.drawuserprimitives(primitivetype.trianglelist, 1, verts)
device.endscene()
device.present()
me.invalidate()
end sub
end class