Skip to main content
gamedev.net
🔒 Locked

TextureLoader does not exist - (solved)

Started by DMINATOR Dec 18, 2004 at 4:52 PM 1 replies 2.9k views
Original Post
DMINATOR
DMINATOR
[solution] - include a reference to Microsoft.DirectX.Direct3DX [details] - at the end OK I have sometimes during the holidays so I thought like, it a good idea to learn Direct3d especially when it's simplified when using managed directx. As always learning microsoft work it was hard to find a source of information to get started. Spending a few days in search and trying numerous sites I came up with this tutorial genkisoft . It was helpfull to get the idea how DX work, but I came up to a problem. Because I am totally new to DX I can't explain much about what is going on. Here is original code from article Adding Texture (4_TextureDemo.cs)

//=========================================================================
// TextureDemo.cs
// Coder: Thobias Jones
// Purpose: Managed DirectX 9 triangle with texture
// Copyright is given up. This code is released into the
// public domain without warranty.
// Visit our website at http://www.genkisoft.com
//=========================================================================

using Microsoft.DirectX;
using Direct3D = Microsoft.DirectX.Direct3D;

namespace Genkisoft
{
    public class DX9Demo : System.Windows.Forms.Form
    {
        // Required designer variable.
        private System.ComponentModel.Container components = null;

        public DX9Demo()
        {
            // Required for Windows Form Designer support
            InitializeComponent();
        }

        // Clean up any resources being used.
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // DX9Demo
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Name = "DX9Demo";
            this.Text = "Texture Demo";

        }
        #endregion

        [System.STAThread]
        static void Main()
        {
            DX9Demo demo = new DX9Demo();
            demo.InitDirect3D();
            demo.Run();
        }

        public void Run()
        {
            Show();

            while(Created)
            {
                DrawScene();
                System.Windows.Forms.Application.DoEvents();
            }
        }

        //
        // Start of Managed DirectX 9 demo code
        //

        private readonly bool windowed = true;
        private Direct3D.Device device = null;
        private Direct3D.VertexBuffer vertexBuffer = null;
        private Direct3D.IndexBuffer indexBuffer = null;
        private Direct3D.Texture texture = null;

        private static Direct3D.CustomVertex.TransformedColoredTextured[] m_aVertices =
        {
            new Direct3D.CustomVertex.TransformedColoredTextured(120.0f, 120.0f, 1.0f, 1.0f, 0,            0.5f, 0.0f),
            new Direct3D.CustomVertex.TransformedColoredTextured(200.0f, 200.0f, 1.0f, 1.0f, 0,            1.0f, 1.0f),
            new Direct3D.CustomVertex.TransformedColoredTextured(30.0f,  200.0f, 1.0f, 1.0f, int.MaxValue, 0.0f, 1.0f),
        };

        private static ushort[] m_aIndices = { 0, 1, 2 };

        private void InitDirect3D()
        {
            Direct3D.PresentParameters presentParams;
            presentParams = new Direct3D.PresentParameters();

            presentParams.Windowed = windowed;
            if(windowed)
            {
                presentParams.SwapEffect = Direct3D.SwapEffect.Copy;
            }
            else
            {
                presentParams.SwapEffect       = Direct3D.SwapEffect.Flip;
                presentParams.BackBufferFormat = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Format;
                presentParams.BackBufferWidth  = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Width;
                presentParams.BackBufferHeight = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Height;
                presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
                presentParams.PresentationInterval      = Direct3D.PresentInterval.One;
            }

            device = new Direct3D.Device(0,
                                         Direct3D.DeviceType.Hardware,
                                         this,
                                         Direct3D.CreateFlags.SoftwareVertexProcessing,
                                         presentParams);

            device.DeviceReset += new System.EventHandler(this.OnDeviceReset);

            OnDeviceReset(device, null);
        }

