2011-06-22 49 views
0

我創建了一個帶有opengl功能的x11窗口,我需要在窗口大小大於圖像的背景上加載一個圖像(jpeg | png) ,沒關係。我衝浪得到像使用魔鬼或免費圖像reslets。我不知道使用哪一個。我使用a link to sample code中給出的示例代碼設置了opengl窗口,並且我希望在void renderGL()中編寫代碼以使圖像成爲背景。你能告訴我要使用哪個圖像庫,並儘可能地提供代碼。使用GLX(opengl和Xlib)設置圖像(jpeg | png)背景

而且還要做什麼來繪製opengl中的彩色像素。我需要一個函數來繪製一個窗口中的像素,爲此我必須提供單獨的x,y像素位置和rgb顏色(無符號整數).....

+0

我發現它自己 – HariHaraSudhan

回答

1

我不是一個opengl程序員,但不知怎的,我做了這個 和它的工作


ilInit(); /* Initialization of DevIL */ 
ilGenImages(1, &texid); /* Generation of one image name */ 
ilBindImage(texid); /* Binding of image name */ 
success = ilLoadImage(backgroundimage); /* Loading of image "image.jpg" */ 
iWidth = ilGetInteger(IL_IMAGE_WIDTH); 
iHeight = ilGetInteger(IL_IMAGE_HEIGHT); 
if (success){ 
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); // Convert every colour component into unsigned byte,replace IL_RGB with IL_RGBA for alpha channel 
} 

glGenTextures(1, &image); /* Texture name generation */ 
glBindTexture(GL_TEXTURE_2D, image); /* Binding of texture name */ 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), 

ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, 
ilGetData()); /* Texture specification */ 

glRotatef(roll, 0.0f,0.0f, 10.0f);  
glOrtho(0.0, float(width), float(height), 0.0, 0.0, 100.0); 
glMatrixMode(GL_MODELVIEW); 
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
glClearDepth(0.0f); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glLoadIdentity(); // Reset The Modelview Matrix 

glBindTexture(GL_TEXTURE_2D, image); // Select The First Image Texture 
glBegin(GL_QUADS);// Start Drawing A Textured Quad 
glTexCoord2i(0, 0); glVertex2f(width/2-iWidth/2,height/2-iHeight/2); 
glTexCoord2i(0, 1); glVertex2f(width/2-iWidth/2,height/2+iHeight/2); 
glTexCoord2i(1, 1); glVertex2f(width/2+iWidth/2,height/2+iHeight/2); 
glTexCoord2i(1, 0); glVertex2f(width/2+iWidth/2,height/2-iHeight/2);   
glEnd();