Jump to content
  • Advertisement
Sign in to follow this  
chosendl

Help, a worm ate my triangle!

This topic is 4162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I am new to doing d3d in vb.net and i have a problem i cant get around. I render a triangle with shading and lighting, no texture, and it looks like it was eaten by an army of caterpillars! There are bits and pieces missing every where. Changing my stencildepthformat, makes a difference, but not much. None of the formats work 100%. My gfx card is a 6600gt agp my dx is 9c. Heres my code, if you copy and paste it, maybe you can run it and see if it is the code that is the problem? ----------------------------------------- Imports Microsoft.directx Imports Microsoft.directx.Direct3D Public Class Form1 Inherits System.Windows.Forms.Form Dim Device As Microsoft.DirectX.Direct3D.Device Dim Disp As DisplayMode = Microsoft.DirectX.Direct3D.Manager.Adapters(0).CurrentDisplayMode Dim mcaps = Manager.GetDeviceCaps(0, DeviceType.Hardware) #Region " Windows Form Designer generated code " #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load InitializeGraphics() Me.Show() Dim myvertb = New Direct3D.VertexBuffer(GetType(CustomVertex.PositionNormal), 3, Device, Usage.WriteOnly, CustomVertex.PositionNormal.Format, Pool.Managed) Device.Transform.World = Matrix.Identity Device.Transform.View = Matrix.Identity Device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 3.0, 1.0, 1, 100) Device.RenderState.CullMode = Cull.None Device.RenderState.ZBufferEnable = True Dim mtrl As Direct3D.Material = New Direct3D.Material() mtrl.Ambient = System.Drawing.Color.FromArgb(0, 250, 250, 250) mtrl.Diffuse = System.Drawing.Color.Cyan Device.Material = mtrl Device.RenderState.Lighting = True Device.Lights(0).Type = LightType.Directional Device.Lights(0).Diffuse = System.Drawing.Color.White Device.Lights(0).Direction = New Vector3(1, 1, 1) Device.Lights(0).Update() Device.Lights(0).Enabled = True Device.RenderState.Ambient = System.Drawing.Color.FromArgb(0, 150, 20, 10) Device.RenderState.ZBufferEnable = True Dim verts(3) As CustomVertex.PositionNormal verts(0) = New CustomVertex.PositionNormal() verts(0).X = -3 verts(0).Y = 0 verts(0).Z = 10 verts(0).Normal = New Vector3(-10, 0, -10) 'verts(0).Color = System.Drawing.Color.Yellow.ToArgb() verts(1) = New CustomVertex.PositionNormal() verts(1).X = 0 verts(1).Y = 3 verts(1).Z = 10 verts(1).Normal = New Vector3(0, 10, -10) 'verts(1).Color = System.Drawing.Color.Yellow.ToArgb() verts(2) = New CustomVertex.PositionNormal() verts(2).X = 3 verts(2).Y = -3 verts(2).Z = 10 verts(2).Normal = New Vector3(10, -10, -10) 'verts(2).Color = System.Drawing.Color.Yellow.ToArgb() myvertb.setdata(verts, 0, Direct3D.LockFlags.None) Device.Clear(ClearFlags.Target, Color.Blue, 1, 0) Device.BeginScene() Device.SetStreamSource(0, myvertb, 0) Device.VertexFormat = CustomVertex.PositionNormal.Format Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1) Device.RenderState.ShadeMode = ShadeMode.Gouraud Device.EndScene() Device.Present() Application.DoEvents() End Sub Private Function InitializeGraphics() As Boolean Dim PParams As PresentParameters = New PresentParameters() PParams.Windowed = True PParams.SwapEffect = SwapEffect.Discard PParams.AutoDepthStencilFormat = DepthFormat.D24S8 PParams.EnableAutoDepthStencil = True PParams.PresentFlag = PresentFlag.None Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, PParams) End Function End Class --------------------------------- Anyone got any ideas to what the problem is or solution? Thanx in advance!

Share this post


Link to post
Share on other sites
Advertisement
You're not clearing the Z-buffer before drawing it. You'll need to clear it along with the framebuffer by adding the Z-buffer flag to the clear call.

Hope this helps.

Share this post


Link to post
Share on other sites
Thanx a million sirob, but another stupid question, if i want to specify bothe the zbuffer and target flags, for the clear method, how do i do it.
In C++ I would of just done this (zbuffer | target,..... But that does not seem to work in vb.net!

Share this post


Link to post
Share on other sites
Just a suggestion but if you have some experience in c++ you might find using c# a bit easier then VB, has the same functionality but more c like syntax.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!