        public void OnDeviceReset(object sender, System.EventArgs e)
        {
            Direct3D.Device dev = (Direct3D.Device)sender;

            dev.RenderState.Lighting = false;

            if(null != vertexBuffer)
            {
                vertexBuffer.Dispose();
            }

            vertexBuffer = new Direct3D.VertexBuffer(m_aVertices[0].GetType(),
                                                     m_aVertices.Length,
                                                     dev,
                                                     Direct3D.Usage.WriteOnly,
                                                     Direct3D.CustomVertex.TransformedColoredTextured.Format,
                                                     Direct3D.Pool.Default);

            vertexBuffer.SetData(m_aVertices, 0, Direct3D.LockFlags.None);

            dev.VertexShader = null;
            dev.VertexFormat = Direct3D.CustomVertex.TransformedColoredTextured.Format;
            dev.SetStreamSource(0, vertexBuffer, 0);

            if(null != indexBuffer)
            {
                indexBuffer.Dispose();
            }

            indexBuffer = new Direct3D.IndexBuffer(m_aIndices[0].GetType(),
                                                   m_aIndices.Length,
                                                   dev,
                                                   Direct3D.Usage.WriteOnly,
                                                   Direct3D.Pool.Default);
            indexBuffer.SetData(m_aIndices, 0, Direct3D.LockFlags.None);

            dev.Indices = indexBuffer;

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream stream = assembly.GetManifestResourceStream("_4_Texture.photo.png");

            // If you want to know the names of all of the embedded resources,
            // you can get an array of strings with the names.
            // string[] resourceNames = assembly.GetManifestResourceNames();

            // If you want to load the texture from a file instead of an embedded resource, you can do this:
  //!!!!! HERE IS ERROR
            // texture = Direct3D.TextureLoader.FromFile(dev, "photo.png");

            if(null != texture)
            {
                texture.Dispose();
            }

            texture = Direct3D.TextureLoader.FromStream(dev, stream);
            stream.Close();

            dev.SetTexture(0, texture);
        }

        private void DrawScene()
        {
            device.Clear(Direct3D.ClearFlags.Target, System.Drawing.Color.CornflowerBlue, 1.0f, 0);
            device.BeginScene();
            device.DrawIndexedPrimitives(Direct3D.PrimitiveType.TriangleList,
                                         0,
                                         0,
                                         m_aVertices.Length,
                                         0,
                                         m_aIndices.Length / 3);
            device.EndScene();
            device.Present();
        }
    }
}




Now when I compile the code I get this error message:
Quote:
MainClass.cs(179,23): error CS0234: The type or namespace name 'TextureLoader' does not exist in the class or namespace 'Microsoft.DirectX.Direct3D' (are you missing an assembly reference?)
Pls help. P.S. I am looking for usefull tutorials, especially for managed DX, If anyone is familiar with it, then help everyone to start by writing tutorials, because the ammount of info on the net is wery limited. [Edited by - DMINATOR on December 19, 2004 1:22:16 PM]
DMINATOR
DMINATOR
skip this :
Quote:

Nope it didn't help

It is also somehow missing
Quote:

'Direct3DX' does not exist in the class or namespace 'Microsoft.DirectX'


Btw I found this in one of the gamedev topics
Direct3DX under C#

It seems that there is no need to include it because it's already a part of Direct3D.


Trying to solve this problem I came up with this article in sharpdevelop forum
Error while unzipping It's not really the same problem I have, so I am still searching for solution.


OK it must be my knowledge of C#. Can anyone explain me what is the reference and what is using ? I thought that these things are the same. So I actually added the reference and it worked :). Tnx anonymous poster :)

BTW it can be done alternativly by using:

texture = new Direct3D.Texture(device, new Bitmap("test.bmp"),Direct3D.Usage.Dynamic, Direct3D.Pool.Default);

[Edited by - DMINATOR on December 19, 2004 1:05:35 PM]

Topic Locked

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

Sign in to reply to this topic.