0

这是代码:

 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 这本书。

4

2 回答 2

0

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

什么设置path被传递到方法中LoadTexture

于 2013-07-11T18:33:26.050 回答
-1

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

public Form1(){

    InitializeComponent();
    _openGLControl.InitializeContexts();
于 2016-09-10T22:55:13.377 回答