Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Problems Rendering

Started by Axiverse 0 replies 300+ views
Original Post
Axiverse
Axiverse
Gah! I always seem to have problems rendering the first quad... Maybe it's because of .net framework 2, but probably not. I don't know what I'm missing: It's just two triangles, but it refuses to work... I've been looking at it for hours... Vertex:

        public struct Vertex
        {
            public Vector3 position;
            public int color;

            public Vertex(Vector3 p, Color c)
            {
                position = p;
                color = c.ToArgb();
            }

            public Vertex(float x, float y, float z)
            {
                position = new Vector3(x, y, z);
                color = Color.Blue.ToArgb();
            }

            public const VertexFormats format = VertexFormats.Position | VertexFormats.Diffuse;
        }

Creation:

            int adapter = 0;
            PresentParameters present = new PresentParameters();
            DeviceType type = DeviceType.Hardware;
            BehaviorFlags behavior = new BehaviorFlags(CreateFlags.SoftwareVertexProcessing);

            present.EnableAutoDepthStencil = false;
            present.IsWindowed = true;
            present.MultiSampleType = MultiSampleType.None;
            present.PresentationInterval = PresentInterval.Default;
            present.SwapEffect = SwapEffect.Discard;

            device = new Device(adapter, type, this.Handle, behavior.Value, present);
            verticies = new VertexBuffer(device, 16 * 6, Usage.None, Vertex.format, Pool.Default, null);

            this.Show();

            GraphicsBuffer<Vertex> vLock = verticies.Lock<Vertex>(0, 6, LockFlags.None);
            vLock.Write(new Vertex(-1.0f, -1.0f, 0.0f));
            vLock.Write(new Vertex(-1.0f, 1.0f, 0.0f));
            vLock.Write(new Vertex(1.0f, -1.0f, 0.0f));
            vLock.Write(new Vertex(-1.0f, 1.0f, 0.0f));
            vLock.Write(new Vertex(1.0f, -1.0f, 0.0f));
            vLock.Write(new Vertex(1.0f, 1.0f, 0.0f));

            vLock.Position = 0;
            Vertex[] v = vLock.ReadArray(6);
            verticies.Unlock();

Render Loop:

            device.Transform.World = Matrix.Identity;

            device.RenderState.CullMode = Cull.None;
            device.RenderState.Lighting = false;

            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            device.BeginScene();

            device.Transform.Projection = Matrix.PerspectiveFieldOfViewLeftHanded((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
            device.Transform.View = Matrix.LookAtLeftHanded(
                            new Vector3(5.0f, 5.0f, 5.0f),
                            new Vector3(0.0f, 0.0f, 0.0f),
                            new Vector3(0.0f, 1.0f, 0.0f));

            device.SetStreamSource(0, verticies, 0);
            device.VertexFormat = Vertex.format;
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);


            device.EndScene();
            device.Present();

Axiverse
Axiverse
Has anyone used the .net framework 2 version of directX? It seems that the problem is in there somehow. But, unless the GraphicsBuffer is used wrong I can't find any problems. It seems to work with the old version though...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.