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 3 of 3

Thread: Texture not loading/rendering correctly (using FreeImage)

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    5

    Texture not loading/rendering correctly (using FreeImage)

    Hello everyone,

    first time beeing here I couldn't manage to make the links to the tutorial URL and the image URL because everytime I got this error message:
    Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words.

    So you have to copypaste the URLs and delete the space in "ht tp". Are actually 2 URLs too many -.- this is really annoying if I can't even link to 1 page or 1 image. well whatever...

    I'm following this tutorial "ht tp://ogldev.atspace.co.uk/index.html" and I am at chapter 22 "Loading models using the Open Asset Import Library" now. You can see there what the model should look like but instead mine looks like this: "ht tp://postimg.org/image/6vq9ovbkx/"

    In the tut he's using ImageMagick but I'm useing FreeImage so I thought the bug might be when loading the texture.

    Code :
    bool Texture::Load()
    {
    	FIBITMAP* bitmap = FreeImage_Load(FreeImage_GetFileType(m_imagePath, 0), m_imagePath);
    	printf("Loading texture: '%s'\n", m_imagePath);
     
    	glGenTextures(1, &m_textureObj);
     
    	glBindTexture(m_textureTarget, m_textureObj);
    	glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    	FIBITMAP *pImage = FreeImage_ConvertTo32Bits(bitmap);
    	int nWidth = FreeImage_GetWidth(pImage);
    	int nHeight = FreeImage_GetHeight(pImage);
     
    	glTexImage2D(m_textureTarget, 0, GL_RGB, nWidth, nHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));
     
    	GLenum error = glGetError();
    	if(error){ 
    		printf("There was an error loading the texture\n");
    	}
     
    	FreeImage_Unload(bitmap);
     
        return true;
    }

    From the look of my model I thought the problem might be the alpha channel but actually I'm using only RGB. Any ideas?

    thanks in advance,
    Jan

    EDIT1: the model file is a .md2 and the texture file a .pcx (the source is also available here "ht tp://ogldev.atspace.co.uk/www/tutorial22/tutorial22.html")

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    5
    Ah I forgot glEnable(GL_DEPTH_TEST); but now nothing is rendered.

    EDIT1: I read in other forums that the problem was that glClear(GL_COLOR_BUFFER_BIT) wasn't set. I'm doing this in the render callback.
    Last edited by Jan539; 11-27-2013 at 10:47 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    5
    Ok I solved this problem too but it was somewhat strange. I set the distance of the near plane of my view field to 0.0f before which didn't work. It only works for values > 0.0f (even thought it worked fine before with 0.0f without GL_DEPTH).
    Also I have to set the projection matrix everytime the render callback is called now. Before it was enough to init the matrixe only once in the beginning. Can some explain this to me (only if it's code independent)?

Posting Permissions

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