开发者

Issue with texture loading using the DevIl library

开发者 https://www.devze.com 2023-03-27 21:32 出处:网络
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 hel

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.Asser开发者_开发知识库t(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));
    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号