2011-08-14 99 views
2

我正在使用DevIl庫並嘗試使用它來加載紋理到OpenGL以應用於精靈。該代碼直接出自C#Game Programming for Serious Game Design一書(如果有幫助的話)。我遇到的問題是與Il.ilLoadImage調用。即使當我將它傳遞給null時,它也不會拋出未找到圖像的錯誤,並且當彈出窗體時,精靈顯示爲深灰色(而不是白色)。使用DevIl庫加載紋理的問題

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

DevIL基於OpenGL的API和通用結構,相當荒謬。因此,報告錯誤的典型方式是ilGetError。如果你想確保一個函數成功與否,你應該使用它。

+0

但我該怎麼做? ilLoadImage調用返回true,所以不能表明沒有錯誤發生?該調用之後的所有行都運行並且斷言從不被調用。 – Pat

+0

調用'ilLoadImage'後調用'ilGetError'。如果它返回「IL_NO_ERROR」以外的內容,則發生錯誤。可悲的是,DevIL的文檔對於'ilLoadImage'的返回值意味着什麼是相當無聊的。 –

+0

我想通了,原來我使用的Tao框架的版本與我從下載最新版本的DevIl得到的dll不兼容。該命令面臨拋出一個錯誤,我只是沒有看到(顯然,當這種情況發生時,命令不返回錯誤)。非常感謝! – Pat