PDA

View Full Version : image loading



phamt78
01-25-2008, 04:35 PM
Im trying to decide which image loading library to use with OpenGL. I found several online such as DevIL and SOIL. I was wondering what everyone here is using.

-NiCo-
01-25-2008, 04:52 PM
DevIL and SOIL are certainly a good place to start. I'm using imagemagick (http://www.imagemagick.org) myself, it's cross-platform and supports virtually all file formats. On the other hand, it doesn't provide an OpenGL interface.

N.

phamt78
01-25-2008, 05:15 PM
NiCo do you have to compile imagemagick to use Magick++. I downloaded the imagemagick binary package and did not see any c++ header files.

-NiCo-
01-26-2008, 12:48 AM
You don't have to compile it if you installed the binary package. The header files are in c:/Program Files/ImageMagick-6.3.8-1-Q8/include

N.

thinks
01-26-2008, 09:35 AM
ifl from Silicon Graphics is also a nice package. I found it a bit easier to use and get started with than ImageMagick.

phamt78
01-26-2008, 09:56 AM
NiCo do you know where i can find an example of how to use imagemagick with opengl.

-NiCo-
01-26-2008, 10:10 AM
Image im;
im.read("test.bmp");

int w = im.columns();
int h = im.rows();

unsigned char* data = new unsigned char[w*h];
im.write(0,0,w,h,"RGBA",CharPixel,data);

...
glTexImage2D(...,GL_RGBA8,GL_UNSIGNED_BYTE,&data[0]);

delete[] data;


N.

phamt78
01-26-2008, 10:12 AM
Nico thanks, I'll try it out.

phamt78
01-26-2008, 12:47 PM
NiCo I know this is not an Opengl question but can you help, I am getting link errors while compiling my code using Dev-C++. The error shows undefined reference to Magick::Image::Image() while compiling.

I include the namespace for it and (using namespace Magick;)
I tried linking the following files

CORE_RL_Magick++_.lib
CORE_RL_magick_.lib
CORE_RL_wand_.lib

but no luck. I also try initializing Magick++ with the following lines of code.

InitializeMagick("C://Program Files/ImageMagick-6.3.8-Q16/");

and still no luck. Any suggestion?

RGHP
01-26-2008, 04:06 PM
Why not FreeImage? Is open source but you can use It for commercial purposes, and now supports HDR images!( OpenEXR and Radiance):

http://freeimage.sourceforge.net/

Some sample code:




thisIsInitGL(){
loadTexture();
}
///Now the interesting code:
loadTexture(){
FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(textureFile,0);//Automatocally detects the format(from over 20 formats!)
FIBITMAP* imagen = FreeImage_Load(formato, textureFile);

FIBITMAP* temp = imagen;
imagen = FreeImage_ConvertTo32Bits(imagen);
FreeImage_Unload(temp);

int w = FreeImage_GetWidth(imagen);
int h = FreeImage_GetHeight(imagen);
cout<<"The size of the image is: "<<textureFile<<" es "<<w<<"*"<<h<<endl; //Some debugging code

GLubyte* textura = new GLubyte[4*w*h];
char* pixeles = (char*)FreeImage_GetBits(imagen);
//FreeImage loads in BGR format, so you need to swap some bytes(Or use GL_BGR).

for(int j= 0; j<w*h; j++){
textura[j*4+0]= pixeles[j*4+2];
textura[j*4+1]= pixeles[j*4+1];
textura[j*4+2]= pixeles[j*4+0];
textura[j*4+3]= pixeles[j*4+3];
//cout<<j<<": "<<textura[j*4+0]<<"**"<<textura[j*4+1]<<"**"<<textura[j*4+2]<<"**"<<textura[j*4+3]<<endl;
}

//Now generate the OpenGL texture object

glGenTextures(1, &amp;texturaID);
glBindTexture(GL_TEXTURE_2D, texturaID);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, w, h, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)textura );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

GLenum huboError = glGetError();
if(huboError){

cout<<"There was an error loading the texture"<<endl;
}


}

RGHP
01-26-2008, 04:10 PM
FreeImage is cross plataform too! and comeswoth a lot of doc. ALso have some functions utilities to save Files, format change rotate, sclae images and tone mapping!

By the way, which format do you use for HDR Cube Maps?, and where is a gallery of these CubeMaps?(others than the ones from debevec.org). I need it works on Linux.

ZbuffeR
01-27-2008, 02:39 AM
A thread in french, have a look at all the links on the 3 pages, it has quite a lot of cubemap and skies galleries :

http://blenderclan.tuxfamily.org/html/mo...der=ASC&start=0 (http://blenderclan.tuxfamily.org/html/modules/newbb/viewtopic.php?topic_id=12027&viewmode=flat&order=ASC&start=0)

Seth Hoffert
01-27-2008, 06:29 PM
There are more HDR probes here:

http://www.unparent.com/photos_probes.html

Personally, I use the format described in EXT_texture_shared_exponent to store my cubemaps.