Jump to content

  • Log In with Google      Sign In   
  • Create Account

Cannot access asset from list OpenGl, C#, Tao framework


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 fafase   Members   -  Reputation: 368

Like
0Likes
Like

Posted 15 July 2013 - 07:37 PM

Ok, I am trying to develop a mini engine using Tao framework (I know about its old status but t has feature I wanted).

I made a Content manager that load assets it finds from a folder. It all seems to work excepth that I can only load the last loaded asset of the list.

For now I only use textures and I only can access the last one loaded whatever names I give.

Here is the content class:

  public static class Content
  {
    public static Dictionary<string, object> _content = new Dictionary<string, object>();
    public static void LoadAsset(){

    string[] filePaths = Directory.GetFiles(@"Container");

    foreach (string s in filePaths)
    {
       int indexDot = s.LastIndexOf('.');
       int indexSlash = s.LastIndexOf('\\');
       string extension = s.Substring(indexDot);
       string temp = s.Remove(indexDot);
       string assetId = temp.Substring(indexSlash+1);

       switch (extension) {  
       // Here a whole bunch of extension but only one is enough
          case ".png":
             _content.Add(assetId, TextureManager.LoadTexture(assetId, s));
             break;
      }
    }
  }
  public static T Load<T>(string asset)
  {
    return (T)_content[asset];
  }
}

 

Then I call the TextureManager.LoadTexture that goes as such:

  public static Texture LoadTexture(string textureId, string path)
  {
    int devilId = 0;
    Il.ilGenImages(1, out devilId);
    Il.ilBindImage(devilId); // set as the active texture.

    if (!Il.ilLoadImage(path))
    {
         System.Diagnostics.Debug.Assert(false,
            "Could not open file, [" + path + "].");
    }

    //Ilu.iluFlipImage();

    int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
    int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
    int openGLId = Ilut.ilutGLBindTexImage();

    System.Diagnostics.Debug.Assert(openGLId != 0);
    Il.ilDeleteImages(1, ref devilId);
    Texture texture = new Texture(textureId,openGLId, width, height);
    return texture;
 }

 

This last bit is taken from C# game programming book so I guess it should work, I only made it static as well as the dictionary.

At the end of the LoadTexture method, the returned texture is added to the content list.

But if for instance I have three texture a.png, b.png and c.png, whether I try to access a, b or c I only get c and no error. I try to debug and I can see the different names but they all seem to point to the same texture in memory in the end. And I know it only takes the last one as I tried to change the name order and realized that if a becomes d then I get the new d.

Also, the dictionary has Count equals to 3 so it is all there, only teh texture is wrong.

Any idea?

Thanks



Sponsor:

#2 Sponji   Members   -  Reputation: 1356

Like
0Likes
Like

Posted 16 July 2013 - 11:52 AM

Does ilutGLBindTexImage really return the id? Have you tried debugging the values it gives to your textures? At least the method's name sounds like it would just bind the texture, and probably returns an error code or something.


Derp




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS