2

I am working with the DevIl library and trying to use it to load a texture to OpenGL to apply to a sprite. The code is directly out of the C# Game Programming for Serious Game Design book (if that helps). The problem I'm having is with the Il.ilLoadImage call. Even when I pass it null, it doesn't throw an image not found error, and the sprite just shows up dark grey (instead of white) when the form pops up.

public void LoadTexture(string textureId, string path)
    {
        int devilId = 0;
        Il.ilGenImages(1, out devilId);
        Il.ilBindImage(devilId);

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

        //Flip the files before passing them to OpenGl
        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);

        _textureDatabase.Add(textureId, new Texture(openGLId, width, height));
    }
Pat
  • 331
  • 1
  • 4
  • 16

1 Answers1

2

DevIL is, rather nonsensically, based on OpenGL's API and general structure. As such, the typical way that errors are reported is with ilGetError. If you want to make sure a function succeeded or not, you should use that.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • How would I do that though? The ilLoadImage call is returning true so wouldn't that indicate that no error is happening? All of the lines after that call run and the assert is never called. – Pat Aug 15 '11 at 03:02
  • 1
    You call `ilGetError` after calling `ilLoadImage`. If it returns something other than `IL_NO_ERROR`, then an error occurred. Sadly, DevIL's documentation is rather uncommunicative about what the return value of `ilLoadImage` means. – Nicol Bolas Aug 15 '11 at 04:37
  • 1
    I figured it out, turns out that the version of the Tao framework I was using was not compatible with the dll's I got from downloading the latest version of DevIl. The command was in face throwing an error that I just was not seeing (and apparently the command doesn't return false when that happens). Thank you so much! – Pat Aug 15 '11 at 23:13