Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Loading an image with FreeImage

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    3

    Loading an image with FreeImage

    Hay guys after I fixed my SOIL problem by using FreeImage, I now need to change the code, so it works like the code I saw in a tutorial.

    The tutorial code looks like this:

    Code :
    // Load texture
        GLuint tex;
        glGenTextures(1, &tex);
     
        int width, height;
        unsigned char* image = SOIL_load_image("sample.png", &width, &height, 0, SOIL_LOAD_RGB);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
        SOIL_free_image_data(image);
     
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    And this should be working because it's a tutorial ofc
    Now my code, which doesn't seem to work pretty well:

    Code :
    // Load textures
        GLuint tex;
        glGenTextures(1, &tex);
     
    	int width, height;
     
    	FREE_IMAGE_FORMAT formato = FreeImage_GetFileType("sample.png",0);
    	FIBITMAP* imagen = FreeImage_Load(formato, "sample.png");
    	FIBITMAP* temp = imagen;  
    	imagen = FreeImage_ConvertTo32Bits(imagen);
    	FreeImage_Unload(temp);
     
    	width = FreeImage_GetWidth(imagen);
    	height = FreeImage_GetHeight(imagen);
     
    	GLubyte* textura = new GLubyte[4*width*height];
    	char* pixeles = (char*)FreeImage_GetBits(imagen);
     
    	for(int j= 0; j<width*height; 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];
    	}
     
    	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)textura );
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    I tried my best to get the same result by searching for examples for FreeImage with google, but this doesn't work!

    Would be nice if you could spot the mistake and tell me so I can gain more experience

    Greetings
    UndeadLeech
    Last edited by UndeadLeech; 10-26-2013 at 02:56 AM.

Posting Permissions

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