Domanda

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));
    }
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top