How do I load textures in OpenGL?

Apr 19, 2012 at 1:15pm
I have tried SOIL, and it works, but it seems to stretch and blend the colors too much, basically a low resolution. Also, it causes a white border to the transparent parts of the image. If that is caused by SOIL, what other method should I use to load textures that would be better? If it is just a setting of SOIL that can be changed, how can I change it?
Apr 19, 2012 at 2:39pm
That's not caused by SOIL, that's caused either by you stretching the image (not texturing it 1 to 1 with the polygon you're rendering it onto), or by you not having power of 2 image sizes.

1) Make sure your image file is a power of 2 size (256x128 is OK. 256x160 is not). I don't know if SOIL automatically converts for you, but this is an OpenGL requirement for textures.

2) If you don't want stretching, make sure you're not doing any stretching. That is, if your image is 100x100 pixels, make sure the polygon is also 100x100 pixels.

3) If you do want stretching but don't want the "blurring" you're seeing, turn off OpenGL filtering:

http://msdn.microsoft.com/en-us/library/dd368641%28v=vs.85%29.aspx

set min filter and mag filter to GL_NEAREST (GL_LINEAR is the default setting and is what is doing the blurring)

1
2
3
// after the texture has been loaded
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Apr 19, 2012 at 9:13pm
Thanks, that helps.
Also, if my object was twice the size of my picture, how would I go about tiling it?
Apr 21, 2012 at 6:10pm
I have run into one other problem. I'm not sure if it is the image, SOIL, or OpenGL, but some sections of the image when displayed by my program are discolored. The image was made with GraphicsGale, and I opened it in paint, photoshop, and photo viewers and it was displayed correctly, but when my program displayed it, there were issues. Does anyone have any idea what could have caused it or how I can fix it?
Topic archived. No new replies allowed.