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));
    }

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.