PDA

View Full Version : I get flat color textures with SOIL lib, plz help!



Bluebomber357
05-26-2009, 01:40 PM
I think I finally got SOIL installed with Visual Studio 2008. The only problem is that after using the code on their website, all I get is a single flat color. I get a different color depending on the texture, which I believe means that something is working... I hope, please let me know if you have any suggestions :)

Below is snippets of my relevant code for texturing in two functions. BTW, cout does not print an error:

(init func)
/* load an image file directly as a new OpenGL texture */
tex_2d = SOIL_load_OGL_texture
(
"img_test.bmp",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);

/* check for an error during the load process */
if( 0 == tex_2d )
{
std::cout << "SOIL loading error: '%s'\n", SOIL_last_result() ;
}


(display func)
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);


drawSnowMan();
glDisable(GL_TEXTURE_2D);

Bluebomber357
05-26-2009, 02:21 PM
I found some random texturing code,

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

The first two are critical for texturing to work in my project. I have some other opengl programs that don't have the first two lines, and they have texturing just fine, what gives? Can someone explain please?

Bluebomber357
05-26-2009, 04:04 PM
So I thought GLUT automatically took care of needing:

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

I am wrong right? Also, I can't get a texture to stretch over the whole object. It either clamps or repeats, what gives! Isn't there a way to get it to stretch with glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ????);

Bluebomber357
05-26-2009, 05:26 PM
Well, I finally figured it out. I had to set a certain flag, SOIL_FLAG_TEXTURE_REPEATS of all flags, which ends up making the texture not repeat. I found it by pure luck... w.e., victory is mine :D