Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About gunhawk

  • Rank
  1. I just cannot figure this out still and need help. I have algorithms that generate my vertex and index buffers, and the finished buffers look great drawn using device.DrawIndexedPrimitives. But the second I try to use the EXACT SAME buffers in a mesh object, it goes down the drain. I cannot even get anything to appear on screen without using optimizeinplace, and then when I use optimizeinplace the buffers get completely jacked up into something other than the desired object. Any ideas?
  2. Okay while I've been searching for the answer, it looks like it's probably because the mesh is defaulted as a triangle fan instead of strip... so looking for how to tell the mesh to be a strip.
  3. I have a working terrain grid with dynamic height that I drew using Device.DrawIndexedPrimitive. I wish to create a mesh using the same data, but when I use the exact same vertex array and index array, the outcome isn't the same. The working version is a square terrain with different heights, and the mesh version is displaying a left-bottom 3d triangle of sorts, where every triangle seems to be connected to (0,0) as one point. Any ideas on why this isn't working the same? They are both using a PositionNormalTextured format. My mesh code is below, WIDTH and HEIGHT are my max X and Z variables. meshTerrain = new Mesh(indices.Length/3, WIDTH * HEIGHT,0,CustomVertex.PositionNormalTextured.Format, device); meshTerrain.SetVertexBufferData(vertices,LockFlags.None); meshTerrain.SetIndexBufferData(indices,LockFlags.None); int[] adjacency = new int[meshTerrain.NumberFaces * 10]; meshTerrain.GenerateAdjacency(0.01F, adjacency); meshTerrain.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency); meshTerrain.ComputeNormals(); numSubSets = meshTerrain.GetAttributeTable().Length; .... // in render sub for (int i = 0; i < numSubSets; ++i) { meshTerrain.DrawSubset(i); } vertices and indices are the arrays that feed my vertex and index buffers that are working properly in Device.DrawIndexedPrimitive. Any ideas?
  4. gunhawk

    Directx 9 Lighting Help? C#

    Thanks so much those articles are a gold mine to me right now. I'm reading up on them now!
  5. gunhawk

    Directx 9 Lighting Help? C#

    Great, thank you. Edited: I've now learned what a normal is, thanks again!
  6. So far I have created an indexed primitive terrain and have set up my camera above it looking down. But I cannot seem to get point light or directional light working (have not tried spot light). Ambient light works, but I really need a directional light. I have tried 0,-1,0 as the direction to make it come from above, but that doesn't work. And I'm also trying to make it come diagonally down from the left but that isn't working either. Can anyone help? Code here: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace GunHawk { public class WinForm : System.Windows.Forms.Form { private Device device; private System.ComponentModel.Container components = null; private VertexBuffer vb; private IndexBuffer ib; private int[] indices; private CustomVertex.PositionNormal[] vertices; private int WIDTH = 10; private int HEIGHT = 10; private string sRandom; public WinForm() { InitializeComponent(); this.Setstyle(Controlstyles.AllPaintingInWmPaint | Controlstyles.Opaque, true); } public void InitializeDevice() { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.EnableAutoDepthStencil = true; // Turn on a Depth stencil presentParams.AutoDepthStencilFormat = DepthFormat.D16; // And the stencil format device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); } private void VertexDeclaration() { vertices = new CustomVertex.PositionNormal[WIDTH*HEIGHT]; vb = new VertexBuffer(typeof(CustomVertex.PositionNormal), WIDTH * HEIGHT, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormal.Format, Pool.Default); for (int x=0;x<WIDTH;x++) { for (int z=0;z<HEIGHT;z++) { Application.DoEvents(); vertices[x+(z*WIDTH)].SetPosition(new Vector3(x, RandomNumber(1,10), z)); //vertices[x+z*WIDTH].Color = Color.White.ToArgb(); } } vb.SetData(vertices,0,LockFlags.None); } private void IndicesDeclaration() { ib = new IndexBuffer(typeof(int),(WIDTH)*(HEIGHT)*6,device,Usage.WriteOnly, Pool.Default); indices = new int[WIDTH*HEIGHT*6]; for (int x=0;x<WIDTH-1;x++) { for (int z=0;z<HEIGHT-1;z++) { // Right topped triangle /| indices[(x+z*(WIDTH))*6] = (x+1)+(z+1)*WIDTH; indices[(x+z*(WIDTH))*6+1] = (x+1)+z*WIDTH; indices[(x+z*(WIDTH))*6+2] = x+z*WIDTH; // Left bottomed triangle |/ indices[(x+z*(WIDTH))*6+3] = (x+1)+(z+1)*WIDTH; indices[(x+z*(WIDTH))*6+4] = x+z*WIDTH; indices[(x+z*(WIDTH))*6+5] = x+(z+1)*WIDTH; } } ib.SetData(indices, 0, LockFlags.None); } private void LightSetup() { Color col = Color.White; // Set up a material. The material here just has the diffuse and ambient // colors set to white. Note that only one material can be used at a time. Material mtrl = new Material(); mtrl.Diffuse = col; mtrl.Ambient = col; device.Material = mtrl; //device.Lights[0].Ambient = Color.FromArgb(255,255,255); device.Lights[0].Type = LightType.Directional; device.Lights[0].Diffuse = Color.White; device.Lights[0].Direction = new Vector3(100f,-10f,0f); device.Lights[0].Commit(); device.Lights[0].Enabled = true; // Finally, turn on some ambient light. // Ambient light is light that scatters and lights all objects evenly. device.RenderState.Ambient = System.Drawing.Color.FromArgb(0x606060); } private void Render() { device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, 1f, 150f); device.Transform.View = Matrix.LookAtLH(new Vector3(5,25,5), new Vector3(5,0,5), new Vector3(0,0,1)); device.RenderState.FillMode = FillMode.Solid; device.RenderState.CullMode = Cull.None; device.RenderState.ZBufferEnable = true; device.RenderState.Lighting = true; device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkBlue , 1.0f, 0); device.BeginScene(); device.SetStreamSource(0,vb,0); device.Indices = ib; device.VertexFormat = CustomVertex.PositionNormal.Format; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, WIDTH*HEIGHT, 0, indices.Length/3); device.EndScene(); device.Present(); this.Invalidate(); } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { this.Render(); } protected override void Dispose (bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(500,500); this.Text = "DirectX Tutorial"; } static void Main() { using (WinForm our_directx_form = new WinForm()) { our_directx_form.InitializeDevice(); our_directx_form.VertexDeclaration(); our_directx_form.IndicesDeclaration(); our_directx_form.LightSetup(); Application.Run(our_directx_form); } } public int RandomNumber(int min, int max) { int i; Random random = new Random(); i = random.Next(min, max); sRandom += i.ToString() + ":"; System.Console.Write(sRandom); return i; } } }
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!