2012-06-08 55 views
1

我在使用DevIL 1.7.8閱讀圖像時遇到問題。 到目前爲止,我知道下面的代碼片段應該工作:使用DevIL閱讀圖像

ilInit(); 
ILuint ImageName; 
ilGenImages(1, &ImageName); 
ilBindImage(ImageName); 
wchar_t* imgFilename = L"..\\..\\resources\\textures\\red.png"; 
ilLoadImage(imgFilename); 
ILubyte* texture = ilGetData(); 

當我檢查的第一像素

for (int i=0; i<64; i++) cout << (int)texture[i] << endl; 

我得到一個漂亮的任意輸出。圖片實際上是完全紅色的。

除了我嘗試使用ILUT

ilutRenderer(ILUT_OPENGL); 
GLuint t = ilutGLLoadImage(L"..\\..\\resources\\textures\\red.png"); 

但實際上我不能甚至包括相應的報頭文件,因爲內的頭文件il.h被鏈接,其被認爲是一個文件夾中(\ IL )不存在。即使當我創建這個文件夾並將所需的頭文件複製到它時,我也會遇到編譯錯誤。

任何人都可以幫助我與魔鬼嗎?

回答

0

我讀圖像,並結合紋理像這樣:

ilEnable(IL_ORIGIN_SET); 
ilOriginFunc(IL_ORIGIN_LOWER_LEFT); // set [0,0] of texture to bottom left corner 

ilImage image; 
GLuint ind; 
glGenTextures(1, &ind); 
glBindTexture(GL_TEXTURE_2D, ind); 
image.Load(L"<path>");// or just name.format be sure to have image in correct folder. 

渲染時,你需要先綁定正確的質地:質地的UV coordites

glBindTexture(GL_TEXTURE_2D, ind); 

,然後分配到頂點:

glTexCoord2f(x1, y1);    
glVertex3f(x, y, z); 

不要忘記啓用GL_TEXTURE_2D或您正在使用的任何類型。