ludaxel
Messages postés
2
Date d'inscription
vendredi 12 septembre 2003
Statut
Membre
Dernière intervention
3 décembre 2004
3 déc. 2004 à 18:44
ludo
Salut vr3h,
merci pour ta reponse, entre temps j'ai fait un petit tour sur directx4vb et j'y est trouvé un tuto concernant dx9. J'en ai tiré que ce qui m'interessé, Voici le bout de code au cas ou ca interresserai qq :
' [Variables DirectX]
Private D3D As Manager
Public D3DDevice As Device
Private D3DHelp As D3DX
Private D3DCaps As Caps
Private DevCreate As Integer
Private D3DP As New PresentParameters
Dim Owner As System.Windows.Forms.PictureBox=me.picturebox1
Private D3DTexture As Texture
Private D3DVertex As VertexBuffer
' initialisation et chargement de la texture :
Private Sub InitDX()
' Parametres D3D
D3DP.Windowed = True
D3DP.SwapEffect = SwapEffect.Discard
D3DP.BackBufferCount = 1
D3DP.BackBufferFormat = D3D.Adapters(0).CurrentDisplayMode.Format
D3DP.BackBufferWidth = Me.Width
D3DP.BackBufferHeight = Me.Height
D3DP.PresentationInterval = PresentInterval.One
' initialisation de directX
'1. check for, and specify, depth buffer
If D3D.CheckDepthStencilMatch(0, DeviceType.Hardware, _
D3DP.BackBufferFormat, _
D3DP.BackBufferFormat, _
DepthFormat.D16) Then
'support exists.
D3DP.AutoDepthStencilFormat = DepthFormat.D16
D3DP.EnableAutoDepthStencil = True
End If
D3DCaps = D3D.GetDeviceCaps(0, DeviceType.Hardware)
'allow this engine to take advantage of hw tnl where available
If D3DCaps.DeviceCaps.SupportsHardwareTransformAndLight Then
DevCreate = CreateFlags.HardwareVertexProcessing Or CreateFlags.MultiThreaded
Else
DevCreate = CreateFlags.SoftwareVertexProcessing Or CreateFlags.MultiThreaded
End If
'3. attempt to create the device interface.
D3DDevice = New Device(0, DeviceType.Hardware, Me, DevCreate, D3DP)
'allow texture transparencies
D3DDevice.RenderState.SourceBlend = Blend.SourceAlpha
D3DDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha
'set up texture blending
D3DDevice.SamplerState(0).MinFilter = TextureFilter.Linear
D3DDevice.SamplerState(0).MagFilter = TextureFilter.Linear
D3DVertex = New VertexBuffer(GetType(CustomVertex.TransformedTextured), _
4, D3DDevice, 0, CustomVertex.TransformedTextured.Format, _
Pool.Default)
Dim v As CustomVertex.TransformedTextured() = CType(D3DVertex.Lock(0, 0), _
CustomVertex.TransformedTextured())
Const iMBWidth As Integer = 128
Const iMBHeight As Integer = 128
'use the constructors to fill the data.
'laid out such that first line = coordinate (x,y,z,rhw)
'and second line = texcoord (u,v)
v(0) = New CustomVertex.TransformedTextured(0, 0, 0, 1, _
0, 2 / 128)
v(1) = New CustomVertex.TransformedTextured(iMBWidth, 0, 0, 1, _
iMBWidth / 128, 2 / 128)
v(2) = New CustomVertex.TransformedTextured(0, 0 + iMBHeight, 0, 1, _
0, iMBHeight / 128)
v(3) = New CustomVertex.TransformedTextured(iMBWidth, 0 + iMBHeight, 0, 1, _
iMBWidth / 128, iMBHeight / 128)
D3DVertex.Unlock()
D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _
Drawing.Color.FromArgb(0, 0, 0, 0), 1.0F, 0)
'chargement de la texture
D3DTexture = TextureLoader.FromFile(D3DDevice, _
DDSFile, _
128, 128, 1, 0, _
Format.A8R8G8B8, Pool.Managed, _
Filter.None, Filter.None, _
Drawing.Color.Magenta.ToArgb())
'rendu de la texture
D3DDevice.BeginScene()
D3DDevice.RenderState.AlphaBlendEnable = True
D3DDevice.SetStreamSource(0, D3DVertex, 0)
D3DDevice.VertexFormat = CustomVertex.TransformedTextured.Format
D3DDevice.SetTexture(0, D3DTexture)
D3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
D3DDevice.RenderState.AlphaBlendEnable = False
D3DDevice.EndScene()
D3DDevice.Present()
et pour sauvegarder la texture en bmp,jpg,png ou vos bmp, jpg, png en dds:
textureloader.save (fichier,format,texture chargée)
@+ ludo