Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: image loading

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    21

    image loading

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: image loading

    DevIL and SOIL are certainly a good place to start. I'm using imagemagick myself, it's cross-platform and supports virtually all file formats. On the other hand, it doesn't provide an OpenGL interface.

    N.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    21

    Re: image loading

    NiCo do you have to compile imagemagick to use Magick++. I downloaded the imagemagick binary package and did not see any c++ header files.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: image loading

    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Jan 2005
    Location
    Stockholm, Sweden
    Posts
    164

    Re: image loading

    ifl from Silicon Graphics is also a nice package. I found it a bit easier to use and get started with than ImageMagick.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    21

    Re: image loading

    NiCo do you know where i can find an example of how to use imagemagick with opengl.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: image loading

    Code :
    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.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    21

    Re: image loading

    Nico thanks, I'll try it out.

  9. #9
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    21

    Re: image loading

    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?

  10. #10
    Intern Contributor
    Join Date
    Nov 2006
    Location
    Peru
    Posts
    95

    Re: image loading

    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:

    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;
    	}
     
     
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •