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:

// 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 :smiley:
Now my code, which doesn’t seem to work pretty well:

// 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 :slight_smile:

Greetings
UndeadLeech