Static background in a render...

afwasborstel
10-26-2006, 02:04 PM
How can i make a static background in a render? I need a grid on wich directx can draw it's stuff...

Iceplug
10-27-2006, 03:17 PM
A static background?
Load up a texture and set up a vertex buffer that will hold TransformedColoredTextured vertices. In the vertex buffer vertices, specify the size of the visible area of your form as the high values for the vertices.

When you draw the vertices, make sure that you apply the texture and set the ZBufferWriteEnable to fallse. :)

afwasborstel
10-27-2006, 04:19 PM
Ok...got it so far...but it doesn't show in the render...



Private textureBackground As Direct3D.Texture = Nothing
Private vertexBackground As Direct3D.VertexBuffer = Nothing


Public Sub Create(ByVal device As Direct3D.Device, ByVal texture As String, ByVal position As DirectX.Vector3)

vertexBackground = New Direct3D.VertexBuffer(GetType(Direct3D.CustomVertex.TransformedColored Textured), 4, device, Direct3D.Usage.WriteOnly, Direct3D.CustomVertex.TransformedColoredTextured.Format, Direct3D.Pool.Default)

textureBackground = Direct3D.TextureLoader.FromFile(device, texture)

Dim v(3) As Direct3D.CustomVertex.TransformedColoredTextured

Dim i As Integer
For i = 0 To 3
v(i).Position = (New DirectX.Vector4(position.X, position.Y, position.Z, 1.0F))
v(i).Color = 255
Next
v(0).Y = CType(device.PresentationParameters.BackBufferHeight, Single)
v(2).Y = CType(device.PresentationParameters.BackBufferHeight, Single)
v(2).X = CType(device.PresentationParameters.BackBufferWidth, Single)
v(3).X = CType(device.PresentationParameters.BackBufferWidth, Single)
v(0).Tu = 0.0F : v(0).Tv = 1.0F
v(1).Tu = 0.0F : v(1).Tv = 0.0F
v(2).Tu = 1.0F : v(2).Tv = 1.0F
v(3).Tu = 1.0F : v(3).Tv = 0.0F

End Sub


Wich is called by: Create(device, "c:\back.bmp", New DirectX.Vector3(0, 0, 1))


And in the render...


Public Sub RenderBackground(ByVal device As Direct3D.Device)
' Render the background
device.SetTexture(0, textureBackground)

device.VertexFormat = Direct3D.CustomVertex.TransformedColoredTextured.Format
device.SetStreamSource(0, vertexBackground, 0)
device.DrawPrimitives(Direct3D.PrimitiveType.TriangleStrip, 0, 2)
End Sub


Any ideas?

Iceplug
10-28-2006, 04:36 AM
Ensure that you've set the RenderState ZBufferWriteEnable to False.
Also, make sure that you have RenderBackground between BeginScene and EndScene, the scene has been cleared, and you don't have culling enabled.

afwasborstel
10-28-2006, 04:50 AM
No luck yet...

This is the render sub I use...



Private Sub Render()
If Me.device Is Nothing Then
Return
End If

Me.device.Clear(Direct3D.ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0F, 0)
Me.device.RenderState.CullMode = Direct3D.Cull.None
Me.device.BeginScene()

device.RenderState.ZBufferWriteEnable = False
RenderBackground(device)

device.RenderState.ZBufferWriteEnable = True
Renderotherthingys(device)

Me.device.EndScene()
Me.device.Present()

End Sub


What I'm doing wrong here?

Iceplug
10-29-2006, 03:18 AM
Wait a minute, are you actually locking and unlocking the vertex buffer so that you can put the vertices in there? It doesn't look like you are.

afwasborstel
10-29-2006, 02:12 PM
Did all that...no luck sofar...attached a sample of the project....maybe if any one could take a look....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum