无法用DevIL打开文件

时间:2013-07-11 18:30:37

标签: c# opengl devil tao-framework

以下是代码:

 public void 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 + "].");
        }
        // The files we'll be using need to be flipped before passing 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));
    }

我收到断言失败,无法打开文件[face.tif]错误。我确保face.tif文件位于项目文件夹,解决方案文件夹,bin文件夹,bin \ debug文件夹中,但仍然无法打开它。

我正在尝试遵循C#Game Programming for Serious Game Creation这本书。

2 个答案:

答案 0 :(得分:0)

它正在您的代码运行的同一目录中查找文件face.tif

设置传递给方法path的{​​{1}}是什么?

答案 1 :(得分:-1)

Form主类(Ex:Form.cs)上,将这两行放在构造函数的顶部:

public Form1(){

    InitializeComponent();
    _openGLControl.InitializeContexts();
相关问题