Advertisement Jump to content
Sign in to follow this  
indieboy

[.net] DirectX and .NET 2.0

This topic is 4558 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.

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!