PDA

View Full Version : textures



riche606
03-29-2011, 07:42 AM
im trying to apply 2 textures to my level the code compiles but the levelis completly white,


void textureLoader()
{

/*glPixelStorei(GL_UNPACK_ALIGNMENT, 1);*/

glGenTextures(2, theTexture);


glBindTexture(GL_TEXTURE_2D, theTexture[0]);
for(int k=0; k < textureCount; k++)
{
if(!imageLoader(textureFilenames0[k], &amp;myTextureData[k]))
exit(1);

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);

glBindTexture(GL_TEXTURE_2D, theTexture[1]);
for(int k=0; k < textureCount; k++)
{
if(!imageLoader(textureFilenames1[k], &amp;myTextureData[k]))
exit(1);

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);
}
}


typedef struct Image Image;

const int textureCount = 2;

Image myTextureData[textureCount];
GLuint theTexture[textureCount];


char* textureFilenames0[textureCount] = {"road.bmp"};
char* textureFilenames1[textureCount] = {"building.bmp"};

Groovounet
03-29-2011, 10:07 AM
If you are manually loading all the mipmaps, you need to use glTexImage2D instead of gluBuild2DMipmaps.

http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

glTexImage2D has a level parameter (your k) not gluBuild2DMipmaps.

I'm not sure however how this should behave but in practice "bmp" files doesn't have mipmaps so k should be 0 in this case.