XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Texture importer not recognized c++/cli

Last post 7/26/2009 6:17 AM by DivideByZero. 3 replies.
  • 7/25/2009 7:12 PM

    Texture importer not recognized c++/cli

    I'm trying to make a Texture importer using the FreeImage library. I'm following the idea in Shawn's blog here:
    http://blogs.msdn.com/shawnhar/archive/2007/04/02/any-language-you-like-as-long-as-it-s-at-build-time.aspx

    I can't seem to get it to use my importer. Here is a basic skeleton, hopefully someone can shed light on.


    File > New Project > Visual Studio Solutions > Blank Solution
    Add > New Project > Visual C++ > CLR > Class Library
        MyImporter

    // MyImporter.h

    #pragma once

    using
    namespace System;
    using namespace Microsoft::Xna::Framework::Graphics;
    using namespace Microsoft::Xna::Framework::Content::Pipeline;
    using namespace Microsoft::Xna::Framework::Content::Pipeline::Graphics;

    namespace

    MyImporter {

    [ContentImporter(
    ".foo", DisplayName="My Custom Texture Importer", DefaultProcessor="SpriteTextureProcessor")]
    public ref class MyTextureImporter : ContentImporter<TextureContent^>
    {
        public:
        MyTextureImporter() {}
        
        public:
        
    virtual TextureContent^ Import(String^ filename, ContentImporterContext^ context) override
        
    {
            Texture2DContent^ texture =
    gcnew Texture2DContent();
            
    // TODO: Load bitmap from filename
            
    BitmapContent^ bitmap = gcnew PixelBitmapContent<Color>(100,100);
            texture->Mipmaps->Add(bitmap);
            
    return texture;
        }
    };
    }

    References...
        C:\Program Files\Microsoft XNA\XNA Game Studio\v3.1\References\Windows\x86\Microsoft.Xna.Framework.dll
        C:\Program Files\Microsoft XNA\XNA Game Studio\v3.1\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.dll

    Add > New Project > Visual C# > XNA Game Studio 3.1 > Windows Game (3.1)
        WindowsGame1

    Content > Add Reference... > Projects > MyImporter

    Build Solution: build succeeded

    Now I add a file Winter.foo to the Content project, build:

     

    ------ Build started: Project: WindowsGame1, Configuration: Debug x86 ------

    Building Winter.foo -> C:\Documents and Settings\kselden\My Documents\Visual Studio 2008\Projects\Solution1\WindowsGame1\bin\x86\Debug\Content\Winter.xnb

    Content\Winter.foo : error : Cannot find importer "MyTextureImporter".

    Done building project "Content.contentproj" -- FAILED.

    ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

    The above example seems so minimal I can't imagine what step I'm missing. I'm hoping that Shawn or someone can just provide a basic skeleton for an importer with c++/cli. I suppose I could revert to P/Invoke but I'd rather not.

    There also doesn't seem to be a great way to debug the content build process.

    Thanks in advance,
    Kris

  • 7/26/2009 1:43 AM In reply to

    Re: Texture importer not recognized c++/cli

    I'm at home right now so can't try this out, but one thing that occurs to me is I think you need to use "class MyTextureImporter : public ContentImporter<...>" - without the public part in C++ you get private inheritance, and I don't know exactly what that means or how it works in C++/CLI but it probably isn't what you want here.

    If that isn't it, my next best guess would be a version mismatch: a common reason for not being able to find pipeline extensions is if the extension is built using say GS 3.1 assemblies, but the content project which references it uses a different GS version eg. 3.0.

    Let me know if neither of those helps, and I'll try this out in practice when I get back to the office on Monday.
    XNA Framework Developer - blog - homepage
  • 7/26/2009 5:59 AM In reply to

    Re: Texture importer not recognized c++/cli

    I changed it to:

    public

     

    ref class MyTextureImporter : public ContentImporter<TextureContent^>

    I still get the same error.

    I checked all the references, all of them are to 3.1. It does however look like I still have stuff from GS 3.0 even though I uninstalled it. I can't rerun the uninstaller because it is no longer listed as being installed. I'd certainly be interested if it is something to do with my install. When I go to choose references I see Microsoft.Xna.Framework 3 times, I pick the last one and check that the path is to 3.1 assemblies.

    Though when I inspect the dll in .net reflector or in the object viewer, all the references look the same and it looks just like the framework TextureImporter, the same references, same super class, same attribute. I don't understand it.

    Thanks for replying, have a good weekend.

     

  • 7/26/2009 6:17 AM In reply to

    Re: Texture importer not recognized c++/cli

    Ok, I removed MyImporter as a project reference and instead choose Browse and selected the MyImporter.dll and it worked.

    What I don't understand, is either way, when I inspect the reference they are the exact same path and copy local is true. Maybe copy local doesn't work when choosing a C++/CLI project as a reference?

    I guess I'll just add the reference by path and manually rebuild it unless someone can shed some light. Or at least how to get MSBuild to log more verbosely.
Page 1 of 1 (4 items) Previous Next