Jump to content
  • Advertisement
Sign in to follow this  
indieboy

[.net] DirectX and .NET 2.0

This topic is 4462 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.. I'm trying to run Hazy mind tutorials on .NET 2.0 but i can't make it work. Here's the code for my vertex group class, it compiles but it generates nothing on screen. The method ReloadResources is called on initialization and Render is called between BeginScene(); and EndScene();
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.Direct3D.CustomVertex;
using Microsoft.DirectX.Generic;

namespace ClientEngine
{
    public class EVertexGroup : EObject
    {
        private PositionTextured[] verts;
        private int[] inds;
        private Texture myTexture;
        private string myPath;

        private VertexBuffer vb;
        private IndexBuffer ib;

        public EVertexGroup(PositionTextured[] vertex, int[] index, string imagePath, Device myDevice)
        {
            verts = vertex;
            inds = index;
            myPath = imagePath;
            ReloadResources(myDevice);
        }

        public override void ReloadResources(Device myDevice)
        {
            myTexture = new Texture(myDevice, myPath);

            vb = VertexBuffer.CreateGeneric<PositionTextured>(myDevice, verts.Length, Usage.WriteOnly, PositionTextured.Format, Pool.Managed, null);
            GraphicsBuffer<PositionTextured> vertBuffData = vb.Lock<PositionTextured>(0, 0, 0);
            vertBuffData.Write(verts);
            vb.Unlock();

            ib = new IndexBuffer(myDevice, inds.Length, Usage.WriteOnly, Pool.Default, false, null);
            GraphicsBuffer<int> indexBuffData = ib.Lock<int>(0, 0, 0);            
            indexBuffData.Write(inds);
            ib.Unlock();
        }

        public override void Render(Device myDevice)
        {
            myDevice.VertexFormat = PositionTextured.Format;
            myDevice.SetTexture(0, myTexture);
            myDevice.SetStreamSource(0, vb, 0);
            myDevice.Indices = ib;
            myDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, verts.Length, 0, inds.Length / 3);
        }
    }
}

Is this the right way to do things when one's using .NET 2.0? Thanks in advance! Leandro

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!